You are here

public function ValidatorTest::testFileValidateExtensions in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Kernel/ValidatorTest.php \Drupal\Tests\file\Kernel\ValidatorTest::testFileValidateExtensions()

Tests the file_validate_extensions() function.

File

core/modules/file/tests/src/Kernel/ValidatorTest.php, line 45

Class

ValidatorTest
Tests the functions used to validate uploaded files.

Namespace

Drupal\Tests\file\Kernel

Code

public function testFileValidateExtensions() {
  $file = File::create([
    'filename' => 'asdf.txt',
  ]);
  $errors = file_validate_extensions($file, 'asdf txt pork');
  $this
    ->assertCount(0, $errors, 'Valid extension accepted.');
  $file
    ->setFilename('asdf.txt');
  $errors = file_validate_extensions($file, 'exe png');
  $this
    ->assertCount(1, $errors, 'Invalid extension blocked.');
}