You are here

public function LocaleConfigTranslationImportTest::testLocaleRemovalAndConfigOverridePreserve in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testLocaleRemovalAndConfigOverridePreserve()
  2. 10 core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testLocaleRemovalAndConfigOverridePreserve()

Test removing a string from Locale changes configuration translations.

File

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

Class

LocaleConfigTranslationImportTest
Tests translation update's effects on configuration translations.

Namespace

Drupal\Tests\locale\Functional

Code

public function testLocaleRemovalAndConfigOverridePreserve() {

  // Enable the locale module.
  $this->container
    ->get('module_installer')
    ->install([
    'locale',
  ]);
  $this
    ->resetAll();
  $admin_user = $this
    ->drupalCreateUser([
    'administer modules',
    'administer site configuration',
    'administer languages',
    'access administration pages',
    'administer permissions',
    'translate interface',
  ]);
  $this
    ->drupalLogin($admin_user);

  // 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 predefined language.
  $this
    ->drupalPostForm('admin/config/regional/language/add', [
    'predefined_langcode' => 'af',
  ], t('Add language'));
  $override = \Drupal::languageManager()
    ->getLanguageConfigOverride('af', 'locale_test_translate.settings');

  // Update test configuration.
  $override
    ->set('translatable_no_default', 'This translation is preserved')
    ->set('translatable_default_with_no_translation', 'This translation is preserved')
    ->save();
  $expected = [
    'translatable_default_with_translation' => 'Locale can translate Afrikaans',
    'translatable_no_default' => 'This translation is preserved',
    'translatable_default_with_no_translation' => 'This translation is preserved',
  ];
  $this
    ->assertEqual($expected, $override
    ->get());

  // Set the translated string to empty.
  $search = [
    'string' => 'Locale can translate',
    'langcode' => 'af',
    'translation' => 'all',
  ];
  $this
    ->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
  $textareas = $this
    ->xpath('//textarea');
  $textarea = current($textareas);
  $lid = $textarea
    ->getAttribute('name');
  $edit = [
    $lid => '',
  ];
  $this
    ->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
  $override = \Drupal::languageManager()
    ->getLanguageConfigOverride('af', 'locale_test_translate.settings');
  $expected = [
    'translatable_no_default' => 'This translation is preserved',
    'translatable_default_with_no_translation' => 'This translation is preserved',
  ];
  $this
    ->assertEqual($expected, $override
    ->get());
}