AllowFileTypeTest.php 854 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace EasySwoole\Validate\tests;
  3. /**
  4. * @internal
  5. */
  6. class AllowFileTypeTest extends BaseTestCase
  7. {
  8. public function testValidCase()
  9. {
  10. $this->freeValidate();
  11. $this->validate->addColumn('file')->allowFileType(['image/png']);
  12. $bool = $this->validate->validate(['file' => (new UploadFile(__DIR__ . '/../res/easyswoole.png', 1, 200, null, 'image/png'))]);
  13. $this->assertTrue($bool);
  14. $this->freeValidate();
  15. $this->validate->addColumn('file')->allowFileType(['image/png', 'image/jpg']);
  16. $bool = $this->validate->validate(['file' => (new UploadFile(__DIR__ . '/../res/easyswoole.png', 1, 200, null, 'image/jpeg'))]);
  17. $this->assertFalse($bool);
  18. $this->assertEquals('file文件类型必须在[image/png,image/jpg]内', $this->validate->getError()->__toString());
  19. }
  20. }