diff --git a/tests/tool_excimer_script_metadata_test.php b/tests/tool_excimer_script_metadata_test.php index 132bf6d..a2f628f 100644 --- a/tests/tool_excimer_script_metadata_test.php +++ b/tests/tool_excimer_script_metadata_test.php @@ -188,6 +188,71 @@ public function sampling_limit_provider(): array { ]; } + /** + * Tests script_metadata::get_request(). + * @dataProvider normalised_relative_script_path_provider + * @covers \tool_excimer\script_metadata::get_request + */ + public function test_get_request(string $pathinfo, string $expected) { + script_metadata::init(); + + global $SCRIPT, $ME; + $globalscript = $SCRIPT ?? null; + $globalme = $ME ?? null; + + $SCRIPT = $pathinfo; + $ME = $pathinfo; + $this->assertEquals($expected, script_metadata::get_request()); + + $SCRIPT = $globalscript; + $ME = $globalme; + } + + + /** + * Tests script_metadata::get_normalised_relative_script_path(). + * @dataProvider normalised_relative_script_path_provider + * @covers \tool_excimer\script_metadata::get_normalised_relative_script_path + * @param string $pathinfo + * @param string $expected + */ + public function test_get_normalised_relative_script_path(string $pathinfo, string $expected) { + script_metadata::init(); + // $this->assertEquals($expected, script_metadata::get_normalised_relative_script_path($pathinfo, null)); + $this->assertEquals($expected, script_metadata::get_normalised_relative_script_path(null, $pathinfo)); + } + + /** + * Provider for test_get_normalised_relative_script_path(). + * @return \string[][] + */ + public function normalised_relative_script_path_provider(): array { + return [ + ['', '/'], + ['/', '/'], + ['//', '/'], + ['///', '/'], + ['home', 'home'], + ['/home', 'home'], + ['home/', 'home'], + ['/home/', 'home'], + ['hello/world', 'hello/world'], + ['/hello/world', 'hello/world'], + ['/hello/world/', 'hello/world'], + ['/////hello////world///', 'hello/world'], + ['/////hello////world/index.php', 'hello/world'], + ['/////hello////world///index.php', 'hello/world'], + ['/////hello////world/index.php///', 'hello/world'], + ['/index.php', '/'], + ['/my//index.php////', 'my'], + ['/my//index.php////index.php', 'my'], + ['/my//index.php////index.php/', 'my'], + ['/my//index.php////index.php/hello/world?param=value¶m2=value', 'my'], + ['https://example.com//index.php', 'https:/example.com'], + ['https://example.com/index.php/', 'https:/example.com'], + ]; + } + /** * Tests get_redactable_param_names(). *