You are here

public function MenuAdminPerMenuAccessTest::testMenuAccess in Menu Admin per Menu 8

Test menu edit page access callback.

@covers ::menuAccess

File

tests/src/Kernel/MenuAdminPerMenuAccessTest.php, line 264

Class

MenuAdminPerMenuAccessTest
Class MenuAdminPerMenuAccessTest.

Namespace

Drupal\Tests\menu_admin_per_menu\Kernel

Code

public function testMenuAccess() {

  // Anonymous users has no access to one of the menus.
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->anonymousUser, $this->menu1));
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->anonymousUser, $this->menu2));
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->anonymousUser, $this->menu3));

  // Anonymous users has no access to one of the menus.
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->authenticatedUser, $this->menu1));
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->authenticatedUser, $this->menu2));
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->authenticatedUser, $this->menu3));

  // Admin user has access to all menus.
  $this
    ->assertEquals(new AccessResultAllowed(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->adminUser, $this->menu1));
  $this
    ->assertEquals(new AccessResultAllowed(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->adminUser, $this->menu2));
  $this
    ->assertEquals(new AccessResultAllowed(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->adminUser, $this->menu3));

  // User with 'administer menu' permission has access to all menus.
  $this
    ->assertEquals(new AccessResultAllowed(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->adminMenuUser, $this->menu1));
  $this
    ->assertEquals(new AccessResultAllowed(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->adminMenuUser, $this->menu2));
  $this
    ->assertEquals(new AccessResultAllowed(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->adminMenuUser, $this->menu3));

  // Menu 1 user has only access to menu 1.
  $this
    ->assertEquals(new AccessResultAllowed(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->menu1User, $this->menu1));
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->menu1User, $this->menu2));
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->menu1User, $this->menu3));

  // Menu 2 user has only access to menu 2.
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->menu2User, $this->menu1));
  $this
    ->assertEquals(new AccessResultAllowed(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->menu2User, $this->menu2));
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->menu2User, $this->menu3));

  // Menu 3 user has only access to menu 3 because of the hook
  // implementation.
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->menu3User, $this->menu1));
  $this
    ->assertEquals(new AccessResultNeutral(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->menu3User, $this->menu2));
  $this
    ->assertEquals(new AccessResultAllowed(), $this->menuAdminPerMenuAllowedMenus
    ->menuAccess($this->menu3User, $this->menu3));
}