You are here

public function LocaleConfigTranslationImportTest::testLocaleRemovalAndConfigOverrideDelete in Drupal 9

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

Tests removing a string from Locale deletes configuration translations.

File

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

Class

LocaleConfigTranslationImportTest
Tests translation update's effects on configuration translations.

Namespace

Drupal\Tests\locale\Functional

Code

public function testLocaleRemovalAndConfigOverrideDelete() {

  // 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');
  $this
    ->assertEquals([
    'translatable_default_with_translation' => 'Locale can translate Afrikaans',
  ], $override
    ->get());

  // Remove the string from translation to simulate a Locale removal. Note
  // that is no current way of doing this in the UI.
  $locale_storage = \Drupal::service('locale.storage');
  $string = $locale_storage
    ->findString([
    'source' => 'Locale can translate',
  ]);
  \Drupal::service('locale.storage')
    ->delete($string);

  // Force a rebuild of config translations.
  $count = Locale::config()
    ->updateConfigTranslations([
    'locale_test_translate.settings',
  ], [
    'af',
  ]);
  $this
    ->assertEquals(1, $count, 'Correct count of updated translations');
  $override = \Drupal::languageManager()
    ->getLanguageConfigOverride('af', 'locale_test_translate.settings');
  $this
    ->assertEquals([], $override
    ->get());
  $this
    ->assertTrue($override
    ->isNew(), 'The configuration override was deleted when the Locale string was deleted.');
}