MenuBlockTitleTest.php in Menu block title 8
File
tests/src/Functional/MenuBlockTitleTest.php
View source
<?php
namespace Drupal\Tests\menu_block_title\Functional;
use Drupal\Tests\BrowserTestBase;
class MenuBlockTitleTest extends BrowserTestBase {
protected static $modules = [
'menu_block_title_test',
];
protected $profile = 'minimal';
protected $defaultTheme = 'stark';
protected static $userPermissions = [
'access content',
];
protected function setUp() : void {
parent::setUp();
$account = $this
->drupalCreateUser(static::$userPermissions);
$this
->drupalLogin($account);
}
public function testExistenceOfTestContent() {
$this
->drupalGet('/node/3');
$this
->assertSession()
->statusCodeEquals(200);
}
public function testExistenceOfMenuBlock() {
$this
->drupalGet('/node/3');
$this
->assertSession()
->elementContains('css', '#block-sidebar-nav-main', 'Menu item without children');
}
public function testSecondLevel() {
$href = '/node/1';
$this
->drupalGet('/node/2');
$this
->assertSession()
->elementContains('css', 'h2#block-sidebar-nav-main-menu', 'Test page title for top level nav');
$xpath = $this
->assertSession()
->buildXPathQuery('//h2[@id="block-sidebar-nav-main-menu"]/a[contains(@href, :href)]', [
':href' => $href,
]);
$link = $this
->getSession()
->getPage()
->findAll('xpath', $xpath);
$message = strtr('Link containing href %href found.', [
'%href' => $href,
]);
$this
->assertSession()
->assert(!empty($link), $message);
}
public function testThirdLevel() {
$href = '/node/6';
$this
->drupalGet('/node/7');
$this
->assertSession()
->elementContains('css', 'h2#block-sidebar-nav-main-menu', 'Child of third item');
$xpath = $this
->assertSession()
->buildXPathQuery('//h2[@id="block-sidebar-nav-main-menu"]/a[contains(@href, :href)]', [
':href' => $href,
]);
$link = $this
->getSession()
->getPage()
->findAll('xpath', $xpath);
$message = strtr('Link containing href %href found.', [
'%href' => $href,
]);
$this
->assertSession()
->assert(!empty($link), $message);
}
}