You are here

public function AdministrativeRoleCheckTest::testAccess in Lightning Core 8.3

Same name and namespace in other branches
  1. 8.5 tests/src/Kernel/Access/AdministrativeRoleCheckTest.php \Drupal\Tests\lightning_core\Kernel\Access\AdministrativeRoleCheckTest::testAccess()
  2. 8 tests/src/Kernel/Access/AdministrativeRoleCheckTest.php \Drupal\Tests\lightning_core\Kernel\Access\AdministrativeRoleCheckTest::testAccess()
  3. 8.2 tests/src/Kernel/Access/AdministrativeRoleCheckTest.php \Drupal\Tests\lightning_core\Kernel\Access\AdministrativeRoleCheckTest::testAccess()
  4. 8.4 tests/src/Kernel/Access/AdministrativeRoleCheckTest.php \Drupal\Tests\lightning_core\Kernel\Access\AdministrativeRoleCheckTest::testAccess()

@covers ::access

File

tests/src/Kernel/Access/AdministrativeRoleCheckTest.php, line 27

Class

AdministrativeRoleCheckTest
@coversDefaultClass \Drupal\lightning_core\Access\AdministrativeRoleCheck

Namespace

Drupal\Tests\lightning_core\Kernel\Access

Code

public function testAccess() {
  $admin_role = $this
    ->randomMachineName();
  Role::create([
    'id' => $admin_role,
    'label' => $admin_role,
    'is_admin' => TRUE,
  ])
    ->save();
  $route = new Route('/foo');
  $route_match = new RouteMatch('foo', $route);
  $account = User::create();
  $account
    ->addRole($admin_role);
  $access_check = new AdministrativeRoleCheck($this->container
    ->get('entity_type.manager'));
  $this
    ->assertTrue($access_check
    ->access($route, $route_match, $account)
    ->isAllowed());
  $account
    ->removeRole($admin_role);
  $this
    ->assertTrue($access_check
    ->access($route, $route_match, $account)
    ->isForbidden());
}