You are here

public function BookMultilingualTest::testMultilingualBookExport in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/book/tests/src/Kernel/BookMultilingualTest.php \Drupal\Tests\book\Kernel\BookMultilingualTest::testMultilingualBookExport()

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);
  }
}