BreadcrumbFrontCacheContextsTest.php in Drupal 8
File
core/modules/system/tests/src/Functional/Menu/BreadcrumbFrontCacheContextsTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Menu;
use Drupal\Tests\BrowserTestBase;
class BreadcrumbFrontCacheContextsTest extends BrowserTestBase {
use AssertBreadcrumbTrait;
public static $modules = [
'block',
'node',
'path',
'user',
];
protected $defaultTheme = 'classy';
protected $nodeWithAlias;
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('system_breadcrumb_block');
$user = $this
->drupalCreateUser();
$this
->drupalCreateContentType([
'type' => 'page',
]);
$node_front = $this
->drupalCreateNode([
'uid' => $user
->id(),
]);
$this->nodeWithAlias = $this
->drupalCreateNode([
'uid' => $user
->id(),
'type' => 'page',
'path' => '/' . $this
->randomMachineName(),
]);
$this
->config('system.site')
->set('page.front', '/node/' . $node_front
->id())
->save();
\Drupal::cache('render')
->deleteAll();
}
public function testBreadcrumbsFrontPageCache() {
$this
->drupalGet('<front>');
$web_assert = $this
->assertSession();
$web_assert
->elementNotExists('css', '.block-system-breadcrumb-block');
$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
->assertTrue($crumbs[0]
->getText() === 'Home');
}
}