You are here

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

Test getPerMenuPermissions method.

@covers ::getPerMenuPermissions

File

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

Class

MenuAdminPerMenuAccessTest
Class MenuAdminPerMenuAccessTest.

Namespace

Drupal\Tests\menu_admin_per_menu\Kernel

Code

public function testGetMenuPermissions() {

  // Anonymous users should not have access to the menus.
  $this
    ->assertEmpty(array_keys($this->menuAdminPerMenuAllowedMenus
    ->getPerMenuPermissions($this->anonymousUser)));

  // The authenticated user should not have access to the menus since this
  // user has none of the appropriate permissions.
  $this
    ->assertEmpty(array_keys($this->menuAdminPerMenuAllowedMenus
    ->getPerMenuPermissions($this->authenticatedUser)));

  // Admin user has access to all menus.
  $this
    ->assertEquals([
    'administer admin menu items',
    'administer footer menu items',
    'administer main menu items',
    'administer menu_1 menu items',
    'administer menu_2 menu items',
    'administer menu_3 menu items',
    'administer tools menu items',
    'administer account menu items',
  ], array_keys($this->menuAdminPerMenuAllowedMenus
    ->getPerMenuPermissions($this->adminUser)));

  // User with 'administer menu' permission has no menu permission. In the
  // access checks this is fixed by checking the 'administer menu'
  // permission.
  $this
    ->assertEmpty(array_keys($this->menuAdminPerMenuAllowedMenus
    ->getPerMenuPermissions($this->adminMenuUser)));

  // User with administer menu_1 permission should have access to menu_1.
  $this
    ->assertEquals([
    'administer menu_1 menu items',
  ], array_keys($this->menuAdminPerMenuAllowedMenus
    ->getPerMenuPermissions($this->menu1User)));

  // User with administer menu_2 permission should have access to menu_2.
  $this
    ->assertEquals([
    'administer menu_2 menu items',
  ], array_keys($this->menuAdminPerMenuAllowedMenus
    ->getPerMenuPermissions($this->menu2User)));

  // User that has access to menu_3 because of the hook implementation should
  // also be listed here.
  $this
    ->assertEquals([
    'administer menu_3 menu items',
  ], array_keys($this->menuAdminPerMenuAllowedMenus
    ->getPerMenuPermissions($this->menu3User)));
}