function BookMultilingualTest::testMultilingualBookBreadcrumbBuilder

Same name in other branches
  1. 9 core/modules/book/tests/src/Kernel/BookMultilingualTest.php \Drupal\Tests\book\Kernel\BookMultilingualTest::testMultilingualBookBreadcrumbBuilder()
  2. 10 core/modules/book/tests/src/Kernel/BookMultilingualTest.php \Drupal\Tests\book\Kernel\BookMultilingualTest::testMultilingualBookBreadcrumbBuilder()

Tests various book breadcrumb builder methods return correct translations.

@dataProvider langcodesProvider

File

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

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 = (string) 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);
}

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