summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAlex Pott2019-01-13 22:34:54 (GMT)
committerAlex Pott2019-01-13 22:35:02 (GMT)
commit94bfb9e5db60879f5c57b80accbcccc85d364e20 (patch)
tree520be5f3b4d2d54a13c67bf1207f025e9da8ed66 /core
parent8a96202f3528008f4965d1975b5a28439fd11233 (diff)
Issue #3015992 by Krzysztof Domański, alexpott, larowlan: Not affecting spacing in PhpTransliterationTestHEAD8.6.x
(cherry picked from commit a09ce7750a838110ee4cbeb263c836c8e5b420a5)
Diffstat (limited to 'core')
-rw-r--r--core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php67
1 files changed, 12 insertions, 55 deletions
diff --git a/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
index b6a79b3..9f30353 100644
--- a/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
+++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
@@ -118,7 +118,8 @@ class PhpTransliterationTest extends TestCase {
$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 @@ class PhpTransliterationTest extends TestCase {
// 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 @@ class PhpTransliterationTest extends TestCase {
['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 !'],
];
}