public function TranslationStringTest::testComparison in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/KernelTests/Core/StringTranslation/TranslationStringTest.php \Drupal\KernelTests\Core\StringTranslation\TranslationStringTest::testComparison()
Tests that TranslatableMarkup objects can be compared.
File
- core/
tests/ Drupal/ KernelTests/ Core/ StringTranslation/ TranslationStringTest.php, line 41 - Contains \Drupal\KernelTests\Core\StringTranslation\TranslationStringTest.
Class
- TranslationStringTest
- Tests the TranslatableMarkup class.
Namespace
Drupal\KernelTests\Core\StringTranslationCode
public function testComparison() {
$this
->rebootAndPrepareSettings();
$a = \Drupal::service('string_translation')
->translate('Example @number', [
'@number' => 42,
], [
'langcode' => 'de',
]);
$this
->rebootAndPrepareSettings();
$b = \Drupal::service('string_translation')
->translate('Example @number', [
'@number' => 42,
], [
'langcode' => 'de',
]);
$c = \Drupal::service('string_translation')
->translate('Example @number', [
'@number' => 43,
], [
'langcode' => 'de',
]);
$d = \Drupal::service('string_translation')
->translate('Example @number', [
'@number' => 42,
], [
'langcode' => 'en',
]);
// The two objects have the same settings so == comparison will work.
$this
->assertEquals($a, $b);
// The two objects are not the same object.
$this
->assertNotSame($a, $b);
// TranslationWrappers which have different settings are not equal.
$this
->assertNotEquals($a, $c);
$this
->assertNotEquals($a, $d);
}