public function SeparatorTranslationTest::testSeparatorTranslation in Drupal 9
Same name and namespace in other branches
- 8 core/modules/datetime_range/tests/src/Kernel/SeparatorTranslationTest.php \Drupal\Tests\datetime_range\Kernel\SeparatorTranslationTest::testSeparatorTranslation()
Tests the translation of the range separator.
File
- core/
modules/ datetime_range/ tests/ src/ Kernel/ SeparatorTranslationTest.php, line 95
Class
- SeparatorTranslationTest
- Test to ensure the datetime range separator is translatable.
Namespace
Drupal\Tests\datetime_range\KernelCode
public function testSeparatorTranslation() {
// Create an entity.
$entity = EntityTest::create([
'name' => $this
->randomString(),
$this->fieldStorage
->getName() => [
'value' => '2016-09-20',
'end_value' => '2016-09-21',
],
]);
// Verify the untranslated separator.
$display = EntityViewDisplay::collectRenderDisplay($entity, 'default');
$build = $display
->build($entity);
$output = $this->container
->get('renderer')
->renderRoot($build);
$this
->assertStringContainsString('UNTRANSLATED', (string) $output);
// Translate the separator.
ConfigurableLanguage::createFromLangcode('nl')
->save();
/** @var \Drupal\language\ConfigurableLanguageManagerInterface $language_manager */
$language_manager = $this->container
->get('language_manager');
$language_manager
->getLanguageConfigOverride('nl', 'core.entity_view_display.entity_test.entity_test.default')
->set('content.' . $this->fieldStorage
->getName() . '.settings.separator', 'NL_TRANSLATED!')
->save();
$this->container
->get('language.config_factory_override')
->setLanguage(new Language([
'id' => 'nl',
]));
$this->container
->get('cache_tags.invalidator')
->invalidateTags($entity
->getCacheTags());
$display = EntityViewDisplay::collectRenderDisplay($entity, 'default');
$build = $display
->build($entity);
$output = $this->container
->get('renderer')
->renderRoot($build);
$this
->assertStringContainsString('NL_TRANSLATED!', (string) $output);
}