Tests automatic translation import when a custom langauge is enabled.
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 = array(
'modules[Testing][locale_test_translate][enable]' => 'locale_test_translate',
);
$this
->drupalPost('admin/modules', $edit, t('Save configuration'));
// Create and enable a custom language with language code 'xx' and a random
// name.
$langcode = 'xx';
$name = $this
->randomName(16);
$edit = array(
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'name' => $name,
'direction' => '0',
);
$this
->drupalPost('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.'), t('Language file automatically imported.'));
$this
->assertText(t('One translation string was skipped because of disallowed or malformed HTML'), t('Language file automatically imported.'));
// Ensure the strings were successfully imported.
$search = array(
'string' => 'lundi',
'langcode' => $langcode,
'translation' => 'translated',
);
$this
->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this
->assertNoText(t('No strings available.'), t('String successfully imported.'));
// Ensure the multiline string was imported.
$search = array(
'string' => 'Source string for multiline translation',
'langcode' => $langcode,
'translation' => 'all',
);
$this
->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this
->assertText('Multiline translation string to make sure that import works with it.', t('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 = array(
'string' => 'HTML source string',
'langcode' => $langcode,
'translation' => 'all',
);
$this
->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this
->assertText('Allowed HTML source string', t('String successfully imported.'));
$this
->assertNoText('Another allowed HTML source string', t('String with disallowed translation not imported.'));
}