You are here

public function PhpTransliterationTest::providerTestPhpTransliteration in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Component\Transliteration\PhpTransliterationTest::providerTestPhpTransliteration()

Provides data for self::testPhpTransliteration().

Return value

array An array of arrays, each containing the parameters for self::testPhpTransliteration().

File

core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php, line 108
Contains \Drupal\Tests\Component\Transliteration\PhpTransliterationTest.

Class

PhpTransliterationTest
Tests Transliteration component functionality.

Namespace

Drupal\Tests\Component\Transliteration

Code

public function providerTestPhpTransliteration() {
  $random_generator = new Random();
  $random = $random_generator
    ->string(10);

  // Make some strings with two, three, and four-byte characters for testing.
  // Note that the 3-byte character is overridden by the 'kg' language.
  $two_byte = 'Ä Ö Ü Å Ø äöüåøhello';

  // This is a Cyrrillic character that looks something like a u. See
  // http://www.unicode.org/charts/PDF/U0400.pdf
  $three_byte = html_entity_decode('ц', ENT_NOQUOTES, 'UTF-8');

  // This is a Canadian Aboriginal character like a triangle. See
  // http://www.unicode.org/charts/PDF/U1400.pdf
  $four_byte = html_entity_decode('ᐑ', ENT_NOQUOTES, 'UTF-8');

  // These are two Gothic alphabet letters. See
  // http://en.wikipedia.org/wiki/Gothic_alphabet
  // They are not in our tables, but should at least give us '?' (unknown).
  $five_byte = html_entity_decode('𐌰𐌸', ENT_NOQUOTES, 'UTF-8');
  return array(
    // Each test case is (language code, input, output).
    // Test ASCII in English.
    array(
      'en',
      $random,
      $random,
    ),
    // Test ASCII in some other language with no overrides.
    array(
      'fr',
      $random,
      $random,
    ),
    // Test 3 and 4-byte characters in a language without overrides.
    // Note: if the data tables change, these will need to change too! They
    // are set up to test that data table loading works, so values come
    // directly from the data files.
    array(
      'fr',
      $three_byte,
      'c',
    ),
    array(
      'fr',
      $four_byte,
      'wii',
    ),
    // Test 5-byte characters.
    array(
      'en',
      $five_byte,
      '??',
    ),
    // Test a language with no overrides.
    array(
      'en',
      $two_byte,
      'A O U A O aouaohello',
    ),
    // Test language overrides provided by core.
    array(
      'de',
      $two_byte,
      'Ae Oe Ue A O aeoeueaohello',
    ),
    array(
      'de',
      $random,
      $random,
    ),
    array(
      'dk',
      $two_byte,
      'A O U Aa Oe aouaaoehello',
    ),
    array(
      'dk',
      $random,
      $random,
    ),
    array(
      'kg',
      $three_byte,
      'ts',
    ),
    // Test strings in some other languages.
    // Turkish, provided by drupal.org user Kartagis.
    array(
      'tr',
      'Abayı serdiler bize. Söyleyeceğim yüzlerine. Sanırım hepimiz aynı şeyi düşünüyoruz.',
      'Abayi serdiler bize. Soyleyecegim yuzlerine. Sanirim hepimiz ayni seyi dusunuyoruz.',
    ),
    // Illegal/unknown unicode.
    array(
      'en',
      chr(0xf8) . chr(0x80) . chr(0x80) . chr(0x80) . chr(0x80),
      '?',
    ),
    // Max length.
    array(
      'de',
      $two_byte,
      'Ae Oe',
      '?',
      5,
    ),
  );
}