mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
MDL-84543 core: Basepath guess should work on root domains
This commit is contained in:
parent
ae31be1e34
commit
d68cf00b25
@ -91,7 +91,7 @@ class router {
|
||||
|
||||
// Moodle is not guaranteed to exist at the domain root.
|
||||
// Strip out the current script.
|
||||
$scriptroot = parse_url($CFG->wwwroot, PHP_URL_PATH);
|
||||
$scriptroot = parse_url($CFG->wwwroot, PHP_URL_PATH) ?? '';
|
||||
$scriptfile = str_replace(
|
||||
realpath($CFG->dirroot),
|
||||
'',
|
||||
|
@ -88,13 +88,26 @@ final class router_test extends route_testcase {
|
||||
$this->assertEquals('/example', $router->basepath);
|
||||
}
|
||||
|
||||
public function test_basepath_guessed(): void {
|
||||
/**
|
||||
* @dataProvider basepath_provider
|
||||
*/
|
||||
public function test_basepath(
|
||||
string $wwwroot,
|
||||
string $expected,
|
||||
): void {
|
||||
global $CFG;
|
||||
|
||||
$wwwroot = new \moodle_url($CFG->wwwroot);
|
||||
$this->resetAfterTest();
|
||||
$CFG->wwwroot = $wwwroot;
|
||||
|
||||
$router = di::get(router::class);
|
||||
|
||||
$this->assertEquals($wwwroot->get_path(), $router->basepath);
|
||||
$this->assertEquals($expected, $router->basepath);
|
||||
}
|
||||
|
||||
public static function basepath_provider(): \Iterator {
|
||||
yield 'Domain' => ['http://example.com', ''];
|
||||
yield 'Subdirectory' => ['http://example.com/moodle', '/moodle'];
|
||||
}
|
||||
|
||||
public function test_basepath_guessed_rphp(): void {
|
||||
|
Loading…
x
Reference in New Issue
Block a user