You are here

public function SeparatorsTranslationTest::testSeparatorsTranslation in Date time day 8

Tests the translation of the date_time_day separators.

File

tests/src/Kernel/SeparatorsTranslationTest.php, line 101

Class

SeparatorsTranslationTest
Test to ensure the date_time_day separators are translatable.

Namespace

Drupal\Tests\date_time_day\Kernel

Code

public function testSeparatorsTranslation() {

  // Create an entity.
  $entity = EntityTest::create([
    'name' => $this
      ->randomString(),
    $this->fieldStorage
      ->getName() => [
      'value' => '2018-02-06',
      'start_time_value' => '10:00',
      'end_time_value' => '10:00',
    ],
  ]);

  // Verify the untranslated separator.
  $display = EntityViewDisplay::collectRenderDisplay($entity, 'default');
  $build = $display
    ->build($entity);
  $output = $this->container
    ->get('renderer')
    ->renderRoot($build);
  $this
    ->verbose($output);
  $this
    ->assertStringContainsString('D_UNTRANSLATED', (string) $output);
  $this
    ->assertStringContainsString('T_UNTRANSLATED', (string) $output);

  // Translate the separators.
  ConfigurableLanguage::createFromLangcode('nl')
    ->save();

  /** @var \Drupal\language\ConfigurableLanguageManagerInterface $language_manager */
  $language_manager = $this->container
    ->get('language_manager');
  $language_manager
    ->getLanguageConfigOverride('nl', 'core.entity_view_display.entity_test.entity_test.default')
    ->set('content.' . $this->fieldStorage
    ->getName() . '.settings.day_separator', 'DNL_TRANSLATED!')
    ->save();
  $language_manager
    ->getLanguageConfigOverride('nl', 'core.entity_view_display.entity_test.entity_test.default')
    ->set('content.' . $this->fieldStorage
    ->getName() . '.settings.time_separator', 'TNL_TRANSLATED!')
    ->save();
  $this->container
    ->get('language.config_factory_override')
    ->setLanguage(new Language([
    'id' => 'nl',
  ]));
  $this->container
    ->get('cache_tags.invalidator')
    ->invalidateTags($entity
    ->getCacheTags());
  $display = EntityViewDisplay::collectRenderDisplay($entity, 'default');
  $build = $display
    ->build($entity);
  $output = $this->container
    ->get('renderer')
    ->renderRoot($build);
  $this
    ->verbose($output);
  $this
    ->assertStringContainsString('DNL_TRANSLATED!', (string) $output);
  $this
    ->assertStringContainsString('TNL_TRANSLATED!', (string) $output);
}