- <?php
- * Tests the transliteration class.
- */
- class TransliterationTest extends BackdropUnitTestCase {
-
- * Tests transliteration API.
- */
- public function testTransliteration() {
- $random = $this->randomName(10);
-
-
- $two_byte = 'Ä Ö Ü Å Ø äöüåøhello';
-
-
- $three_byte = html_entity_decode('ц', ENT_NOQUOTES, 'UTF-8');
-
-
- $four_byte = html_entity_decode('ᐑ', ENT_NOQUOTES, 'UTF-8');
-
- $unknown_character = html_entity_decode('￱', ENT_NOQUOTES, 'UTF-8');
-
- $cases = array(
-
-
- array('en', $random, $random),
-
-
- array('fr', $random, $random),
-
-
-
-
- array('fr', $three_byte, 'c'),
- array('fr', $four_byte, 'wii'),
-
- array('en', $two_byte, 'A O U A O aouaohello'),
-
- array('de', $two_byte, 'Ae Oe Ue A O aeoeueaohello'),
- array('de', $random, $random),
- array('da', $two_byte, 'A O U Aa Oe aouaaoehello'),
- array('da', $random, $random),
- array('kg', $three_byte, 'ts'),
-
-
- array('en', 'foo' . $unknown_character . 'foo', 'foo?foo'),
- array('en', 'foo' . $unknown_character . $unknown_character . $unknown_character . 'foo', 'foo???foo'),
-
-
- array('en', '一個簡單的句子', 'yigejiandandejuzi'),
-
-
- array('bg', 'първа статия', 'parva statiya'),
- );
-
- include_once BACKDROP_ROOT . '/core/includes/transliteration.inc';
- foreach ($cases as $case) {
- list($langcode, $before, $after) = $case;
- $actual = transliteration_get($before, '?', $langcode);
- $this->assertEqual($after, $actual, format_string('@before is correctly transliterated to @after (actual: @actual) in @langcode langcode.', array('@before' => $before, '@after' => $after, '@actual' => $actual, '@langcode' => $langcode)));
- }
- }
-
-
- * Tests machine name transliteration provided by System module.
- */
- public function testMachineNameTransliteration() {
- $unknown_character = html_entity_decode('￱', ENT_NOQUOTES, 'UTF-8');
- $string = " ä $unknown_character test $unknown_character$unknown_character string - gap -_ ";
- $cases = array(
-
- array('en', '_', NULL, NULL, $string, 'a_test_string_gap'),
- array('de', '_', NULL, NULL, $string, 'ae_test_string_gap'),
- array('en', '_', NULL, '[^a-zA-Z0-9_-]+', $string, 'a_test_string_-_gap_-'),
- array('en', '', NULL, NULL, $string, 'ateststringgap'),
- array('en', '', 10, NULL, $string, 'ateststrin'),
- );
- include_once BACKDROP_ROOT . '/core/modules/system/system.admin.inc';
- foreach ($cases as $case) {
- list($langcode, $replace, $maxlength, $replace_pattern, $before, $after) = $case;
- $options = array(
- 'langcode' => $langcode,
- 'replace' => $replace,
- 'maxlength' => $maxlength,
- 'replace_pattern' => $replace_pattern,
- );
-
- $options = array_filter($options, function($variable) { return !is_null($variable); });
- $actual = system_transliterate_machine_name($before, $options);
- $this->assertEqual($after, $actual, format_string('@before is correctly transliterated to @after (actual: @actual) in @langcode langcode with options @options.', array('@before' => $before, '@after' => $after, '@actual' => $actual, '@langcode' => $langcode, '@options' => print_r($options, 1))));
- }
- }
- }