2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Unit tests for setuplib.php
20 * @package core_phpunit
21 * @copyright 2012 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
29 * Unit tests for setuplib.php
31 * @copyright 2012 The Open University
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class core_setuplib_testcase
extends basic_testcase
{
37 * Test get_docs_url_standard in the normal case when we should link to Moodle docs.
39 public function test_get_docs_url_standard() {
41 if (empty($CFG->docroot
)) {
42 $docroot = 'http://docs.moodle.org/';
44 $docroot = $CFG->docroot
;
46 $this->assertRegExp('~^' . preg_quote($docroot, '') . '/2\d/' . current_language() . '/course/editing$~',
47 get_docs_url('course/editing'));
51 * Test get_docs_url_standard in the special case of an absolute HTTP URL.
53 public function test_get_docs_url_http() {
54 $url = 'http://moodle.org/';
55 $this->assertEquals($url, get_docs_url($url));
59 * Test get_docs_url_standard in the special case of an absolute HTTPS URL.
61 public function test_get_docs_url_https() {
62 $url = 'https://moodle.org/';
63 $this->assertEquals($url, get_docs_url($url));
67 * Test get_docs_url_standard in the special case of a link relative to wwwroot.
69 public function test_get_docs_url_wwwroot() {
71 $this->assertEquals($CFG->wwwroot
. '/lib/tests/setuplib_test.php',
72 get_docs_url('%%WWWROOT%%/lib/tests/setuplib_test.php'));
76 * Test if get_exception_info() removes file system paths
78 public function test_exception_info_removes_serverpaths() {
81 // This doesn't test them all possible ones, but these are set for unit tests.
82 $cfgnames = array('dataroot', 'dirroot', 'tempdir', 'cachedir');
86 foreach ($cfgnames as $cfgname) {
87 if (!empty($CFG->$cfgname)) {
88 $fixture .= $CFG->$cfgname.' ';
89 $expected .= "[$cfgname] ";
92 $exception = new moodle_exception('generalexceptionmessage', 'error', '', $fixture, $fixture);
93 $exceptioninfo = get_exception_info($exception);
95 $this->assertContains($expected, $exceptioninfo->message
, 'Exception message does not contain system paths');
96 $this->assertContains($expected, $exceptioninfo->debuginfo
, 'Exception debug info does not contain system paths');