8000 [Validator] Improve tests for the Image and File constraints · symfony/symfony@1a82c71 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a82c71

Browse files
committed
[Validator] Improve tests for the Image and File constraints
1 parent 46408f0 commit 1a82c71

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ public function testMaxSizeExceeded($bytesWritten, $limit, $sizeAsString, $limit
185185
public function provideMaxSizeNotExceededTests()
186186
{
187187
return [
188+
// 0 has no effect
189+
[100, 0],
190+
188191
// limit in bytes
189192
[1000, 1000],
190193
[1000000, 1000000],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foobar

src/Symfony/Component/Validator/Tests/Constraints/ImageValidatorTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ImageValidatorTest extends ConstraintValidatorTestCase
3434
protected $imagePortrait;
3535
protected $image4By3;
3636
protected $imageCorrupted;
37+
protected $notAnImage;
3738

3839
protected function createValidator()
3940
{
@@ -50,6 +51,7 @@ protected function setUp(): void
5051
$this->image4By3 = __DIR__.'/Fixtures/test_4by3.gif';
5152
$this->image16By9 = __DIR__.'/Fixtures/test_16by9.gif';
5253
$this->imageCorrupted = __DIR__.'/Fixtures/test_corrupted.gif';
54+
$this->notAnImage = __DIR__.'/Fixtures/ccc.txt';
5355
}
5456

5557
public function testNullIsValid()
@@ -416,4 +418,19 @@ public function testCorrupted()
416418
->setCode(Image::CORRUPTED_IMAGE_ERROR)
417419
->assertRaised();
418420
}
421+
422+
public function testInvalidMimeType()
423+
{
424+
$this->validator->validate($this->notAnImage, $constraint = new Image());
425+
426+
$this->assertSame('image/*', $constraint->mimeTypes);
427+
428+
$this->buildViolation('This file is not a valid image.')
429+
->setParameter('{{ file }}', sprintf('"%s"', $this->notAnImage))
430+
->setParameter('{{ type }}', '"text/plain"')
431+
->setParameter('{{ types }}', '"image/*"')
432+
->setParameter('{{ name }}', '"ccc.txt"')
433+
->setCode(Image::INVALID_MIME_TYPE_ERROR)
434+
->assertRaised();
435+
}
419436
}

0 commit comments

Comments
 (0)
0