function ConfigTranslationUiTest::testLocaleDBStorage

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

Test translation storage in locale storage.

File

core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php, line 810

Class

ConfigTranslationUiTest
Translate settings and entities to various languages.

Namespace

Drupal\Tests\config_translation\Functional

Code

public function testLocaleDBStorage() {
    // 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();
    $this->drupalLogin($this->adminUser);
    $langcode = 'xx';
    $name = $this->randomMachineName(16);
    $edit = [
        'predefined_langcode' => 'custom',
        'langcode' => $langcode,
        'label' => $name,
        'direction' => Language::DIRECTION_LTR,
    ];
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
    // Make sure there is no translation stored in locale storage before edit.
    $translation = $this->getTranslation('user.settings', 'anonymous', 'fr');
    $this->assertTrue(empty($translation));
    // Add custom translation.
    $edit = [
        'translation[config_names][user.settings][anonymous]' => 'Anonyme',
    ];
    $this->drupalPostForm('admin/config/people/accounts/translate/fr/add', $edit, t('Save translation'));
    // Make sure translation stored in locale storage after saved language
    // specific configuration translation.
    $translation = $this->getTranslation('user.settings', 'anonymous', 'fr');
    $this->assertEqual('Anonyme', $translation->getString());
    // revert custom translations to base translation.
    $edit = [
        'translation[config_names][user.settings][anonymous]' => 'Anonymous',
    ];
    $this->drupalPostForm('admin/config/people/accounts/translate/fr/edit', $edit, t('Save translation'));
    // Make sure there is no translation stored in locale storage after revert.
    $translation = $this->getTranslation('user.settings', 'anonymous', 'fr');
    $this->assertEqual('Anonymous', $translation->getString());
}

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