class BreadcrumbFrontCacheContextsTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Menu/BreadcrumbFrontCacheContextsTest.php \Drupal\Tests\system\Functional\Menu\BreadcrumbFrontCacheContextsTest
- 10 core/modules/system/tests/src/Functional/Menu/BreadcrumbFrontCacheContextsTest.php \Drupal\Tests\system\Functional\Menu\BreadcrumbFrontCacheContextsTest
- 8.9.x core/modules/system/tests/src/Functional/Menu/BreadcrumbFrontCacheContextsTest.php \Drupal\Tests\system\Functional\Menu\BreadcrumbFrontCacheContextsTest
Tests breadcrumbs functionality.
@group Menu
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Menu\BreadcrumbFrontCacheContextsTest uses \Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of BreadcrumbFrontCacheContextsTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Menu/ BreadcrumbFrontCacheContextsTest.php, line 12
Namespace
Drupal\Tests\system\Functional\MenuView source
class BreadcrumbFrontCacheContextsTest extends BrowserTestBase {
use AssertBreadcrumbTrait;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'block',
'node',
'path',
'user',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'starterkit_theme';
/**
* A test node with path alias.
*
* @var \Drupal\node\NodeInterface
*/
protected $nodeWithAlias;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
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->assertCount(1, $crumbs);
$this->assertSame('Home', $crumbs[0]->getText());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.