public function LocaleUpdateTest::testEnableCustomLanguage in Drupal 8
Same name and namespace in other branches
- 9 core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testEnableCustomLanguage()
Tests automatic translation import when a custom language is added.
File
- core/
modules/ locale/ tests/ src/ Functional/ LocaleUpdateTest.php, line 388
Class
- LocaleUpdateTest
- Tests for updating the interface translations of projects.
Namespace
Drupal\Tests\locale\FunctionalCode
public function testEnableCustomLanguage() {
// 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
->drupalPostForm('admin/modules', $edit, t('Install'));
// Create a custom language with language code 'xx' and a random
// name.
$langcode = 'xx';
$name = $this
->randomMachineName(16);
$edit = [
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
];
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
// Ensure the translation file is automatically imported when the language
// was added.
$this
->assertText(t('One translation file imported.'), 'Language file automatically imported.');
$this
->assertText(t('One translation string was skipped because of disallowed or malformed HTML'), 'Language file automatically imported.');
// Ensure the strings were successfully imported.
$search = [
'string' => 'lundi',
'langcode' => $langcode,
'translation' => 'translated',
];
$this
->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this
->assertNoText(t('No strings available.'), 'String successfully imported.');
// Ensure the multiline string was imported.
$search = [
'string' => 'Source string for multiline translation',
'langcode' => $langcode,
'translation' => 'all',
];
$this
->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this
->assertText('Multiline translation string to make sure that import works with it.', 'String successfully imported.');
// Ensure 'Allowed HTML source string' was imported but the translation for
// 'Another allowed HTML source string' was not because it contains invalid
// HTML.
$search = [
'string' => 'HTML source string',
'langcode' => $langcode,
'translation' => 'all',
];
$this
->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this
->assertText('Allowed HTML source string', 'String successfully imported.');
$this
->assertNoText('Another allowed HTML source string', 'String with disallowed translation not imported.');
}