function LocaleConfigTranslationImportTest::testLocaleRemovalAndConfigOverridePreserve

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

Tests removing a string from Locale changes configuration translations.

File

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

Class

LocaleConfigTranslationImportTest
Tests translation update's effects on configuration translations.

Namespace

Drupal\Tests\locale\Functional

Code

public function testLocaleRemovalAndConfigOverridePreserve() : void {
  // 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->drupalGet('admin/config/regional/language/add');
  $this->submitForm([
    'predefined_langcode' => 'af',
  ], '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->assertEquals($expected, $override->get());
  // Set the translated string to empty.
  $search = [
    'string' => 'Locale can translate',
    'langcode' => 'af',
    'translation' => 'all',
  ];
  $this->drupalGet('admin/config/regional/translate');
  $this->submitForm($search, 'Filter');
  $textarea = $this->assertSession()
    ->elementExists('xpath', '//textarea');
  $lid = $textarea->getAttribute('name');
  $edit = [
    $lid => '',
  ];
  $this->drupalGet('admin/config/regional/translate');
  $this->submitForm($edit, '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->assertEquals($expected, $override->get());
}

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