|
9 | 9 | use PHPUnit\Framework\Attributes\CoversClass; |
10 | 10 | use PHPUnit\Framework\Attributes\DataProvider; |
11 | 11 |
|
| 12 | +use function implode; |
| 13 | +use function range; |
| 14 | +use function str_repeat; |
| 15 | + |
12 | 16 | #[CoversClass(Sanitize::class)] |
13 | 17 | class SanitizeTest extends AbstractTestCase |
14 | 18 | { |
@@ -139,15 +143,28 @@ public function testBBCode(): void |
139 | 143 | ); |
140 | 144 | } |
141 | 145 |
|
142 | | - /** |
143 | | - * Test for Sanitize::sanitizeFilename |
144 | | - */ |
145 | | - public function testSanitizeFilename(): void |
| 146 | + #[DataProvider('providerTestSanitizeFileName')] |
| 147 | + public function testSanitizeFilename(string $expected, string $input, bool $replaceDot): void |
146 | 148 | { |
147 | | - self::assertSame( |
148 | | - 'File_name_123', |
149 | | - Sanitize::sanitizeFilename('File_name 123'), |
150 | | - ); |
| 149 | + self::assertSame($expected, Sanitize::sanitizeFilename($input, $replaceDot)); |
| 150 | + } |
| 151 | + |
| 152 | + /** @return list<array{string,string,bool}> */ |
| 153 | + public static function providerTestSanitizeFileName(): array |
| 154 | + { |
| 155 | + return [ |
| 156 | + ['Hello123', 'Hello123', false], |
| 157 | + ['宮保雞丁', '宮保雞丁', false], |
| 158 | + ['Україна', 'Україна', false], |
| 159 | + ['-_-', '-.-', true], |
| 160 | + ['-.-', '-.-', false], |
| 161 | + ['___', '"\'"', false], |
| 162 | + ['_test_', '<test>', false], |
| 163 | + ['Hello__World_', "Hello\r\nWorld!", false], |
| 164 | + ['_', "\u{fffd}", false], |
| 165 | + ['_', '🚀', false], |
| 166 | + [str_repeat('_', 32), implode('', range("\0", "\x1f")), false], |
| 167 | + ]; |
151 | 168 | } |
152 | 169 |
|
153 | 170 | /** |
|
0 commit comments