Skip to content

Commit

Permalink
[#272] Add unit tests for get_request()
Browse files Browse the repository at this point in the history
  • Loading branch information
Fragonite authored and brendanheywood committed Sep 6, 2023
1 parent c4b7746 commit b96682a
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/tool_excimer_script_metadata_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,72 @@ public function sampling_limit_provider(): array {
];
}

/**
* Tests script_metadata::get_request().
* @dataProvider relative_script_path_provider
* @covers \tool_excimer\script_metadata::get_request
* @param string $path
* @param string $expected
*/
public function test_get_request(string $path, string $expected) {
script_metadata::init();

global $SCRIPT, $ME;
$globalscript = $SCRIPT ?? null;
$globalme = $ME ?? null;

$SCRIPT = $path;
$ME = $path;
$this->assertEquals($expected, script_metadata::get_request());

$SCRIPT = $globalscript;
$ME = $globalme;
}

/**
* Tests script_metadata::get_normalised_relative_script_path().
* @dataProvider relative_script_path_provider
* @covers \tool_excimer\script_metadata::get_normalised_relative_script_path
* @param string $path
* @param string $expected
*/
public function test_get_normalised_relative_script_path(string $path, string $expected) {
script_metadata::init();
$this->assertEquals($expected, script_metadata::get_normalised_relative_script_path($path, null));
$this->assertEquals($expected, script_metadata::get_normalised_relative_script_path(null, $path));
}

/**
* Provider for test_get_normalised_relative_script_path().
* @return \string[][]
*/
public function 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/index.php'],
['/////hello////world///index.php', 'hello////world///index.php'],
['/////hello////world/index.php///', 'hello////world/index.php'],
['/index.php', 'index.php'],
['/my//index.php////', 'my//index.php'],
['/my//index.php////index.php', 'my//index.php'],
['/my//index.php////index.php/', 'my//index.php'],
['/my//index.php////index.php/hello/world?param=value&param2=value', 'my//index.php'],
['https://example.com//index.php', 'https://example.com//index.php'],
['https://example.com/index.php/', 'https://example.com/index.php'],
];
}

/**
* Tests get_redactable_param_names().
*
Expand Down

0 comments on commit b96682a

Please sign in to comment.