Skip to content

Commit

Permalink
[#272] Unit tests for new logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Fragonite committed Sep 5, 2023
1 parent 1c5bbe2 commit 02961ba
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 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,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&param2=value', 'my'],
['https://example.com//index.php', 'https:/example.com'],
['https://example.com/index.php/', 'https:/example.com'],
];
}

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

0 comments on commit 02961ba

Please sign in to comment.