public function LocaleUpdateTest::testEnableLanguage in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/locale/src/Tests/LocaleUpdateTest.php \Drupal\locale\Tests\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/ src/ Tests/ LocaleUpdateTest.php, line 345 - Contains \Drupal\locale\Tests\LocaleUpdateTest.
Class
- LocaleUpdateTest
- Tests for updating the interface translations of projects.
Namespace
Drupal\locale\TestsCode
public function testEnableLanguage() {
// Make the hidden test modules look like a normal custom module.
\Drupal::state()
->set('locale.test_system_info_alter', TRUE);
// Enable a module.
$edit = array(
'modules[Testing][locale_test_translate][enable]' => 'locale_test_translate',
);
$this
->drupalPostForm('admin/modules', $edit, t('Install'));
// Check if there is no Dutch translation yet.
$this
->assertTranslation('Extraday', '', 'nl');
$this
->assertTranslation('Tuesday', 'Dienstag', 'de');
// Add a language.
$edit = array(
'predefined_langcode' => 'nl',
);
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
// Check if the right number of translations are added.
$this
->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array(
'%number' => 8,
'%update' => 0,
'%delete' => 0,
)), 'One language added.');
$this
->assertTranslation('Extraday', 'extra dag', 'nl');
// Check if the language data is added to the database.
$result = db_query("SELECT project FROM {locale_file} WHERE langcode='nl'")
->fetchField();
$this
->assertTrue($result, 'Files added to file history');
// Remove a language.
$this
->drupalPostForm('admin/config/regional/language/delete/nl', array(), t('Delete'));
// Check if the language data is removed from the database.
$result = db_query("SELECT project FROM {locale_file} WHERE langcode='nl'")
->fetchField();
$this
->assertFalse($result, 'Files removed from file history');
// Check that the Dutch translation is gone.
$this
->assertTranslation('Extraday', '', 'nl');
$this
->assertTranslation('Tuesday', 'Dienstag', 'de');
}