function LocaleConfigSubscriberTest::setUpTranslation

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

Sets up a configuration string with a translation.

The actual configuration is already available by installing locale_test module, as it is done in LocaleConfigSubscriberTest::setUp(). This sets up the necessary source and translation strings and verifies that everything is as expected to avoid false positives.

Parameters

string $config_name: The configuration name.

string $key: The configuration key.

string $source: The source string.

string $translation: The translation string.

string $langcode: The language code.

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

2 calls to LocaleConfigSubscriberTest::setUpTranslation()
LocaleConfigSubscriberForeignTest::setUpLocale in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberForeignTest.php
Sets up the locale storage strings to be in line with configuration.
LocaleConfigSubscriberTest::setUpLocale in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php
Sets up the locale storage strings to be in line with configuration.

File

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

Class

LocaleConfigSubscriberTest
Tests that shipped configuration translations are updated correctly.

Namespace

Drupal\Tests\locale\Kernel

Code

protected function setUpTranslation($config_name, $key, $source, $translation, $langcode, $is_active = FALSE) {
    // Create source and translation strings for the configuration value and add
    // the configuration name as a location. This would be performed by
    // locale_translate_batch_import() invoking
    // LocaleConfigManager::updateConfigTranslations() normally.
    $this->localeConfigManager
        ->reset();
    $this->localeConfigManager
        ->getStringTranslation($config_name, $langcode, $source, '')
        ->setString($translation)
        ->setCustomized(FALSE)
        ->save();
    $this->configFactory
        ->reset($config_name);
    $this->localeConfigManager
        ->reset();
    $this->localeConfigManager
        ->updateConfigTranslations([
        $config_name,
    ], [
        $langcode,
    ]);
    if ($is_active) {
        $this->assertActiveConfig($config_name, $key, $translation, $langcode);
    }
    else {
        $this->assertConfigOverride($config_name, $key, $translation, $langcode);
    }
    $this->assertTranslation($config_name, $translation, $langcode, FALSE);
}

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