Commit 1506516d authored by catch's avatar catch

Issue #2875276 by huzooka, ion.macaria, cestmoi, catch: Breadcrumbs disappears...

Issue #2875276 by huzooka, ion.macaria, cestmoi, catch: Breadcrumbs disappears when starting with front-page after cache rebuild (for anonymous user)
parent e5a4531a
......@@ -27,6 +27,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
'url.path.parent',
'url.query_args:_wrapper_format',
'user.roles',
'url.path.is_front',
// These two cache contexts are added by BigPipe.
'cookies:big_pipe_nojs',
'session.exists',
......
......@@ -144,7 +144,7 @@ public function build(RouteMatchInterface $route_match) {
// Add the url.path.parent cache context. This code ignores the last path
// part so the result only depends on the path parents.
$breadcrumb->addCacheContexts(['url.path.parent']);
$breadcrumb->addCacheContexts(['url.path.parent', 'url.path.is_front']);
// Do not display a breadcrumb on the frontpage.
if ($this->pathMatcher->isFrontPage()) {
......
<?php
namespace Drupal\Tests\system\Functional\Menu;
use Drupal\Tests\BrowserTestBase;
/**
* Tests breadcrumbs functionality.
*
* @group Menu
*/
class BreadcrumbFrontCacheContextsTest extends BrowserTestBase {
use AssertBreadcrumbTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'block',
'node',
'path',
'user',
];
/**
* A test node with path alias.
*
* @var \Drupal\node\NodeInterface
*/
protected $nodeWithAlias;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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 <front> page first.
*/
public function testBreadcrumbsFrontPageCache() {
// Hit front page first as anonymous user with 'cold' render cache.
$this->drupalGet('<front>');
$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');
}
}
......@@ -151,7 +151,7 @@ public function testBuildOnFrontpage() {
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals([], $breadcrumb->getLinks());
$this->assertEquals(['url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.is_front', 'url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
......@@ -168,7 +168,7 @@ public function testBuildWithOnePathElement() {
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.is_front', 'url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
......@@ -203,7 +203,11 @@ public function testBuildWithTwoPathElements() {
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals([0 => new Link('Home', new Url('<front>')), 1 => new Link('Example', new Url('example'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path.parent', 'user.permissions'], $breadcrumb->getCacheContexts());
$this->assertEquals([
'url.path.is_front',
'url.path.parent',
'user.permissions',
], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
......@@ -254,7 +258,12 @@ public function testBuildWithThreePathElements() {
new Link('Example', new Url('example')),
new Link('Bar', new Url('example_bar')),
], $breadcrumb->getLinks());
$this->assertEquals(['bar', 'url.path.parent', 'user.permissions'], $breadcrumb->getCacheContexts());
$this->assertEquals([
'bar',
'url.path.is_front',
'url.path.parent',
'user.permissions',
], $breadcrumb->getCacheContexts());
$this->assertEquals(['example'], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
......@@ -281,7 +290,7 @@ public function testBuildWithException($exception_class, $exception_argument) {
// No path matched, though at least the frontpage is displayed.
$this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.is_front', 'url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
......@@ -325,7 +334,7 @@ public function testBuildWithNonProcessedPath() {
// No path matched, though at least the frontpage is displayed.
$this->assertEquals([0 => new Link('Home', new Url('<front>'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals(['url.path.is_front', 'url.path.parent'], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
......@@ -373,7 +382,11 @@ public function testBuildWithUserPath() {
$breadcrumb = $this->builder->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
$this->assertEquals([0 => new Link('Home', new Url('<front>')), 1 => new Link('Admin', new Url('user_page'))], $breadcrumb->getLinks());
$this->assertEquals(['url.path.parent', 'user.permissions'], $breadcrumb->getCacheContexts());
$this->assertEquals([
'url.path.is_front',
'url.path.parent',
'user.permissions',
], $breadcrumb->getCacheContexts());
$this->assertEquals([], $breadcrumb->getCacheTags());
$this->assertEquals(Cache::PERMANENT, $breadcrumb->getCacheMaxAge());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment