MDL-84351 url: Add method for getting slashargument
This commit is contained in:
committed by
Huong Nguyen
parent
dbd723f81c
commit
57d26f552e
@@ -0,0 +1,5 @@
|
||||
issueNumber: MDL-84351
|
||||
notes:
|
||||
core:
|
||||
- message: The public method `get_slashargument` has been added to the `url` class.
|
||||
type: improved
|
||||
@@ -936,6 +936,17 @@ All values that are not arrays should be a string.');
|
||||
public function get_port() {
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the 'slashargument' portion of a URL. For example, if the URL is
|
||||
* http://www.example.org.com/pluginfile.php/1/core_admin/logocompact/ then this will
|
||||
* return '1/core_admin/logocompact/'.
|
||||
*
|
||||
* @return string Slash argument as string.
|
||||
*/
|
||||
public function get_slashargument(): string {
|
||||
return $this->slashargument;
|
||||
}
|
||||
}
|
||||
|
||||
// Alias this class to the old name.
|
||||
|
||||
@@ -334,6 +334,19 @@ final class url_test extends \advanced_testcase {
|
||||
$this->assertMatchesRegularExpression($expected, $url->out(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the get_slashargument method.
|
||||
*/
|
||||
public function test_get_slashargument(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$url = new url('/pluginfile.php/14/user/private/capybara.png');
|
||||
$this->assertEquals('/14/user/private/capybara.png', $url->get_slashargument());
|
||||
|
||||
$url = new url('/image/capybara.png');
|
||||
$this->assertEmpty($url->get_slashargument());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for make_pluginfile_url tests.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user