MDL-40635 moodle_url: can now set anchor during construction

This commit is contained in:
Sam Hemelryk
2013-07-15 10:17:49 +12:00
parent 07bbbcf174
commit 61b223a632
2 changed files with 34 additions and 1 deletions
+29
View File
@@ -147,6 +147,35 @@ class web_testcase extends advanced_testcase {
$this->assertEquals(wikify_links('this is a <a href="http://someaddress.com/query">link</a>'), 'this is a link [ http://someaddress.com/query ]');
}
/**
* Test basic moodle_url construction.
*/
function test_moodle_url_constructor() {
global $CFG;
$url = new moodle_url('/index.php');
$this->assertEquals($CFG->wwwroot.'/index.php', $url->out());
$url = new moodle_url('/index.php', array());
$this->assertEquals($CFG->wwwroot.'/index.php', $url->out());
$url = new moodle_url('/index.php', array('id' => 2));
$this->assertEquals($CFG->wwwroot.'/index.php?id=2', $url->out());
$url = new moodle_url('/index.php', array('id' => 'two'));
$this->assertEquals($CFG->wwwroot.'/index.php?id=two', $url->out());
$url = new moodle_url('/index.php', array('id' => 1, 'cid' => '2'));
$this->assertEquals($CFG->wwwroot.'/index.php?id=1&amp;cid=2', $url->out());
$this->assertEquals($CFG->wwwroot.'/index.php?id=1&cid=2', $url->out(false));
$url = new moodle_url('/index.php', null, 'test');
$this->assertEquals($CFG->wwwroot.'/index.php#test', $url->out());
$url = new moodle_url('/index.php', array('id' => 2), 'test');
$this->assertEquals($CFG->wwwroot.'/index.php?id=2#test', $url->out());
}
/**
* Tests moodle_url::get_path().
*/
+5 -1
View File
@@ -298,8 +298,9 @@ class moodle_url {
* $params instead. For admin URLs, just use /admin/script.php, this
* class takes care of the $CFG->admin issue.
* @param array $params these params override current params or add new
* @param string $anchor The anchor to use as part of the URL if there is one.
*/
public function __construct($url, array $params = null) {
public function __construct($url, array $params = null, $anchor = null) {
global $CFG;
if ($url instanceof moodle_url) {
@@ -361,6 +362,9 @@ class moodle_url {
}
$this->params($params);
if ($anchor !== null) {
$this->anchor = (string)$anchor;
}
}
/**