BreadcrumbFunctionalTest.php in Entity Reference Hierarchy 8.2
File
modules/entity_hierarchy_breadcrumb/tests/src/Functional/BreadcrumbFunctionalTest.php
View source
<?php
namespace Drupal\Tests\entity_hierarchy_breadcrumb\Functional;
use Behat\Mink\Element\NodeElement;
use Drupal\Tests\block\Traits\BlockCreationTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\entity_hierarchy\Traits\EntityHierarchyTestTrait;
class BreadcrumbFunctionalTest extends BrowserTestBase {
use EntityHierarchyTestTrait;
use BlockCreationTrait;
const FIELD_NAME = 'parents';
const ENTITY_TYPE = 'entity_test';
protected $defaultTheme = 'stark';
protected static $modules = [
'entity_hierarchy',
'entity_hierarchy_breadcrumb',
'entity_test',
'system',
'user',
'dbal',
'block',
'field',
];
protected function setUp() {
parent::setUp();
$this
->setupEntityHierarchyField(static::ENTITY_TYPE, static::ENTITY_TYPE, static::FIELD_NAME);
$this
->additionalSetup();
$this
->placeBlock('system_breadcrumb_block');
}
public function testBreadcrumbs() {
$children = $this
->createChildEntities($this->parent
->id());
$this
->drupalLogin($this
->drupalCreateUser([
'view test entity',
]));
$this
->drupalGet($this->parent
->toUrl());
$this
->assertElementsOrder('nav[aria-labelledby="system-breadcrumb"] li', [
'Home',
'Parent',
]);
$first_child = reset($children);
$this
->drupalGet($first_child
->toUrl());
$this
->assertElementsOrder('nav[aria-labelledby="system-breadcrumb"] li', [
'Home',
'Parent',
'Child 1',
]);
}
protected function assertElementsOrder($selector, array $elements) {
$dom_nodes = $this
->getSession()
->getPage()
->findAll('css', $selector);
$actual = array_map(function (NodeElement $node) {
return $node
->getText();
}, $dom_nodes);
$this
->assertEquals($elements, $actual);
}
}