PermissionsTest.php in Menu Item Role Access 8
File
tests/src/Functional/PermissionsTest.php
View source
<?php
namespace Drupal\Tests\menu_item_role_access\Functional;
use Drupal\system\Entity\Menu;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Url;
use Drupal\user\Entity\User;
class PermissionsTest extends BrowserTestBase {
public static $modules = [
'router_test',
'menu_ui',
'menu_link_content',
'menu_item_role_access',
];
protected $adminUser;
protected $noAccessUser;
protected $menuLinkManager;
protected $menuName;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer menu',
'edit menu_item_role_access',
]);
$this->noAccessUser = $this
->drupalCreateUser([
'administer menu',
]);
$this
->drupalLogin($this->adminUser);
$this->menuLinkManager = \Drupal::service('plugin.manager.menu.link');
$this->menuName = 'menu_test';
Menu::create([
'id' => $this->menuName,
'label' => 'Test menu',
'description' => 'Description text',
])
->save();
}
public function testMenuItemRoleAccessFieldExists() {
$this
->getToAddLinkPage($this->adminUser);
$this
->assertSession()
->elementExists('css', '#edit-menu-item-roles-wrapper');
}
public function testMenuItemRoleAccessFieldNoPermission() {
$this
->getToAddLinkPage($this->noAccessUser);
$this
->assertSession()
->elementNotExists('css', '#edit-menu-item-roles-wrapper');
}
private function getToAddLinkPage(User $user) {
$this
->drupalLogin($user);
$this
->drupalGet(Url::fromRoute('entity.menu.edit_form', [
'menu' => $this->menuName,
]));
$this
->clickLink('Add link');
}
}