mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-29624 Media embedding system, part 0: Add get_path() to moodle_url
(It may not seem directly related, but this function is needed for the media embedding system.
This commit is contained in:
parent
e16e2300c5
commit
ffe4de973b
@ -112,6 +112,21 @@ 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 ]');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests moodle_url::get_path().
|
||||
*/
|
||||
public function test_moodle_url_get_path() {
|
||||
$url = new moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
|
||||
$this->assertEquals('/my/file/is/here.txt', $url->get_path());
|
||||
|
||||
$url = new moodle_url('http://www.example.org/');
|
||||
$this->assertEquals('/', $url->get_path());
|
||||
|
||||
$url = new moodle_url('http://www.example.org/pluginfile.php/slash/arguments');
|
||||
$this->assertEquals('/pluginfile.php/slash/arguments', $url->get_path());
|
||||
$this->assertEquals('/pluginfile.php', $url->get_path(false));
|
||||
}
|
||||
|
||||
function test_moodle_url_round_trip() {
|
||||
$strurl = 'http://moodle.org/course/view.php?id=5';
|
||||
$url = new moodle_url($strurl);
|
||||
|
@ -754,6 +754,23 @@ class moodle_url {
|
||||
|
||||
return str_replace($CFG->wwwroot, '', $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the 'path' portion of a URL. For example, if the URL is
|
||||
* http://www.example.org:447/my/file/is/here.txt?really=1 then this will
|
||||
* return '/my/file/is/here.txt'.
|
||||
*
|
||||
* By default the path includes slash-arguments (for example,
|
||||
* '/myfile.php/extra/arguments') so it is what you would expect from a
|
||||
* URL path. If you don't want this behaviour, you can opt to exclude the
|
||||
* slash arguments.
|
||||
*
|
||||
* @param bool $includeslashargument If true, includes slash arguments
|
||||
* @return string Path of URL
|
||||
*/
|
||||
public function get_path($includeslashargument = true) {
|
||||
return $this->path . ($includeslashargument ? $this->slashargument : '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user