function SeparatorTranslationTest::testSeparatorTranslation
Same name in other branches
- 8.9.x core/modules/datetime_range/tests/src/Kernel/SeparatorTranslationTest.php \Drupal\Tests\datetime_range\Kernel\SeparatorTranslationTest::testSeparatorTranslation()
- 10 core/modules/datetime_range/tests/src/Kernel/SeparatorTranslationTest.php \Drupal\Tests\datetime_range\Kernel\SeparatorTranslationTest::testSeparatorTranslation()
- 11.x 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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.