function LocaleConfigTranslationImportTest::testLocaleRemovalAndConfigOverrideDelete

Same name in other branches
  1. 9 core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testLocaleRemovalAndConfigOverrideDelete()
  2. 8.9.x core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php \Drupal\Tests\locale\Functional\LocaleConfigTranslationImportTest::testLocaleRemovalAndConfigOverrideDelete()
  3. 10 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 198

Class

LocaleConfigTranslationImportTest
Tests translation update's effects on configuration translations.

Namespace

Drupal\Tests\locale\Functional

Code

public function testLocaleRemovalAndConfigOverrideDelete() : 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');
    $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 = \Drupal::service('locale.config_manager')->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.');
}

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