public function LocaleConfigTranslationImportTest::testConfigTranslationModuleInstall in Drupal 10
Same name and namespace in other branches
- 8 core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testConfigTranslationModuleInstall()
- 9 core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testConfigTranslationModuleInstall()
Tests update changes configuration translations if enabled after language.
File
- core/
modules/ locale/ tests/ src/ Functional/ LocaleConfigTranslationImportTest.php, line 122
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
->drupalGet('admin/config/regional/language/add');
$this
->submitForm([
'predefined_langcode' => 'af',
], 'Add language');
// Add the system branding block to the page.
$this
->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
'id' => 'site-branding',
]);
$this
->drupalGet('admin/config/system/site-information');
$this
->submitForm([
'site_slogan' => 'Test site slogan',
], 'Save configuration');
$this
->drupalGet('admin/config/system/site-information/translate/af/edit');
$this
->submitForm([
'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
->assertSession()
->pageTextContains('Test site slogan in Afrikaans');
$override = \Drupal::languageManager()
->getLanguageConfigOverride('af', 'locale_test_translate.settings');
$this
->assertEquals('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
->drupalGet('admin/modules');
$this
->submitForm([
'modules[dblog][enable]' => 'dblog',
], 'Install');
$this
->assertSession()
->pageTextContains('Module Database Logging has been enabled.');
// Get the front page and ensure that the translated configuration still
// appears.
$this
->drupalGet('af');
$this
->assertSession()
->pageTextContains('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
->assertEquals($expected, $override
->get());
}