function LocaleUpdateTest::testEnableCustomLanguage

Same name in other branches
  1. 9 core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testEnableCustomLanguage()
  2. 8.9.x core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testEnableCustomLanguage()
  3. 11.x 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 424

Class

LocaleUpdateTest
Tests for updating the interface translations of projects.

Namespace

Drupal\Tests\locale\Functional

Code

public function testEnableCustomLanguage() : 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');
    // 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->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');
    // Ensure the translation file is automatically imported when the language
    // was added.
    $this->assertSession()
        ->pageTextContains('One translation file imported.');
    $this->assertSession()
        ->pageTextContains('One translation string was skipped because of disallowed or malformed HTML');
    // Ensure the strings were successfully imported.
    $search = [
        'string' => 'lundi',
        'langcode' => $langcode,
        'translation' => 'translated',
    ];
    $this->drupalGet('admin/config/regional/translate');
    $this->submitForm($search, 'Filter');
    $this->assertSession()
        ->pageTextNotContains('No strings available.');
    // Ensure the multiline string was imported.
    $search = [
        'string' => 'Source string for multiline translation',
        'langcode' => $langcode,
        'translation' => 'all',
    ];
    $this->drupalGet('admin/config/regional/translate');
    $this->submitForm($search, 'Filter');
    $this->assertSession()
        ->pageTextContains('Multiline translation string to make sure that import works with it.');
    // 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->drupalGet('admin/config/regional/translate');
    $this->submitForm($search, 'Filter');
    $this->assertSession()
        ->pageTextContains('Allowed HTML source string');
    $this->assertSession()
        ->pageTextNotContains('Another allowed HTML source string');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.