SimplifyMenuTest.php in Simplify Menu 8.2
File
src/Tests/SimplifyMenuTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\simplify_menu\Functional;
use Drupal\Tests\BrowserTestBase;
class SimplifyMenuTest extends BrowserTestBase {
protected $profile = 'standard';
protected $adminUser;
protected static $modules = [
'node',
'simplify_menu',
'simplify_menu_test',
];
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
], 'Admin User', TRUE);
}
public function testTwigExtension() {
$this
->drupalGet('node');
$element = $this
->xpath('//nav[@id="main"]//a[text()="Home" and @href[contains(., "/")]]');
$this
->assertTrue(count($element) === 1, 'The Main menu was rendered correctly');
$element = $this
->xpath('//nav[@id="account"]//a[text()="My account"]');
$this
->assertTrue(count($element) === 0, 'The Account menu is not visible');
$element = $this
->xpath('//nav[@id="account"]//a[text()="Log in" and @href[contains(., "/user/login")]]');
$this
->assertTrue(count($element) === 1, 'The Login menu is visible');
$element = $this
->xpath('//nav[@id="admin"]//a[text()="Administration"]');
$this
->assertTrue(count($element) === 0, 'The Admin menu is not visible');
$element = $this
->xpath('//a[text()="Inaccessible"]');
$this
->assertTrue(count($element) === 0, 'The text Inaccessible should not be on the links');
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('node');
$element = $this
->xpath('//nav[@id="main"]//a[text()="Home" and @href[contains(., "/")]]');
$this
->assertTrue(count($element) === 1, 'The Main menu was rendered correctly');
$element = $this
->xpath('//nav[@id="account"]//a[text()="My account" and @href[contains(., "/user")]]');
$this
->assertTrue(count($element) === 1, 'The Account menu is visible');
$element = $this
->xpath('//nav[@id="account"]//a[text()="Log out" and @href[contains(., "/user/logout")]]');
$this
->assertTrue(count($element) === 1, 'The Login menu is visible');
$element = $this
->xpath('//nav[@id="admin"]//a[text()="Administration" and @href[contains(., "/admin")]]');
$this
->assertTrue(count($element) === 1, 'The Admin menu was rendered correctly');
}
}