You are here

public function BookMultilingualTest::testMultilingualBookExport in Drupal 9

Tests the book export returns correct translations.

@dataProvider langcodesProvider

File

core/modules/book/tests/src/Kernel/BookMultilingualTest.php, line 235

Class

BookMultilingualTest
Tests multilingual books.

Namespace

Drupal\Tests\book\Kernel

Code

public function testMultilingualBookExport(string $langcode) {
  $this
    ->setCurrentLanguage($langcode);

  /** @var \Drupal\book\BookExport $be */
  $be = $this->container
    ->get('book.export');

  /** @var \Drupal\book\BookManagerInterface $bm */
  $bm = $this->container
    ->get('book.manager');
  $books = $bm
    ->getAllBooks();
  $this
    ->assertNotEmpty($books);
  foreach ($books as $book) {
    $contents = $be
      ->bookExportHtml(Node::load($book['bid']))['#contents'][0];
    $this
      ->assertSame($contents["#node"]
      ->language()
      ->getId(), $langcode);
    $this
      ->assertSame($contents["#children"][0]["#node"]
      ->language()
      ->getId(), $langcode);
    $this
      ->assertSame($contents["#children"][1]["#node"]
      ->language()
      ->getId(), $langcode);
    $this
      ->assertSame($contents["#children"][0]["#children"][0]["#node"]
      ->language()
      ->getId(), $langcode);
    $this
      ->assertSame($contents["#children"][0]["#children"][1]["#node"]
      ->language()
      ->getId(), $langcode);
    $this
      ->assertSame($contents["#children"][1]["#children"][0]["#node"]
      ->language()
      ->getId(), $langcode);
    $this
      ->assertSame($contents["#children"][1]["#children"][1]["#node"]
      ->language()
      ->getId(), $langcode);
  }
}