Skip to content

Commit

Permalink
MDL-29624 Media embedding system, part 0: Add get_path() to moodle_url
Browse files Browse the repository at this point in the history
(It may not seem directly related, but this function is needed for the
media embedding system.
  • Loading branch information
sammarshallou committed May 9, 2012
1 parent e16e230 commit ffe4de9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/tests/weblib_test.php
Expand Up @@ -112,6 +112,21 @@ function test_wikify_links() {
$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);
Expand Down
17 changes: 17 additions & 0 deletions lib/weblib.php
Expand Up @@ -754,6 +754,23 @@ public function out_as_local_url($escaped = true, array $overrideparams = null)

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 : '');
}
}

/**
Expand Down

0 comments on commit ffe4de9

Please sign in to comment.