function SanitizeNameTest::provideInvalidUtf8Filenames

Same name and namespace in other branches
  1. main core/modules/file/tests/src/Unit/SanitizeNameTest.php \Drupal\Tests\file\Unit\SanitizeNameTest::provideInvalidUtf8Filenames()

Provides data for testInvalidUtf8Filename().

Return value

array Arrays with original name, expected name, and sanitization options.

File

core/modules/file/tests/src/Unit/SanitizeNameTest.php, line 302

Class

SanitizeNameTest
Filename sanitization tests.

Namespace

Drupal\Tests\file\Unit

Code

public static function provideInvalidUtf8Filenames() : array {
  return [
    'No transliteration: replace (-)' => [
      "bad\xffname.txt",
      'bad-name.txt',
      [
        FALSE,
        '-',
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'No transliteration: replace (_)' => [
      "bad\xffname.txt",
      'bad_name.txt',
      [
        FALSE,
        '_',
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'No transliteration: raw file without extension' => [
      "bad\xffname",
      'bad-name',
      [
        FALSE,
        '-',
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'No transliteration: every byte invalid' => [
      "\xff\xfe\xfd.txt",
      '---.txt',
      [
        FALSE,
        '-',
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'No transliteration: existing question mark is preserved' => [
      "why?\xffnot.txt",
      'why?-not.txt',
      [
        FALSE,
        '-',
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Transliteration: replace (-)' => [
      "Á-TÉXT-\xffœ.txt",
      'A-TEXT--oe.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Transliteration: replace (_)' => [
      "Á-TÉXT-\xffœ.txt",
      'A-TEXT-_oe.txt',
      [
        TRUE,
        '_',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Transliteration: existing question mark is preserved' => [
      "why?\xffnot.txt",
      'why?-not.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Transliteration and replace whitespace: complex' => [
      "S  Pácê\xff--táb#\t#--🙈.jpg",
      'S--Pace---tab#-#---.jpg',
      [
        TRUE,
        '-',
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
  ];
}

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