You are here

protected function LocaleConfigSubscriberTest::assertTranslation in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php \Drupal\Tests\locale\Kernel\LocaleConfigSubscriberTest::assertTranslation()

Ensures a translation exists and is marked as customized.

Parameters

string $config_name: The configuration name.

string|array $translation: The translation.

string $langcode: The language code.

bool $customized: Whether or not the string should be asserted to be customized or not customized.

13 calls to LocaleConfigSubscriberTest::assertTranslation()
LocaleConfigSubscriberForeignTest::testCreateActiveTranslation in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberForeignTest.php
Tests creating translations of shipped configuration.
LocaleConfigSubscriberForeignTest::testDeleteActiveTranslation in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberForeignTest.php
Tests deleting translations of shipped configuration.
LocaleConfigSubscriberForeignTest::testDeleteTranslation in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberForeignTest.php
Tests deleting a translation override.
LocaleConfigSubscriberForeignTest::testEnglish in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberForeignTest.php
Tests that adding English creates a translation override.
LocaleConfigSubscriberForeignTest::testLocaleCreateActiveTranslation in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberForeignTest.php
Tests importing community translations of shipped configuration.

... See full list

File

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

Class

LocaleConfigSubscriberTest
Tests that shipped configuration translations are updated correctly.

Namespace

Drupal\Tests\locale\Kernel

Code

protected function assertTranslation($config_name, $translation, $langcode, $customized = TRUE) {

  // Make sure a string exists.
  $strings = $this->stringStorage
    ->getTranslations([
    'type' => 'configuration',
    'name' => $config_name,
    'language' => $langcode,
    'translated' => TRUE,
  ]);
  $this
    ->assertCount(1, $strings);
  $string = reset($strings);
  $this
    ->assertInstanceOf(StringInterface::class, $string);

  /** @var \Drupal\locale\StringInterface $string */
  $this
    ->assertSame($translation, $string
    ->getString());
  $this
    ->assertTrue($string
    ->isTranslation());
  $this
    ->assertInstanceOf(TranslationString::class, $string);

  /** @var \Drupal\locale\TranslationString $string */

  // Make sure the string is marked as customized so that it does not get
  // overridden when the string translations are updated.
  $this
    ->assertEquals($customized, (bool) $string->customized);
}