X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FMenu%2FBreadcrumbFrontCacheContextsTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FMenu%2FBreadcrumbFrontCacheContextsTest.php;h=90272094672355c6b6246856b3b7e9dc64670ccf;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/modules/system/tests/src/Functional/Menu/BreadcrumbFrontCacheContextsTest.php b/web/core/modules/system/tests/src/Functional/Menu/BreadcrumbFrontCacheContextsTest.php new file mode 100644 index 000000000..902720946 --- /dev/null +++ b/web/core/modules/system/tests/src/Functional/Menu/BreadcrumbFrontCacheContextsTest.php @@ -0,0 +1,91 @@ +drupalPlaceBlock('system_breadcrumb_block'); + + $user = $this->drupalCreateUser(); + + $this->drupalCreateContentType([ + 'type' => 'page', + ]); + + // Create a node for front page. + $node_front = $this->drupalCreateNode([ + 'uid' => $user->id(), + ]); + + // Create a node with a random alias. + $this->nodeWithAlias = $this->drupalCreateNode([ + 'uid' => $user->id(), + 'type' => 'page', + 'path' => '/' . $this->randomMachineName(), + ]); + + // Configure 'node' as front page. + $this->config('system.site') + ->set('page.front', '/node/' . $node_front->id()) + ->save(); + + \Drupal::cache('render')->deleteAll(); + } + + /** + * Validate that breadcrumb markup get the right cache contexts. + * + * Checking that the breadcrumb will be printed on node canonical routes even + * if it was rendered for the page first. + */ + public function testBreadcrumbsFrontPageCache() { + // Hit front page first as anonymous user with 'cold' render cache. + $this->drupalGet(''); + $web_assert = $this->assertSession(); + // Verify that no breadcrumb block presents. + $web_assert->elementNotExists('css', '.block-system-breadcrumb-block'); + + // Verify that breadcrumb appears correctly for the test content + // (which is not set as front page). + $this->drupalGet($this->nodeWithAlias->path->alias); + $breadcrumbs = $this->assertSession()->elementExists('css', '.block-system-breadcrumb-block'); + $crumbs = $breadcrumbs->findAll('css', 'ol li'); + $this->assertTrue(count($crumbs) === 1); + $this->assertTrue($crumbs[0]->getText() === 'Home'); + } + +}