Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / ImageValidatorTest.php
index 4605a06577a8a6aa154a6a2865a6c41cafc94f25..93b1d05bab7b2d623c78213866dcdc56f5a8ba84 100644 (file)
@@ -13,12 +13,12 @@ namespace Symfony\Component\Validator\Tests\Constraints;
 
 use Symfony\Component\Validator\Constraints\Image;
 use Symfony\Component\Validator\Constraints\ImageValidator;
-use Symfony\Component\Validator\Validation;
+use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
 
 /**
  * @requires extension fileinfo
  */
-class ImageValidatorTest extends AbstractConstraintValidatorTest
+class ImageValidatorTest extends ConstraintValidatorTestCase
 {
     protected $context;
 
@@ -32,11 +32,7 @@ class ImageValidatorTest extends AbstractConstraintValidatorTest
     protected $imageLandscape;
     protected $imagePortrait;
     protected $image4By3;
-
-    protected function getApiVersion()
-    {
-        return Validation::API_VERSION_2_5;
-    }
+    protected $imageCorrupted;
 
     protected function createValidator()
     {
@@ -51,6 +47,7 @@ class ImageValidatorTest extends AbstractConstraintValidatorTest
         $this->imageLandscape = __DIR__.'/Fixtures/test_landscape.gif';
         $this->imagePortrait = __DIR__.'/Fixtures/test_portrait.gif';
         $this->image4By3 = __DIR__.'/Fixtures/test_4by3.gif';
+        $this->imageCorrupted = __DIR__.'/Fixtures/test_corrupted.gif';
     }
 
     public function testNullIsValid()
@@ -329,4 +326,26 @@ class ImageValidatorTest extends AbstractConstraintValidatorTest
             ->setCode(Image::PORTRAIT_NOT_ALLOWED_ERROR)
             ->assertRaised();
     }
+
+    public function testCorrupted()
+    {
+        if (!function_exists('imagecreatefromstring')) {
+            $this->markTestSkipped('This test require GD extension');
+        }
+
+        $constraint = new Image(array(
+            'detectCorrupted' => true,
+            'corruptedMessage' => 'myMessage',
+        ));
+
+        $this->validator->validate($this->image, $constraint);
+
+        $this->assertNoViolation();
+
+        $this->validator->validate($this->imageCorrupted, $constraint);
+
+        $this->buildViolation('myMessage')
+            ->setCode(Image::CORRUPTED_IMAGE_ERROR)
+            ->assertRaised();
+    }
 }