1 transliteration.test public TransliterationTest::testMachineNameTransliteration()

Tests machine name transliteration provided by System module.

File

core/modules/simpletest/tests/transliteration.test, line 73

Class

TransliterationTest
Tests the transliteration class.

Code

public function testMachineNameTransliteration() {
  $unknown_character = html_entity_decode('￱', ENT_NOQUOTES, 'UTF-8');
  $string = "  ä $unknown_character test $unknown_character$unknown_character string - gap -_ ";
  $cases = array(
    // Keys are langcode, replace, maxlength, replace_pattern, input, output.
    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,
    );
    // Remove NULL options.
    $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))));
  }
}