You are here

public function MenuAdminPerMenuMenuPagesTest::testMenuOverviewPage in Menu Admin per Menu 8

Test menu overview page.

File

tests/src/Functional/MenuAdminPerMenuMenuPagesTest.php, line 159

Class

MenuAdminPerMenuMenuPagesTest
Tests the Menu pages in combination with Menu Admin per Menu.

Namespace

Drupal\Tests\menu_admin_per_menu\Functional

Code

public function testMenuOverviewPage() : void {
  $assert_session = $this
    ->assertSession();

  // Anonymous users don't have access to this page.
  $this
    ->drupalGet('admin/structure/menu');
  $assert_session
    ->statusCodeEquals(403);

  // An authenticated user without permissions doesn't have access to this
  // page.
  $this
    ->drupalLogin($this->authenticatedUser);
  $this
    ->drupalGet('admin/structure/menu');
  $assert_session
    ->statusCodeEquals(403);

  // Admin users have access to all menus.
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet('admin/structure/menu');
  $assert_session
    ->statusCodeEquals(200);

  // Make sure the title on the menus overview page is present.
  $assert_session
    ->responseContains('<h1>Menus</h1>');
  $assert_session
    ->pageTextContains('Menu 1 menu');
  $assert_session
    ->pageTextContains('Menu 2 menu');
  $assert_session
    ->pageTextContains('Menu 3 menu');

  // A user with 'administer menu' permission has access to all menus.
  $this
    ->drupalLogin($this->adminMenuUser);
  $this
    ->drupalGet('admin/structure/menu');
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains('Menu 1 menu');
  $assert_session
    ->pageTextContains('Menu 2 menu');
  $assert_session
    ->pageTextContains('Menu 3 menu');

  // A user with 'administer menu_1 menu items' only has access to menu_1.
  $this
    ->drupalLogin($this->menu1User);
  $this
    ->drupalGet('admin/structure/menu');
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains('Menu 1 menu');
  $assert_session
    ->pageTextNotContains('Menu 2 menu');
  $assert_session
    ->pageTextNotContains('Menu 3 menu');

  // A user with 'administer menu_2 menu items' only has access to menu_2.
  $this
    ->drupalLogin($this->menu2User);
  $this
    ->drupalGet('admin/structure/menu');
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextNotContains('Menu 1 menu');
  $assert_session
    ->pageTextContains('Menu 2 menu');
  $assert_session
    ->pageTextNotContains('Menu 3 menu');

  // Permission for this user was added by
  // hook_menu_admin_per_menu_get_permissions_alter.
  $this
    ->drupalLogin($this->menu3User);
  $this
    ->drupalGet('admin/structure/menu');
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextNotContains('Menu 1 menu');
  $assert_session
    ->pageTextNotContains('Menu 2 menu');
  $assert_session
    ->pageTextContains('Menu 3 menu');
}