3 namespace Drupal\Tests\system\Functional\Menu;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests breadcrumbs functionality.
12 class BreadcrumbFrontCacheContextsTest extends BrowserTestBase {
14 use AssertBreadcrumbTrait;
21 public static $modules = [
29 * A test node with path alias.
31 * @var \Drupal\node\NodeInterface
33 protected $nodeWithAlias;
38 protected function setUp() {
41 $this->drupalPlaceBlock('system_breadcrumb_block');
43 $user = $this->drupalCreateUser();
45 $this->drupalCreateContentType([
49 // Create a node for front page.
50 $node_front = $this->drupalCreateNode([
54 // Create a node with a random alias.
55 $this->nodeWithAlias = $this->drupalCreateNode([
58 'path' => '/' . $this->randomMachineName(),
61 // Configure 'node' as front page.
62 $this->config('system.site')
63 ->set('page.front', '/node/' . $node_front->id())
66 \Drupal::cache('render')->deleteAll();
70 * Validate that breadcrumb markup get the right cache contexts.
72 * Checking that the breadcrumb will be printed on node canonical routes even
73 * if it was rendered for the <front> page first.
75 public function testBreadcrumbsFrontPageCache() {
76 // Hit front page first as anonymous user with 'cold' render cache.
77 $this->drupalGet('<front>');
78 $web_assert = $this->assertSession();
79 // Verify that no breadcrumb block presents.
80 $web_assert->elementNotExists('css', '.block-system-breadcrumb-block');
82 // Verify that breadcrumb appears correctly for the test content
83 // (which is not set as front page).
84 $this->drupalGet($this->nodeWithAlias->path->alias);
85 $breadcrumbs = $this->assertSession()->elementExists('css', '.block-system-breadcrumb-block');
86 $crumbs = $breadcrumbs->findAll('css', 'ol li');
87 $this->assertTrue(count($crumbs) === 1);
88 $this->assertTrue($crumbs[0]->getText() === 'Home');