You are here

public function FileValidationTest::testFileValidation in SVG Image Field 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Unit/FileValidationTest.php \Drupal\Tests\svg_image_field\Unit\FileValidationTest::testFileValidation()
  2. 2.1.x tests/src/Unit/FileValidationTest.php \Drupal\Tests\svg_image_field\Unit\FileValidationTest::testFileValidation()

Checks that the list of files is being checked as expected.

File

tests/src/Unit/FileValidationTest.php, line 62

Class

FileValidationTest
Svg Image Field module unit tests.

Namespace

Drupal\Tests\svg_image_field\Unit

Code

public function testFileValidation() {
  $files = scandir($this->testDataDirPath);
  foreach ($files as $file_name) {
    if (strpos($file_name, 'valid_svg') === 0) {
      $file_path = realpath($this->testDataDirPath . '/' . $file_name);
      $file = File::create([
        'uri' => $file_path,
        'uid' => 1,
        'status' => 1,
      ]);
      $file
        ->setFilename($file_name);
      $this
        ->assertEquals(TRUE, count(svg_image_field_validate_mime_type($file)) === 0, t("Check that %file_name is valid", [
        '%file_name' => $file_name,
      ]));
    }
    elseif (strpos($file_name, 'invalid_svg') === 0) {
      $file_path = realpath($this->testDataDirPath . '/' . $file_name);
      $file = File::create([
        'uri' => $file_path,
        'uid' => 1,
        'status' => 1,
      ]);
      $file
        ->setFilename($file_name);
      $this
        ->assertEquals(TRUE, count(svg_image_field_validate_mime_type($file)) > 0, t("Check that %file_name is invalid", [
        '%file_name' => $file_name,
      ]));
    }
  }
}