90272094672355c6b6246856b3b7e9dc64670ccf
[yaffs-website] / web / core / modules / system / tests / src / Functional / Menu / BreadcrumbFrontCacheContextsTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Menu;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests breadcrumbs functionality.
9  *
10  * @group Menu
11  */
12 class BreadcrumbFrontCacheContextsTest extends BrowserTestBase {
13
14   use AssertBreadcrumbTrait;
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = [
22     'block',
23     'node',
24     'path',
25     'user',
26   ];
27
28   /**
29    * A test node with path alias.
30    *
31    * @var \Drupal\node\NodeInterface
32    */
33   protected $nodeWithAlias;
34
35   /**
36    * {@inheritdoc}
37    */
38   protected function setUp() {
39     parent::setUp();
40
41     $this->drupalPlaceBlock('system_breadcrumb_block');
42
43     $user = $this->drupalCreateUser();
44
45     $this->drupalCreateContentType([
46       'type' => 'page',
47     ]);
48
49     // Create a node for front page.
50     $node_front = $this->drupalCreateNode([
51       'uid' => $user->id(),
52     ]);
53
54     // Create a node with a random alias.
55     $this->nodeWithAlias = $this->drupalCreateNode([
56       'uid' => $user->id(),
57       'type' => 'page',
58       'path' => '/' . $this->randomMachineName(),
59     ]);
60
61     // Configure 'node' as front page.
62     $this->config('system.site')
63       ->set('page.front', '/node/' . $node_front->id())
64       ->save();
65
66     \Drupal::cache('render')->deleteAll();
67   }
68
69   /**
70    * Validate that breadcrumb markup get the right cache contexts.
71    *
72    * Checking that the breadcrumb will be printed on node canonical routes even
73    * if it was rendered for the <front> page first.
74    */
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');
81
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');
89   }
90
91 }