You are here

public function BookMultilingualTest::testMultilingualBookBreadcrumbBuilder in Drupal 9

Tests various book breadcrumb builder methods return correct translations.

@dataProvider langcodesProvider

File

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

Class

BookMultilingualTest
Tests multilingual books.

Namespace

Drupal\Tests\book\Kernel

Code

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

  // Test a level 3 node.
  $nid = 7;

  /** @var \Drupal\node\NodeInterface $node */
  $node = Node::load($nid);
  $route = new Route('/node/{node}');
  $route_match = new RouteMatch('entity.node.canonical', $route, [
    'node' => $node,
  ], [
    'node' => $nid,
  ]);

  /** @var \Drupal\book\BookBreadcrumbBuilder $bbb */
  $bbb = $this->container
    ->get('book.breadcrumb');
  $links = $bbb
    ->build($route_match)
    ->getLinks();
  $link = array_shift($links);
  $rendered_link = Link::fromTextAndUrl($link
    ->getText(), $link
    ->getUrl())
    ->toString();
  $this
    ->assertStringContainsString("http://{$langcode}.book.test.domain/", $rendered_link);
  $link = array_shift($links);
  $this
    ->assertNodeLinkIsCorrectlyTranslated(1, $link
    ->getText(), $link
    ->getUrl(), $langcode);
  $link = array_shift($links);
  $this
    ->assertNodeLinkIsCorrectlyTranslated(3, $link
    ->getText(), $link
    ->getUrl(), $langcode);
  $this
    ->assertEmpty($links);
}