You are here

public function PhpTransliterationTest::testPhpTransliterationWithAlter in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Core\Transliteration\PhpTransliterationTest::testPhpTransliterationWithAlter()

Tests the PhpTransliteration with an alter hook.

@dataProvider providerTestPhpTransliterationWithAlter

Parameters

string $langcode: The langcode of the string.

string $original: The string which was not transliterated yet.

string $expected: The string expected after the transliteration.

string|NULL $printable: (optional) An alternative version of the original string which is printable in the output.

File

core/tests/Drupal/Tests/Core/Transliteration/PhpTransliterationTest.php, line 38
Contains \Drupal\Tests\Core\Transliteration\PhpTransliterationTest.

Class

PhpTransliterationTest
Tests Transliteration component functionality.

Namespace

Drupal\Tests\Core\Transliteration

Code

public function testPhpTransliterationWithAlter($langcode, $original, $expected, $printable = NULL) {
  if ($printable === NULL) {
    $printable = $original;
  }

  // Test each case both with a new instance of the transliteration class,
  // and with one that builds as it goes.
  $module_handler = $this
    ->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
  $module_handler
    ->expects($this
    ->any())
    ->method('alter')
    ->will($this
    ->returnCallback(function ($hook, &$overrides, $langcode) {
    if ($langcode == 'zz') {

      // The default transliteration of Ä is A, but change it to Z for testing.
      $overrides[0xc4] = 'Z';

      // Also provide transliterations of two 5-byte characters from
      // http://en.wikipedia.org/wiki/Gothic_alphabet.
      $overrides[0x10330] = 'A';
      $overrides[0x10338] = 'Th';
    }
  }));
  $transliteration = new PhpTransliteration(NULL, $module_handler);
  $actual = $transliteration
    ->transliterate($original, $langcode);
  $this
    ->assertSame($expected, $actual, "'{$printable}' transliteration to '{$actual}' is identical to '{$expected}' for language '{$langcode}' in service instance.");
}