moodle/lib/tests/setuplib_test.php
Tim Hunt 32c842e290 MDL-34035 help links: allow other types of URL for plugins.
For third-parth plugins, in can be helpful if the 'More help' links in
help pop-ups (the ones that come from $string['..._link'] string in the
language file) can go to other places.

This change support two other sorts of URL in addition to the standard
'course/editing' type of link that goes to MoodelDocs.

You can use absolute URLs, starting http:// or https:///

You can use a link starting %%WWWROOT%%, and that token is replaced by
$CFG->wwwroot to make the link.
2012-06-26 18:54:15 +01:00

75 lines
2.4 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for setuplib.php
*
* @package core_phpunit
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Unit tests for setuplib.php
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_setuplib_testcase extends basic_testcase {
/**
* Test get_docs_url_standard in the normal case when we should link to Moodle docs.
*/
public function test_get_docs_url_standard() {
global $CFG;
if (empty($CFG->docroot)) {
$docroot = 'http://docs.moodle.org/';
} else {
$docroot = $CFG->docroot;
}
$this->assertRegExp('~^' . preg_quote($docroot, '') . '/2\d/' . current_language() . '/course/editing$~',
get_docs_url('course/editing'));
}
/**
* Test get_docs_url_standard in the special case of an absolute HTTP URL.
*/
public function test_get_docs_url_http() {
$url = 'http://moodle.org/';
$this->assertEquals($url, get_docs_url($url));
}
/**
* Test get_docs_url_standard in the special case of an absolute HTTPS URL.
*/
public function test_get_docs_url_https() {
$url = 'https://moodle.org/';
$this->assertEquals($url, get_docs_url($url));
}
/**
* Test get_docs_url_standard in the special case of a link relative to wwwroot.
*/
public function test_get_docs_url_wwwroot() {
global $CFG;
$this->assertEquals($CFG->wwwroot . '/lib/tests/setuplib_test.php',
get_docs_url('%%WWWROOT%%/lib/tests/setuplib_test.php'));
}
}