You are here

public function TranslationTest::testTranslatedEntity in Entity Print 8.2

Test the translated version of the printed document.

File

tests/src/Kernel/TranslationTest.php, line 54

Class

TranslationTest
@coversDefaultClass \Drupal\entity_print\PrintBuilder @group entity_print

Namespace

Drupal\Tests\entity_print\Kernel

Code

public function testTranslatedEntity() {
  $node = $this
    ->createNode([
    'title' => 'english',
  ]);
  $node
    ->addTranslation('de', [
    'title' => 'german',
  ])
    ->save();
  $this->container
    ->get('entity_type.manager')
    ->getStorage('node')
    ->resetCache([
    $node
      ->id(),
  ]);
  $this
    ->assertSame('english', $node
    ->getTitle());
  $this
    ->assertSame('german', $node
    ->getTranslation('de')
    ->getTitle());
  $controller = EntityPrintController::create($this->container);

  // Ensure we get the English version of the node by default.
  $this
    ->assertStringContainsString('english', (string) $controller
    ->viewPrintDebug('pdf', 'node', $node
    ->id()));

  // Change the default language and ensure we get the German version.
  $this
    ->config('system.site')
    ->set('default_langcode', 'de')
    ->save();
  $this
    ->assertStringContainsString('german', (string) $controller
    ->viewPrintDebug('pdf', 'node', $node
    ->id()));
}