|
16 | 16 | use CodeIgniter\Test\CIUnitTestCase; |
17 | 17 | use Config\Services; |
18 | 18 | use InvalidArgumentException; |
| 19 | +use PHPUnit\Framework\Attributes\DataProvider; |
19 | 20 | use PHPUnit\Framework\Attributes\Group; |
20 | 21 | use Tests\Support\Validation\TestRules; |
21 | 22 |
|
@@ -62,6 +63,20 @@ protected function setUp(): void |
62 | 63 | 'width' => 640, |
63 | 64 | 'height' => 400, |
64 | 65 | ], |
| 66 | + 'excel_xlsx' => [ |
| 67 | + 'tmp_name' => TESTPATH . '_support/Validation/uploads/abc77tz', |
| 68 | + 'name' => 'whata.xlsx', |
| 69 | + 'size' => 12345, |
| 70 | + 'type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
| 71 | + 'error' => UPLOAD_ERR_OK, |
| 72 | + ], |
| 73 | + 'excel_xls' => [ |
| 74 | + 'tmp_name' => TESTPATH . '_support/Validation/uploads/abc77tz', |
| 75 | + 'name' => 'whatb.xls', |
| 76 | + 'size' => 12345, |
| 77 | + 'type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
| 78 | + 'error' => UPLOAD_ERR_OK, |
| 79 | + ], |
65 | 80 | 'bigfile' => [ |
66 | 81 | 'tmp_name' => TESTPATH . '_support/Validation/uploads/phpUxc0ty', |
67 | 82 | 'name' => 'my-big-file.png', |
@@ -280,21 +295,41 @@ public function testMimeTypeImpossible(): void |
280 | 295 | $this->assertFalse($this->validation->run([])); |
281 | 296 | } |
282 | 297 |
|
283 | | - public function testExtensionOk(): void |
284 | | - { |
285 | | - $this->validation->setRules(['avatar' => 'ext_in[avatar,jpg,jpeg,gif,png]']); |
286 | | - $this->assertTrue($this->validation->run([])); |
287 | | - } |
288 | | - |
289 | | - public function testExtensionNotOk(): void |
| 298 | + public static function provideExtensionMore(): iterable |
290 | 299 | { |
291 | | - $this->validation->setRules(['avatar' => 'ext_in[avatar,xls,doc,ppt]']); |
292 | | - $this->assertFalse($this->validation->run([])); |
| 300 | + yield from [ |
| 301 | + [ |
| 302 | + 'avatar', |
| 303 | + 'jpg,jpeg,gif,png', |
| 304 | + true, |
| 305 | + ], |
| 306 | + [ |
| 307 | + 'avatar', |
| 308 | + 'xls,doc,ppt', |
| 309 | + false, |
| 310 | + ], |
| 311 | + [ |
| 312 | + 'excel_xlsx', |
| 313 | + 'xls,xlsx', |
| 314 | + true, |
| 315 | + ], |
| 316 | + [ |
| 317 | + 'excel_xls', |
| 318 | + 'xls,xlsx', |
| 319 | + true, |
| 320 | + ], |
| 321 | + [ |
| 322 | + 'excel_xls', |
| 323 | + 'pdf', |
| 324 | + false, |
| 325 | + ], |
| 326 | + ]; |
293 | 327 | } |
294 | 328 |
|
295 | | - public function testExtensionImpossible(): void |
| 329 | + #[DataProvider('provideExtensionMore')] |
| 330 | + public function testExtensionMoreOk(string $field, string $rules, bool $expect): void |
296 | 331 | { |
297 | | - $this->validation->setRules(['avatar' => 'ext_in[unknown,xls,doc,ppt]']); |
298 | | - $this->assertFalse($this->validation->run([])); |
| 332 | + $this->validation->setRules([$field => "ext_in[{$field},{$rules}]"]); |
| 333 | + $this->assertSame($expect, $this->validation->run([])); |
299 | 334 | } |
300 | 335 | } |
0 commit comments