function FileIsImageConstraintValidatorTest::testFileIsImage

Same name in other branches
  1. 10 core/modules/file/tests/src/Kernel/Plugin/Validation/Constraint/FileIsImageConstraintValidatorTest.php \Drupal\Tests\file\Kernel\Plugin\Validation\Constraint\FileIsImageConstraintValidatorTest::testFileIsImage()

This ensures a specific file is actually an image.

@covers ::validate

File

core/modules/file/tests/src/Kernel/Plugin/Validation/Constraint/FileIsImageConstraintValidatorTest.php, line 55

Class

FileIsImageConstraintValidatorTest
Tests the FileIsImageConstraintValidator.

Namespace

Drupal\Tests\file\Kernel\Plugin\Validation\Constraint

Code

public function testFileIsImage() : void {
    $this->assertFileExists($this->image
        ->getFileUri());
    $validators = [
        'FileIsImage' => [],
    ];
    $violations = $this->validator
        ->validate($this->image, $validators);
    $this->assertCount(0, $violations, 'No error reported for our image file.');
    $this->assertFileExists($this->nonImage
        ->getFileUri());
    $violations = $this->validator
        ->validate($this->nonImage, $validators);
    $this->assertCount(1, $violations, 'An error reported for our non-image file.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.