You are here

public function LocaleConfigTranslationImportTest::testLocaleRemovalAndConfigOverrideDelete 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::testLocaleRemovalAndConfigOverrideDelete()

Test removing a string from Locale deletes configuration translations.

File

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

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
    ->drupalPostForm('admin/config/regional/language/add', [
    'predefined_langcode' => 'af',
  ], t('Add language'));
  $override = \Drupal::languageManager()
    ->getLanguageConfigOverride('af', 'locale_test_translate.settings');
  $this
    ->assertEqual([
    '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
    ->assertEqual($count, 1, 'Correct count of updated translations');
  $override = \Drupal::languageManager()
    ->getLanguageConfigOverride('af', 'locale_test_translate.settings');
  $this
    ->assertEqual([], $override
    ->get());
  $this
    ->assertTrue($override
    ->isNew(), 'The configuration override was deleted when the Locale string was deleted.');
}