public function ConfigTranslationUiTest::testDateFormatTranslation in Drupal 8
Same name and namespace in other branches
- 9 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testDateFormatTranslation()
- 10 core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationUiTest::testDateFormatTranslation()
Tests date format translation.
File
- core/
modules/ config_translation/ tests/ src/ Functional/ ConfigTranslationUiTest.php, line 447
Class
- ConfigTranslationUiTest
- Translate settings and entities to various languages.
Namespace
Drupal\Tests\config_translation\FunctionalCode
public function testDateFormatTranslation() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/regional/date-time');
// Check for medium format.
$this
->assertLinkByHref('admin/config/regional/date-time/formats/manage/medium');
// Save default language configuration for a new format.
$edit = [
'label' => 'Custom medium date',
'id' => 'custom_medium',
'date_format_pattern' => 'Y. m. d. H:i',
];
$this
->drupalPostForm('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
// Test translating a default shipped format and our custom format.
$formats = [
'medium' => 'Default medium date',
'custom_medium' => 'Custom medium date',
];
foreach ($formats as $id => $label) {
$translation_base_url = 'admin/config/regional/date-time/formats/manage/' . $id . '/translate';
$this
->drupalGet($translation_base_url);
// 'Add' link should be present for French translation.
$translation_page_url = "{$translation_base_url}/fr/add";
$this
->assertLinkByHref($translation_page_url);
// Make sure original text is present on this page.
$this
->drupalGet($translation_page_url);
$this
->assertText($label);
// Make sure that the date library is added.
$this
->assertRaw('core/modules/system/js/system.date.js');
// Update translatable fields.
$edit = [
'translation[config_names][core.date_format.' . $id . '][label]' => $id . ' - FR',
'translation[config_names][core.date_format.' . $id . '][pattern]' => 'D',
];
// Save language specific version of form.
$this
->drupalPostForm($translation_page_url, $edit, t('Save translation'));
// Get translation and check we've got the right value.
$override = \Drupal::languageManager()
->getLanguageConfigOverride('fr', 'core.date_format.' . $id);
$expected = [
'label' => $id . ' - FR',
'pattern' => 'D',
];
$this
->assertEqual($expected, $override
->get());
// Formatting the date 8 / 27 / 1985 @ 13:37 EST with pattern D should
// display "Tue".
$formatted_date = $this->container
->get('date.formatter')
->format(494015820, $id, NULL, 'America/New_York', 'fr');
$this
->assertEqual($formatted_date, 'Tue', 'Got the right formatted date using the date format translation pattern.');
}
}