function LegacyValidatorTest::testFileValidateExtensionsOnUri

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

Tests the file_validate_extensions() function.

@dataProvider providerTestFileValidateExtensionsOnUri

Parameters

array $file_properties: The properties of the file being validated.

string[] $extensions: An array of the allowed file extensions.

string[] $expected_errors: The expected error messages as string.

File

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

Class

LegacyValidatorTest
Tests the functions used to validate uploaded files.

Namespace

Drupal\Tests\file\Kernel

Code

public function testFileValidateExtensionsOnUri(array $file_properties, array $extensions, array $expected_errors) {
    $file = File::create($file_properties);
    $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');
    $actual_errors = file_validate_extensions($file, implode(' ', $extensions));
    $actual_errors_as_string = array_map(function ($error_message) {
        return (string) $error_message;
    }, $actual_errors);
    $this->assertEquals($expected_errors, $actual_errors_as_string);
}

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