function LegacyValidatorTest::testFileValidateExtensions

Same name in other branches
  1. 10 core/modules/file/tests/src/Kernel/LegacyValidatorTest.php \Drupal\Tests\file\Kernel\LegacyValidatorTest::testFileValidateExtensions()

Tests the file_validate_extensions() function.

File

core/modules/file/tests/src/Kernel/LegacyValidatorTest.php, line 50

Class

LegacyValidatorTest
Tests the functions used to validate uploaded files.

Namespace

Drupal\Tests\file\Kernel

Code

public function testFileValidateExtensions() {
    $file = File::create([
        'filename' => 'asdf.txt',
    ]);
    $this->expectDeprecation('file_validate_extensions() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'file.validator\' service instead. See https://www.drupal.org/node/3363700');
    $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.');
}

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