function SanitizeNameTest::provideFilenames

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

Provides data for testFileNameTransliteration().

Return value

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

File

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

Class

SanitizeNameTest
Filename sanitization tests.

Namespace

Drupal\Tests\file\Unit

Code

public static function provideFilenames() {
  return [
    'Test default options' => [
      'TÉXT-œ.txt',
      'TÉXT-œ.txt',
      [
        FALSE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test raw file without extension' => [
      'TÉXT-œ',
      'TÉXT-œ',
      [
        FALSE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test only transliteration: simple' => [
      'Á-TÉXT-œ.txt',
      'A-TEXT-oe.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test only transliteration: raw file without extension' => [
      'Á-TÉXT-œ',
      'A-TEXT-oe',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test only transliteration: complex and replace (-)' => [
      'S  Pácê--táb#	#--🙈.jpg',
      'S  Pace--tab#	#---.jpg',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test only transliteration: complex and replace (_)' => [
      'S  Pácê--táb#	#--🙈.jpg',
      'S  Pace--tab#	#--_.jpg',
      [
        TRUE,
        '_',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (-) and replace whitespace (trim front)' => [
      '  S  Pácê--táb#	#--🙈.png',
      'S--Pace--tab#-#---.png',
      [
        TRUE,
        '-',
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (-) and replace whitespace (trim both sides)' => [
      '  S  Pácê--táb#	#--🙈   .jpg',
      'S--Pace--tab#-#---.jpg',
      [
        TRUE,
        '-',
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (_) and replace whitespace (trim both sides)' => [
      '  S  Pácê--táb#	#--🙈  .jpg',
      'S__Pace--tab#_#--_.jpg',
      [
        TRUE,
        '_',
        TRUE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (_), replace whitespace and replace non-alphanumeric' => [
      '  S  Pácê--táb#	#--🙈.txt',
      'S__Pace--tab___--_.txt',
      [
        TRUE,
        '_',
        TRUE,
        TRUE,
        FALSE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (-), replace whitespace and replace non-alphanumeric' => [
      '  S  Pácê--táb#	#--🙈.txt',
      'S--Pace--tab------.txt',
      [
        TRUE,
        '-',
        TRUE,
        TRUE,
        FALSE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (-), replace whitespace, replace non-alphanumeric and removing duplicate separators' => [
      'S  Pácê--táb#	#--🙈.txt',
      'S-Pace-tab.txt',
      [
        TRUE,
        '-',
        TRUE,
        TRUE,
        TRUE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (-), replace whitespace and deduplicate separators' => [
      '  S  Pácê--táb#	#--🙈.txt',
      'S-Pace-tab#-#.txt',
      [
        TRUE,
        '-',
        TRUE,
        FALSE,
        TRUE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (_), replace whitespace, replace non-alphanumeric and deduplicate separators' => [
      'S  Pácê--táb#	#--🙈.txt',
      'S_Pace_tab.txt',
      [
        TRUE,
        '_',
        TRUE,
        TRUE,
        TRUE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (-), replace whitespace, replace non-alphanumeric, deduplicate separators and lowercase conversion' => [
      'S  Pácê--táb#	#--🙈.jpg',
      's-pace-tab.jpg',
      [
        TRUE,
        '-',
        TRUE,
        TRUE,
        TRUE,
        TRUE,
      ],
    ],
    'Test transliteration, replace (_), replace whitespace, replace non-alphanumeric, deduplicate separators and lowercase conversion' => [
      'S  Pácê--táb#	#--🙈.txt',
      's_pace_tab.txt',
      [
        TRUE,
        '_',
        TRUE,
        TRUE,
        TRUE,
        TRUE,
      ],
    ],
    'Ignore non-alphanumeric replacement if transliteration is not set, but still replace whitespace, deduplicate separators, and lowercase' => [
      '  2S  Pácê--táb#	#--🙈.txt',
      '2s-pácê-táb#-#-🙈.txt',
      [
        FALSE,
        '-',
        TRUE,
        TRUE,
        TRUE,
        TRUE,
      ],
    ],
    'Only lowercase, simple' => [
      'TEXT.txt',
      'text.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        TRUE,
      ],
    ],
    'Only lowercase, with unicode' => [
      'TÉXT.txt',
      'text.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        TRUE,
      ],
    ],
    'No transformations' => [
      'Ä Ö Ü Å Ø äöüåøhello.txt',
      'Ä Ö Ü Å Ø äöüåøhello.txt',
      [
        FALSE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Transliterate via en (not de), no other transformations' => [
      'Ä Ö Ü Å Ø äöüåøhello.txt',
      'A O U A O aouaohello.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Transliterate via de (not en), no other transformations' => [
      'Ä Ö Ü Å Ø äöüåøhello.txt',
      'Ae Oe Ue A O aeoeueaohello.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
      'de',
    ],
    'Transliterate via de not en, plus whitespace + lowercase' => [
      'Ä Ö Ü Å Ø äöüåøhello.txt',
      'ae-oe-ue-a-o-aeoeueaohello.txt',
      [
        TRUE,
        '-',
        TRUE,
        FALSE,
        FALSE,
        TRUE,
      ],
      'de',
    ],
    'Remove duplicate separators with falsey extension' => [
      'foo.....0',
      'foo.0',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        TRUE,
        FALSE,
      ],
    ],
    'Remove duplicate separators with extension and ending in dot' => [
      'foo.....txt',
      'foo.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        TRUE,
        FALSE,
      ],
    ],
    'Remove duplicate separators without extension and ending in dot' => [
      'foo.....',
      'foo',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        TRUE,
        FALSE,
      ],
    ],
    'All unknown unicode' => [
      '🙈🙈🙈.txt',
      '---.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    '✓ unicode' => [
      '✓.txt',
      '-.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Multiple ✓ unicode' => [
      '✓✓✓.txt',
      '---.txt',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        FALSE,
        FALSE,
      ],
    ],
    'Test transliteration, replace (-), replace whitespace and removing multiple duplicate separators #1' => [
      'Test_-_file.png',
      'test-file.png',
      [
        TRUE,
        '-',
        TRUE,
        TRUE,
        TRUE,
        TRUE,
      ],
    ],
    'Test transliteration, replace (-), replace whitespace and removing multiple duplicate separators #2' => [
      'Test .. File.png',
      'test-file.png',
      [
        TRUE,
        '-',
        TRUE,
        TRUE,
        TRUE,
        TRUE,
      ],
    ],
    'Test transliteration, replace (-), replace whitespace and removing multiple duplicate separators #3' => [
      'Test -..__-- file.png',
      'test-file.png',
      [
        TRUE,
        '-',
        TRUE,
        TRUE,
        TRUE,
        TRUE,
      ],
    ],
    'Test transliteration, replace (-), replace sequences of dots, underscores and/or dashes with the replacement character' => [
      'abc. --_._-- .abc.jpeg',
      'abc. - .abc.jpeg',
      [
        TRUE,
        '-',
        FALSE,
        FALSE,
        TRUE,
        FALSE,
      ],
    ],
  ];
}

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