public function LocaleUpdateTest::testEnableCustomLanguage in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/locale/src/Tests/LocaleUpdateTest.php \Drupal\locale\Tests\LocaleUpdateTest::testEnableCustomLanguage()
Tests automatic translation import when a custom language is added.
File
- core/modules/ locale/ src/ Tests/ LocaleUpdateTest.php, line 389 
- Contains \Drupal\locale\Tests\LocaleUpdateTest.
Class
- LocaleUpdateTest
- Tests for updating the interface translations of projects.
Namespace
Drupal\locale\TestsCode
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 = array(
    'modules[Testing][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 = array(
    '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 = array(
    '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 = array(
    '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 = array(
    '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.');
}