function LocaleConfigSubscriberTest::saveLocaleTranslationData

Same name and namespace in other branches
  1. 10 core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php \Drupal\Tests\locale\Kernel\LocaleConfigSubscriberTest::saveLocaleTranslationData()
  2. 11.x core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php \Drupal\Tests\locale\Kernel\LocaleConfigSubscriberTest::saveLocaleTranslationData()
  3. 8.9.x core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php \Drupal\Tests\locale\Kernel\LocaleConfigSubscriberTest::saveLocaleTranslationData()

Saves translation data from locale module.

This will invoke LocaleConfigSubscriber through the event dispatcher. To make sure the configuration was persisted correctly, the configuration value is checked. Because LocaleConfigSubscriber temporarily disables the override state of the configuration factory we check that the correct value is restored afterwards.

Parameters

string $config_name: The configuration name.

string $key: The configuration key.

string $source: The source string.

string $translation: The translation string to save.

string $langcode: The language code.

bool $is_active: Whether the update will affect the active configuration.

File

core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php, line 304

Class

LocaleConfigSubscriberTest
Tests that shipped configuration translations are updated correctly.

Namespace

Drupal\Tests\locale\Kernel

Code

protected function saveLocaleTranslationData($config_name, $key, $source, $translation, $langcode, $is_active = FALSE) {
  $this->localeConfigManager
    ->reset();
  $this->localeConfigManager
    ->getStringTranslation($config_name, $langcode, $source, '')
    ->setString($translation)
    ->save();
  $this->localeConfigManager
    ->reset();
  $this->localeConfigManager
    ->updateConfigTranslations([
    $config_name,
  ], [
    $langcode,
  ]);
  $this->configFactory
    ->reset($config_name);
  if ($is_active) {
    $this->assertActiveConfig($config_name, $key, $translation, $langcode);
  }
  else {
    $this->assertConfigOverride($config_name, $key, $translation, $langcode);
  }
}

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