mirror of
https://github.com/moodle/moodle.git
synced 2025-08-11 20:06:46 +02:00
Merge branch 'MDL-80896-main' of https://github.com/andrewnicols/moodle
This commit is contained in:
commit
a0e333fb7c
2 changed files with 53 additions and 0 deletions
|
@ -16,6 +16,8 @@
|
|||
|
||||
namespace core;
|
||||
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
|
||||
/**
|
||||
* Tests for moodle_url.
|
||||
*
|
||||
|
@ -414,4 +416,33 @@ class moodle_url_test extends \advanced_testcase {
|
|||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function test_from_uri(): void {
|
||||
global $CFG;
|
||||
|
||||
$uri = new Uri('http://www.example.org:447/my/file/is/here.txt?really=1');
|
||||
$url = \moodle_url::from_uri($uri);
|
||||
$this->assertSame('http://www.example.org:447/my/file/is/here.txt?really=1', $url->out(false));
|
||||
$this->assertEquals(1, $url->param('really'));
|
||||
|
||||
$uri = new Uri('https://www.example.org/my/file/is/here.txt?really=1');
|
||||
$url = \moodle_url::from_uri($uri);
|
||||
$this->assertSame('https://www.example.org/my/file/is/here.txt?really=1', $url->out(false));
|
||||
$this->assertEquals(1, $url->param('really'));
|
||||
|
||||
// Multiple params.
|
||||
$uri = new Uri('https://www.example.org/my/file/is/here.txt?really=1&another=2&&more=3&moar=4');
|
||||
$url = \moodle_url::from_uri($uri);
|
||||
$this->assertSame('https://www.example.org/my/file/is/here.txt?really=1&another=2&more=3&moar=4', $url->out(false));
|
||||
$this->assertEquals(1, $url->param('really'));
|
||||
$this->assertEquals(2, $url->param('another'));
|
||||
$this->assertEquals(3, $url->param('more'));
|
||||
$this->assertEquals(4, $url->param('moar'));
|
||||
|
||||
// Anchors.
|
||||
$uri = new Uri("{$CFG->wwwroot}/course/view/#section-1");
|
||||
$url = \moodle_url::from_uri($uri);
|
||||
$this->assertSame("{$CFG->wwwroot}/course/view/#section-1", $url->out(false));
|
||||
$this->assertEmpty($url->params());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue