function LocaleConfigTranslationImportTest::testConfigTranslationImport

Same name in other branches
  1. 9 core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testConfigTranslationImport()
  2. 10 core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testConfigTranslationImport()
  3. 11.x core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testConfigTranslationImport()

Test update changes configuration translations if enabled after language.

File

core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php, line 38

Class

LocaleConfigTranslationImportTest
Tests translation update's effects on configuration translations.

Namespace

Drupal\Tests\locale\Functional

Code

public function testConfigTranslationImport() {
    $admin_user = $this->drupalCreateUser([
        'administer modules',
        'administer site configuration',
        'administer languages',
        'access administration pages',
        'administer permissions',
    ]);
    $this->drupalLogin($admin_user);
    // Add a language. The Afrikaans translation file of locale_test_translate
    // (test.af.po) has been prepared with a configuration translation.
    ConfigurableLanguage::createFromLangcode('af')->save();
    // Enable locale module.
    $this->container
        ->get('module_installer')
        ->install([
        'locale',
    ]);
    $this->resetAll();
    // Enable import of translations. By default this is disabled for automated
    // tests.
    $this->config('locale.settings')
        ->set('translation.import_enabled', TRUE)
        ->set('translation.use_source', LOCALE_TRANSLATION_USE_SOURCE_LOCAL)
        ->save();
    // Add translation permissions now that the locale module has been enabled.
    $edit = [
        'authenticated[translate interface]' => 'translate interface',
    ];
    $this->drupalPostForm('admin/people/permissions', $edit, t('Save permissions'));
    // Check and update the translation status. This will import the Afrikaans
    // translations of locale_test_translate module.
    $this->drupalGet('admin/reports/translations/check');
    // Override the Drupal core translation status to be up to date.
    // Drupal core should not be a subject in this test.
    $status = locale_translation_get_status();
    $status['drupal']['af']->type = 'current';
    \Drupal::state()->set('locale.translation_status', $status);
    $this->drupalPostForm('admin/reports/translations', [], t('Update translations'));
    // Check if configuration translations have been imported.
    $override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'system.maintenance');
    $this->assertEqual($override->get('message'), 'Ons is tans besig met onderhoud op @site. Wees asseblief geduldig, ons sal binnekort weer terug wees.');
}

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