function BookMultilingualTest::testMultilingualBookExport

Same name and namespace in other branches
  1. 9 core/modules/book/tests/src/Kernel/BookMultilingualTest.php \Drupal\Tests\book\Kernel\BookMultilingualTest::testMultilingualBookExport()
  2. 11.x 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 239

Class

BookMultilingualTest
Tests multilingual books.

Namespace

Drupal\Tests\book\Kernel

Code

public function testMultilingualBookExport(string $langcode) : void {
  $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);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.