class PhpTransliterationTest
Same name in this branch
- 11.x core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Component\Transliteration\PhpTransliterationTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Core\Transliteration\PhpTransliterationTest
- 9 core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Component\Transliteration\PhpTransliterationTest
- 8.9.x core/tests/Drupal/Tests/Core/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Core\Transliteration\PhpTransliterationTest
- 8.9.x core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Component\Transliteration\PhpTransliterationTest
- 10 core/tests/Drupal/Tests/Core/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Core\Transliteration\PhpTransliterationTest
- 10 core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php \Drupal\Tests\Component\Transliteration\PhpTransliterationTest
Tests Transliteration component functionality.
@group Transliteration
@coversClass \Drupal\Core\Transliteration\PhpTransliteration
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Transliteration\PhpTransliterationTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of PhpTransliterationTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Transliteration/ PhpTransliterationTest.php, line 18
Namespace
Drupal\Tests\Core\TransliterationView source
class PhpTransliterationTest extends UnitTestCase {
/**
* Tests the PhpTransliteration with an alter hook.
*
* @param string $langcode
* The langcode of the string.
* @param string $original
* The string which was not transliterated yet.
* @param string $expected
* The string expected after the transliteration.
* @param string|null $printable
* (optional) An alternative version of the original string which is
* printable in the output.
*
* @dataProvider providerTestPhpTransliterationWithAlter
*/
public function testPhpTransliterationWithAlter($langcode, $original, $expected, $printable = NULL) : void {
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.");
}
/**
* Provides test data for testPhpTransliterationWithAlter.
*
* @return array
*/
public static function providerTestPhpTransliterationWithAlter() {
$random_generator = new Random();
$random = $random_generator->string(10);
// Make some strings with two, three, and four-byte characters for testing.
// Note that the 3-byte character is overridden by the 'kg' language.
// cSpell:disable-next-line
$two_byte = 'Ä Ö Ü Å Ø äöüåøhello';
// These are two Gothic alphabet letters. See
// http://wikipedia.org/wiki/Gothic_alphabet
// They are not in our tables, but should at least give us '?' (unknown).
$five_byte = html_entity_decode('𐌰𐌸', ENT_NOQUOTES, 'UTF-8');
// Five-byte characters do not work in MySQL, so make a printable version.
$five_byte_printable = '𐌰𐌸';
$cases = [
// Test the language override hook in the test module, which changes
// the transliteration of Ä to Z and provides for the 5-byte characters.
// cSpell:disable-next-line
[
'zz',
$two_byte,
'Z O U A O aouaohello',
],
[
'zz',
$random,
$random,
],
[
'zz',
$five_byte,
'ATh',
$five_byte_printable,
],
];
return $cases;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
PhpTransliterationTest::providerTestPhpTransliterationWithAlter | public static | function | Provides test data for testPhpTransliterationWithAlter. | |
PhpTransliterationTest::testPhpTransliterationWithAlter | public | function | Tests the PhpTransliteration with an alter hook. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUp | protected | function | 367 | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.