function LocaleConfigTranslationImportTest::testConfigTranslationModuleInstall
Same name in other branches
- 9 core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testConfigTranslationModuleInstall()
- 10 core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testConfigTranslationModuleInstall()
- 11.x core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testConfigTranslationModuleInstall()
Test update changes configuration translations if enabled after language.
File
-
core/
modules/ locale/ tests/ src/ Functional/ LocaleConfigTranslationImportTest.php, line 89
Class
- LocaleConfigTranslationImportTest
- Tests translation update's effects on configuration translations.
Namespace
Drupal\Tests\locale\FunctionalCode
public function testConfigTranslationModuleInstall() {
// Enable locale, block and config_translation modules.
$this->container
->get('module_installer')
->install([
'block',
'config_translation',
]);
$this->resetAll();
// The testing profile overrides locale.settings to disable translation
// import. Test that this override is in place.
$this->assertFalse($this->config('locale.settings')
->get('translation.import_enabled'), 'Translations imports are disabled by default in the Testing profile.');
$admin_user = $this->drupalCreateUser([
'administer modules',
'administer site configuration',
'administer languages',
'access administration pages',
'administer permissions',
'translate configuration',
]);
$this->drupalLogin($admin_user);
// Enable import of translations. By default this is disabled for automated
// tests.
$this->config('locale.settings')
->set('translation.import_enabled', TRUE)
->set('translation.use_source', LOCALE_TRANSLATION_USE_SOURCE_LOCAL)
->save();
// Add predefined language.
$this->drupalPostForm('admin/config/regional/language/add', [
'predefined_langcode' => 'af',
], t('Add language'));
// Add the system branding block to the page.
$this->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
'id' => 'site-branding',
]);
$this->drupalPostForm('admin/config/system/site-information', [
'site_slogan' => 'Test site slogan',
], 'Save configuration');
$this->drupalPostForm('admin/config/system/site-information/translate/af/edit', [
'translation[config_names][system.site][slogan]' => 'Test site slogan in Afrikaans',
], 'Save translation');
// Get the front page and ensure that the translated configuration appears.
$this->drupalGet('af');
$this->assertText('Test site slogan in Afrikaans');
$override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'locale_test_translate.settings');
$this->assertEqual('Locale can translate Afrikaans', $override->get('translatable_default_with_translation'));
// Update test configuration.
$override->set('translatable_no_default', 'This translation is preserved')
->set('translatable_default_with_translation', 'This translation is preserved')
->set('translatable_default_with_no_translation', 'This translation is preserved')
->save();
// Install any module.
$this->drupalPostForm('admin/modules', [
'modules[dblog][enable]' => 'dblog',
], t('Install'));
$this->assertText('Module Database Logging has been enabled.');
// Get the front page and ensure that the translated configuration still
// appears.
$this->drupalGet('af');
$this->assertText('Test site slogan in Afrikaans');
$this->rebuildContainer();
$override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'locale_test_translate.settings');
$expected = [
'translatable_no_default' => 'This translation is preserved',
'translatable_default_with_translation' => 'This translation is preserved',
'translatable_default_with_no_translation' => 'This translation is preserved',
];
$this->assertEqual($expected, $override->get());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.