@@ -118,7 +118,8 @@ public function providerTestPhpTransliteration() {
118118 $ five_byte = html_entity_decode ('𐌰𐌸 ' , ENT_NOQUOTES , 'UTF-8 ' );
119119
120120 return [
121- // Each test case is (language code, input, output).
121+ // Each test case is language code, input, output, unknown character, max
122+ // length.
122123 // Test ASCII in English.
123124 ['en ' , $ random , $ random ],
124125 // Test ASCII in some other language with no overrides.
@@ -143,60 +144,9 @@ public function providerTestPhpTransliteration() {
143144 // Turkish, provided by drupal.org user Kartagis.
144145 ['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. ' ],
145146 // Max length.
146- ['de ' , $ two_byte , 'Ae Oe ' , '? ' , 5 ],
147- ];
148- }
149-
150- /**
151- * Tests the transliteration with max length.
152- */
153- public function testTransliterationWithMaxLength () {
154- $ transliteration = new PhpTransliteration ();
155-
156- // Test with max length, using German. It should never split up the
157- // transliteration of a single character.
158- $ input = 'Ä Ö Ü Å Ø äöüåøhello ' ;
159- $ trunc_output = 'Ae Oe Ue A O aeoe ' ;
160-
161- $ this ->assertSame ($ trunc_output , $ transliteration ->transliterate ($ input , 'de ' , '? ' , 17 ), 'Truncating to 17 characters works ' );
162- $ this ->assertSame ($ trunc_output , $ transliteration ->transliterate ($ input , 'de ' , '? ' , 18 ), 'Truncating to 18 characters works ' );
163- }
164-
165- /**
166- * Tests the unknown character replacement.
167- *
168- * @param string $langcode
169- * The language code to test.
170- * @param string $original
171- * The original string.
172- * @param string $expected
173- * The expected return from PhpTransliteration::transliterate().
174- * @param string $unknown_character
175- * The character to substitute for characters in $string without
176- * transliterated equivalents.
177- * @param int $max_length
178- * The maximum length of the string that returns the transliteration.
179- *
180- * @dataProvider providerTestTransliterationUnknownCharacter
181- */
182- public function testTransliterationUnknownCharacter ($ langcode , $ original , $ expected , $ unknown_character = '? ' , $ max_length = NULL ) {
183- $ transliteration = new PhpTransliteration ();
184- $ actual = $ transliteration ->transliterate ($ original , $ langcode , $ unknown_character , $ max_length );
185- $ this ->assertSame ($ expected , $ actual );
186- }
187-
188- /**
189- * Provides data for self::testTransliterationUnknownCharacter().
190- *
191- * @return array
192- * An array of arrays, each containing the parameters for
193- * self::testTransliterationUnknownCharacter().
194- */
195- public function providerTestTransliterationUnknownCharacter () {
196- return [
197- // Each test case is (language code, input, output, unknown character, max
198- // length).
199-
147+ ['de ' , $ two_byte , 'Ae Oe Ue A O aeoe ' , '? ' , 17 ],
148+ // Do not split up the transliteration of a single character.
149+ ['de ' , $ two_byte , 'Ae Oe Ue A O aeoe ' , '? ' , 18 ],
200150 // Illegal/unknown unicode.
201151 ['en ' , chr (0xF8 ) . chr (0x80 ) . chr (0x80 ) . chr (0x80 ) . chr (0x80 ), '????? ' ],
202152 ['en ' , chr (0xF8 ) . chr (0x80 ) . chr (0x80 ) . chr (0x80 ) . chr (0x80 ), '----- ' , '- ' ],
@@ -213,6 +163,13 @@ public function providerTestTransliterationUnknownCharacter() {
213163 ['pl ' , chr (0x80 ) . 'óóść ' , 'ooosc ' , 'ó ' ],
214164 // Ensure question marks are replaced when max length used.
215165 ['en ' , chr (0x80 ) . 'ello ? World? ' , '_ello ? ' , '_ ' , 7 ],
166+ // Empty replacement.
167+ ['en ' , chr (0x80 ) . 'ello World ' . chr (0xF8 ), 'ello World ' , '' ],
168+ // Not affecting spacing from the beginning and end of a string.
169+ ['en ' , ' Hello Abventor! ' , ' Hello Abventor! ' ],
170+ ['pl ' , ' Drupal Kraków Community ' , ' Drupal Krakow ' , '? ' , 15 ],
171+ // Keep many spaces between words.
172+ ['en ' , 'Too many spaces between words ! ' , 'Too many spaces between words ! ' ],
216173 ];
217174 }
218175
0 commit comments