You are here

public function ValidatorTest::testFileValidateExtensionsOnUri in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/file/tests/src/Kernel/ValidatorTest.php \Drupal\Tests\file\Kernel\ValidatorTest::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/ValidatorTest.php, line 67

Class

ValidatorTest
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);
  $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);
}