function LocaleConfigSubscriberTest::assertTranslation

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

Ensures a translation exists and is marked as customized.

@internal

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 475

Class

LocaleConfigSubscriberTest
Tests that shipped configuration translations are updated correctly.

Namespace

Drupal\Tests\locale\Kernel

Code

protected function assertTranslation(string $config_name, $translation, string $langcode, bool $customized = TRUE) : void {
    // 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);
}

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