This commit is contained in:
Jun Pataleta
2025-03-13 17:01:39 +08:00
2 changed files with 17 additions and 4 deletions
+1 -1
View File
@@ -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),
'',
+16 -3
View File
@@ -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 {