You are here

public function MenuAdminPerMenuNodeFormTest::testMenuPermissionsOnNodeForm in Menu Admin per Menu 8

Test menu_admin_per_menu permissions on node forms.

File

tests/src/Functional/MenuAdminPerMenuNodeFormTest.php, line 180

Class

MenuAdminPerMenuNodeFormTest
Tests the interaction of the node system with menu links.

Namespace

Drupal\Tests\menu_admin_per_menu\Functional

Code

public function testMenuPermissionsOnNodeForm() {
  $assert_session = $this
    ->assertSession();

  // Content only user does not have access to the menu settings.
  $this
    ->drupalLogin($this->contentOnlyUser);
  $this
    ->drupalGet('node/add/menu_test');
  $assert_session
    ->fieldNotExists('menu[enabled]');
  $assert_session
    ->fieldNotExists('menu[menu_parent]');

  // User with 'administer menu_1 menu items' can only add menu items to
  // menu_1.
  $this
    ->drupalLogin($this->menu1User);
  $this
    ->drupalGet('node/add/menu_test');
  $assert_session
    ->fieldExists('menu[enabled]');
  $assert_session
    ->optionExists('menu[menu_parent]', 'menu_1:');
  $assert_session
    ->optionExists('menu[menu_parent]', 'menu_1:menu_1.link');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_2:');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_2:menu_2.link');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_3:');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_3:menu_3.link');
  $this
    ->drupalLogin($this->menu2User);
  $this
    ->drupalGet('node/add/menu_test');
  $assert_session
    ->fieldExists('menu[enabled]');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_1:');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_1:menu_1.link');
  $assert_session
    ->optionExists('menu[menu_parent]', 'menu_2:');
  $assert_session
    ->optionExists('menu[menu_parent]', 'menu_2:menu_2.link');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_3:');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_3:menu_3.link');
  $this
    ->drupalLogin($this->menu3User);
  $this
    ->drupalGet('node/add/menu_test');
  $assert_session
    ->fieldExists('menu[enabled]');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_1:');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_1:menu_1.link');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_2:');
  $assert_session
    ->optionNotExists('menu[menu_parent]', 'menu_2:menu_2.link');
  $assert_session
    ->optionExists('menu[menu_parent]', 'menu_3:');
  $assert_session
    ->optionExists('menu[menu_parent]', 'menu_3:menu_3.link');
}