You are here

protected function LocaleConfigSubscriberTest::assertTranslation in Zircon Profile 8

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

Ensures a translation exists and is marked as customized.

Parameters

string $config_name: The configuration name.

string $translation: The translation.

string $langcode: The language code.

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

Return value

bool TRUE if the assertion succeeded, FALSE otherwise.

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

... See full list

File

core/modules/locale/src/Tests/LocaleConfigSubscriberTest.php, line 469
Contains \Drupal\locale\Tests\LocaleConfigSubscriberTest.

Class

LocaleConfigSubscriberTest
Tests that shipped configuration translations are updated correctly.

Namespace

Drupal\locale\Tests

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,
  ]);
  $pass = $this
    ->assertIdentical(1, count($strings));
  $string = reset($strings);
  if ($this
    ->assertTrue($string instanceof StringInterface)) {

    /** @var \Drupal\locale\StringInterface $string */
    $pass = $pass && $this
      ->assertIdentical($translation, $string
      ->getString());
    $pass = $pass && $this
      ->assertTrue($string
      ->isTranslation());
    if ($this
      ->assertTrue($string instanceof TranslationString)) {

      /** @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.
      return $pass && $this
        ->assertEqual($customized, $string->customized);
    }
  }
  return FALSE;
}