function LegacyValidatorTest::providerTestFileValidateExtensionsOnUri

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

Data provider for ::testFileValidateExtensionsOnUri.

Return value

array[][] The test cases.

File

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

Class

LegacyValidatorTest
Tests the functions used to validate uploaded files.

Namespace

Drupal\Tests\file\Kernel

Code

public static function providerTestFileValidateExtensionsOnUri() : array {
    $temporary_txt_file_properties = [
        'filename' => 'asdf.txt',
        'uri' => 'temporary://asdf',
        'status' => 0,
    ];
    $permanent_txt_file_properties = [
        'filename' => 'asdf.txt',
        'uri' => 'public://asdf_0.txt',
        'status' => 1,
    ];
    $permanent_png_file_properties = [
        'filename' => 'The Druplicon',
        'uri' => 'public://druplicon.png',
        'status' => 1,
    ];
    return [
        'Temporary txt validated with "asdf", "txt", "pork"' => [
            'File properties' => $temporary_txt_file_properties,
            'Allowed_extensions' => [
                'asdf',
                'txt',
                'pork',
            ],
            'Expected errors' => [],
        ],
        'Temporary txt validated with "exe" and "png"' => [
            'File properties' => $temporary_txt_file_properties,
            'Allowed_extensions' => [
                'exe',
                'png',
            ],
            'Expected errors' => [
                'Only files with the following extensions are allowed: <em class="placeholder">exe png</em>.',
            ],
        ],
        'Permanent txt validated with "asdf", "txt", "pork"' => [
            'File properties' => $permanent_txt_file_properties,
            'Allowed_extensions' => [
                'asdf',
                'txt',
                'pork',
            ],
            'Expected errors' => [],
        ],
        'Permanent txt validated with "exe" and "png"' => [
            'File properties' => $permanent_txt_file_properties,
            'Allowed_extensions' => [
                'exe',
                'png',
            ],
            'Expected errors' => [
                'Only files with the following extensions are allowed: <em class="placeholder">exe png</em>.',
            ],
        ],
        'Permanent png validated with "png", "gif", "jpg", "jpeg"' => [
            'File properties' => $permanent_png_file_properties,
            'Allowed_extensions' => [
                'png',
                'gif',
                'jpg',
                'jpeg',
            ],
            'Expected errors' => [],
        ],
        'Permanent png validated with "exe" and "txt"' => [
            'File properties' => $permanent_png_file_properties,
            'Allowed_extensions' => [
                'exe',
                'txt',
            ],
            'Expected errors' => [
                'Only files with the following extensions are allowed: <em class="placeholder">exe txt</em>.',
            ],
        ],
    ];
}

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