diff --git a/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php index 965ede5..80a9ebb 100644 --- a/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php +++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php @@ -33,14 +33,20 @@ public static function getInfo() { * The original string. * @param string $expected * The expected return from PHPTransliteration::transliterate(). + * @param string $unknown_character + * (optional) The character to substitute for characters in $string without + * transliterated equivalents. Defaults to '?'. + * @param int $max_length + * (optional) If provided, return at most this many characters, ensuring + * that the transliteration does not split in the middle of an input + * character's transliteration. * * @dataProvider providerTestPHPTransliteration */ - public function testPHPTransliteration($langcode, $original, $expected) { - $printable = (isset($case[3])) ? $case[3] : $original; + public function testPHPTransliteration($langcode, $original, $expected, $unknown_character = '?', $max_length = NULL) { $transliterator_class = new PHPTransliteration(); - $actual = $transliterator_class->transliterate($original, $langcode); - $this->assertSame($actual, $expected, sprintf('%s transliteration to %s is identical to %s for language %s in new class instance.', $printable, $actual, $expected, $langcode)); + $actual = $transliterator_class->transliterate($original, $langcode, $unknown_character, $max_length); + $this->assertSame($expected, $actual); } /** @@ -66,8 +72,6 @@ public static function providerTestPHPTransliteration() { // 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'); - // Five-byte characters do not work in MySQL, so make a printable version. - $five_byte_printable = '𐌰𐌸'; return array( // Each test case is (language code, input, output). @@ -82,7 +86,7 @@ public static function providerTestPHPTransliteration() { array('fr', $three_byte, 'c'), array('fr', $four_byte, 'wii'), // Test 5-byte characters. - array('en', $five_byte, '??', $five_byte_printable), + 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. @@ -101,6 +105,8 @@ public static function providerTestPHPTransliteration() { 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), ); }