You are here

public function MenuAccessControlHandlerTest::testAccess in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Kernel/MenuAccessControlHandlerTest.php \Drupal\Tests\system\Kernel\MenuAccessControlHandlerTest::testAccess()

@covers ::checkAccess @covers ::checkCreateAccess @dataProvider testAccessProvider

File

core/modules/system/tests/src/Kernel/MenuAccessControlHandlerTest.php, line 55

Class

MenuAccessControlHandlerTest
@coversDefaultClass \Drupal\system\MenuAccessControlHandler @group system

Namespace

Drupal\Tests\system\Kernel

Code

public function testAccess($which_user, $which_entity, $view_label_access_result, $view_access_result, $update_access_result, $delete_access_result, $create_access_result) {

  // We must always create user 1, so that a "normal" user has an ID >1.
  $root_user = $this
    ->drupalCreateUser();
  if ($which_user === 'user1') {
    $user = $root_user;
  }
  else {
    $permissions = $which_user === 'admin' ? [
      'administer menu',
    ] : [];
    $user = $this
      ->drupalCreateUser($permissions);
  }
  $entity_values = $which_entity === 'unlocked' ? [
    'locked' => FALSE,
  ] : [
    'locked' => TRUE,
  ];
  $entity_values['id'] = 'llama';
  $entity = Menu::create($entity_values);
  $entity
    ->save();
  static::assertEquals($view_label_access_result, $this->accessControlHandler
    ->access($entity, 'view label', $user, TRUE));
  static::assertEquals($view_access_result, $this->accessControlHandler
    ->access($entity, 'view', $user, TRUE));
  static::assertEquals($update_access_result, $this->accessControlHandler
    ->access($entity, 'update', $user, TRUE));
  static::assertEquals($delete_access_result, $this->accessControlHandler
    ->access($entity, 'delete', $user, TRUE));
  static::assertEquals($create_access_result, $this->accessControlHandler
    ->createAccess(NULL, $user, [], TRUE));
}