function LocaleUpdateTest::testEnableLanguage
Same name in other branches
- 9 core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testEnableLanguage()
- 8.9.x core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testEnableLanguage()
- 11.x core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testEnableLanguage()
Tests automatic translation import when a language is added.
When a language is added, the system will check for translations files of enabled modules and will import them. When a language is removed the system will remove all translations of that language from the database.
File
-
core/
modules/ locale/ tests/ src/ Functional/ LocaleUpdateTest.php, line 366
Class
- LocaleUpdateTest
- Tests for updating the interface translations of projects.
Namespace
Drupal\Tests\locale\FunctionalCode
public function testEnableLanguage() : void {
// Make the hidden test modules look like a normal custom module.
\Drupal::state()->set('locale.test_system_info_alter', TRUE);
// Enable a module.
$edit = [
'modules[locale_test_translate][enable]' => 'locale_test_translate',
];
$this->drupalGet('admin/modules');
$this->submitForm($edit, 'Install');
// Check if there is no Dutch translation yet.
$this->assertTranslation('Extraday', '', 'nl');
// cSpell:disable-next-line
$this->assertTranslation('Tuesday', 'Dienstag', 'de');
// Add a language.
$edit = [
'predefined_langcode' => 'nl',
];
$this->drupalGet('admin/config/regional/language/add');
$this->submitForm($edit, 'Add language');
// Check if the right number of translations are added.
$this->assertSession()
->pageTextContains("One translation file imported. 8 translations were added, 0 translations were updated and 0 translations were removed.");
// cSpell:disable-next-line
$this->assertTranslation('Extra day', 'extra dag', 'nl');
// Check if the language data is added to the database.
$connection = Database::getConnection();
$result = $connection->select('locale_file', 'lf')
->fields('lf', [
'project',
])
->condition('langcode', 'nl')
->execute()
->fetchField();
$this->assertNotEmpty($result, 'Files added to file history');
// Remove a language.
$this->drupalGet('admin/config/regional/language/delete/nl');
$this->submitForm([], 'Delete');
// Check if the language data is removed from the database.
$result = $connection->select('locale_file', 'lf')
->fields('lf', [
'project',
])
->condition('langcode', 'nl')
->execute()
->fetchField();
$this->assertFalse($result, 'Files removed from file history');
// Check that the Dutch translation is gone.
$this->assertTranslation('Extra day', '', 'nl');
// cSpell:disable-next-line
$this->assertTranslation('Tuesday', 'Dienstag', 'de');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.