public function PhpTransliterationTest::testPhpTransliterationWithAlter in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Core\Transliteration\PhpTransliterationTest::testPhpTransliterationWithAlter()
- 9 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 33
Class
- PhpTransliterationTest
- Tests Transliteration component functionality.
Namespace
Drupal\Tests\Core\TransliterationCode
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
->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$module_handler
->expects($this
->any())
->method('alter')
->willReturnCallback(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://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.");
}