Unverified Commit 94bfb9e5 authored by alexpott's avatar alexpott

Issue #3015992 by Krzysztof Domański, alexpott, larowlan: Not affecting...

Issue #3015992 by Krzysztof Domański, alexpott, larowlan: Not affecting spacing in PhpTransliterationTest

(cherry picked from commit a09ce775)
parent 8a96202f
......@@ -118,7 +118,8 @@ public function providerTestPhpTransliteration() {
$five_byte = html_entity_decode('𐌰𐌸', ENT_NOQUOTES, 'UTF-8');
return [
// Each test case is (language code, input, output).
// Each test case is language code, input, output, unknown character, max
// length.
// Test ASCII in English.
['en', $random, $random],
// Test ASCII in some other language with no overrides.
......@@ -143,60 +144,9 @@ public function providerTestPhpTransliteration() {
// Turkish, provided by drupal.org user Kartagis.
['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.'],
// Max length.
['de', $two_byte, 'Ae Oe', '?', 5],
];
}
/**
* Tests the transliteration with max length.
*/
public function testTransliterationWithMaxLength() {
$transliteration = new PhpTransliteration();
// Test with max length, using German. It should never split up the
// transliteration of a single character.
$input = 'Ä Ö Ü Å Ø äöüåøhello';
$trunc_output = 'Ae Oe Ue A O aeoe';
$this->assertSame($trunc_output, $transliteration->transliterate($input, 'de', '?', 17), 'Truncating to 17 characters works');
$this->assertSame($trunc_output, $transliteration->transliterate($input, 'de', '?', 18), 'Truncating to 18 characters works');
}
/**
* Tests the unknown character replacement.
*
* @param string $langcode
* The language code to test.
* @param string $original
* The original string.
* @param string $expected
* The expected return from PhpTransliteration::transliterate().
* @param string $unknown_character
* The character to substitute for characters in $string without
* transliterated equivalents.
* @param int $max_length
* The maximum length of the string that returns the transliteration.
*
* @dataProvider providerTestTransliterationUnknownCharacter
*/
public function testTransliterationUnknownCharacter($langcode, $original, $expected, $unknown_character = '?', $max_length = NULL) {
$transliteration = new PhpTransliteration();
$actual = $transliteration->transliterate($original, $langcode, $unknown_character, $max_length);
$this->assertSame($expected, $actual);
}
/**
* Provides data for self::testTransliterationUnknownCharacter().
*
* @return array
* An array of arrays, each containing the parameters for
* self::testTransliterationUnknownCharacter().
*/
public function providerTestTransliterationUnknownCharacter() {
return [
// Each test case is (language code, input, output, unknown character, max
// length).
['de', $two_byte, 'Ae Oe Ue A O aeoe', '?', 17],
// Do not split up the transliteration of a single character.
['de', $two_byte, 'Ae Oe Ue A O aeoe', '?', 18],
// Illegal/unknown unicode.
['en', chr(0xF8) . chr(0x80) . chr(0x80) . chr(0x80) . chr(0x80), '?????'],
['en', chr(0xF8) . chr(0x80) . chr(0x80) . chr(0x80) . chr(0x80), '-----', '-'],
......@@ -213,6 +163,13 @@ public function providerTestTransliterationUnknownCharacter() {
['pl', chr(0x80) . 'óóść', 'ooosc', 'ó'],
// Ensure question marks are replaced when max length used.
['en', chr(0x80) . 'ello ? World?', '_ello ?', '_', 7],
// Empty replacement.
['en', chr(0x80) . 'ello World' . chr(0xF8), 'ello World', ''],
// Not affecting spacing from the beginning and end of a string.
['en', ' Hello Abventor! ', ' Hello Abventor! '],
['pl', ' Drupal Kraków Community', ' Drupal Krakow ', '?', 15],
// Keep many spaces between words.
['en', 'Too many spaces between words !', 'Too many spaces between words !'],
];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment