|
17 | 17 |
|
18 | 18 | final class NormalizationTest extends TestCase
|
19 | 19 | {
|
| 20 | + /** |
| 21 | + * @test |
| 22 | + * @dataProvider namesProvider |
| 23 | + * @dataProvider edgeCaseTestNames |
| 24 | + */ |
| 25 | + public function can_normalize_test_names(string $testName, string $expectedOutput): void |
| 26 | + { |
| 27 | + $browser = $this->createMock(Browser::class); |
| 28 | + $browser |
| 29 | + ->expects(self::once()) |
| 30 | + ->method('saveCurrentState') |
| 31 | + ->with($expectedOutput); |
| 32 | + |
| 33 | + $extension = new LegacyExtension(); |
| 34 | + $extension->executeBeforeFirstTest(); |
| 35 | + $extension->executeBeforeTest($testName); |
| 36 | + $extension::registerBrowser($browser); |
| 37 | + $extension->executeAfterTestError($testName, '', 0); |
| 38 | + } |
| 39 | + |
20 | 40 | public static function namesProvider(): \Generator
|
21 | 41 | {
|
22 | 42 | $baseTemplate = 'error_'.__METHOD__;
|
@@ -52,22 +72,32 @@ public static function namesProvider(): \Generator
|
52 | 72 | ];
|
53 | 73 | }
|
54 | 74 |
|
55 |
| - /** |
56 |
| - * @test |
57 |
| - * @dataProvider namesProvider |
58 |
| - */ |
59 |
| - public function can_normalize_test_names(string $testName, string $normalizedName): void |
| 75 | + public static function edgeCaseTestNames(): \Generator |
60 | 76 | {
|
61 |
| - $browser = $this->createMock(Browser::class); |
62 |
| - $browser |
63 |
| - ->expects(self::once()) |
64 |
| - ->method('saveCurrentState') |
65 |
| - ->with($normalizedName); |
66 |
| - |
67 |
| - $extension = new LegacyExtension(); |
68 |
| - $extension->executeBeforeFirstTest(); |
69 |
| - $extension->executeBeforeTest($testName); |
70 |
| - $extension::registerBrowser($browser); |
71 |
| - $extension->executeAfterTestError($testName, '', 0); |
| 77 | + $baseTemplate = \strtr('error_'.__METHOD__."__data-set-", '\\:', '-_'); |
| 78 | + yield 'self within moustache' => [ |
| 79 | + 'test name' => __METHOD__.' with data set "te{{self}}st" (test set)', |
| 80 | + 'expected output' => $baseTemplate.'te-self-st__0', |
| 81 | + ]; |
| 82 | + yield 'double quoted with space' => [ |
| 83 | + 'test name' => __METHOD__.' with data set "_self.env.setCache("uri://host.net:2121") _self.env.loadTemplate("other-host")" (test set)', |
| 84 | + 'expected output' => $baseTemplate.'_self-env-setCache-uri-host-net-2121-_self-env-loadTemplate-other-host-__0', |
| 85 | + ]; |
| 86 | + yield 'double quotes in moustache' => [ |
| 87 | + 'test name' => __METHOD__.' with data set "te{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("id")}}st"', |
| 88 | + 'expected output' => $baseTemplate.'te-_self-env-registerUndefinedFilterCallback-exec-_self-env-getFilter-id-st__0', |
| 89 | + ]; |
| 90 | + yield 'escaped simple quote' => [ |
| 91 | + 'test name' => __METHOD__.' with data set "te{{\'/etc/passwd\'|file_excerpt(1,30)}}st"', |
| 92 | + 'expected output' => $baseTemplate.'te-etc-passwd-file_excerpt-1-30-st__0', |
| 93 | + ]; |
| 94 | + yield 'single quote for array index access' => [ |
| 95 | + 'test name' => __METHOD__.' with data set "te{{[\'id\']|filter(\'system\')}}st"', |
| 96 | + 'expected output' => $baseTemplate.'te-id-filter-system-st__0', |
| 97 | + ]; |
| 98 | + yield 'numeric array access' => [ |
| 99 | + 'test name' => __METHOD__.' with data set "te{{[0]|reduce(\'system\',\'id\')}}st"', |
| 100 | + 'expected output' => $baseTemplate.'te-0-reduce-system-id-st__0', |
| 101 | + ]; |
72 | 102 | }
|
73 | 103 | }
|
0 commit comments