mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
MDL-51718 weblib: Allow moodle_url scheme to be set
This commit is contained in:
parent
4cef723c22
commit
462065e822
@ -246,6 +246,24 @@ class core_weblib_testcase extends advanced_testcase {
|
||||
$this->assertSame($strurl, $url->out(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test set good scheme on Moodle URL objects.
|
||||
*/
|
||||
public function test_moodle_url_set_good_scheme() {
|
||||
$url = new moodle_url('http://moodle.org/foo/bar');
|
||||
$url->set_scheme('myscheme');
|
||||
$this->assertSame('myscheme://moodle.org/foo/bar', $url->out());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test set bad scheme on Moodle URL objects.
|
||||
*/
|
||||
public function test_moodle_url_set_bad_scheme() {
|
||||
$url = new moodle_url('http://moodle.org/foo/bar');
|
||||
$this->setExpectedException('coding_exception');
|
||||
$url->set_scheme('not a valid $ scheme');
|
||||
}
|
||||
|
||||
public function test_moodle_url_round_trip_array_params() {
|
||||
$strurl = 'http://example.com/?a%5B1%5D=1&a%5B2%5D=2';
|
||||
$url = new moodle_url($strurl);
|
||||
|
@ -672,6 +672,20 @@ class moodle_url {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scheme for the URI (the bit before ://)
|
||||
*
|
||||
* @param string $scheme
|
||||
*/
|
||||
public function set_scheme($scheme) {
|
||||
// See http://www.ietf.org/rfc/rfc3986.txt part 3.1.
|
||||
if (preg_match('/^[a-zA-Z][a-zA-Z0-9+.-]*$/', $scheme)) {
|
||||
$this->scheme = $scheme;
|
||||
} else {
|
||||
throw new coding_exception('Bad URL scheme.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the url slashargument value.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user