You are here

public function PermissionAccessCheckTest::testAccess in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Unit/PermissionAccessCheckTest.php \Drupal\Tests\user\Unit\PermissionAccessCheckTest::testAccess()
  2. 9 core/modules/user/tests/src/Unit/PermissionAccessCheckTest.php \Drupal\Tests\user\Unit\PermissionAccessCheckTest::testAccess()

Tests the access check method.

@dataProvider providerTestAccess @covers ::access

File

core/modules/user/tests/src/Unit/PermissionAccessCheckTest.php, line 71

Class

PermissionAccessCheckTest
@coversDefaultClass \Drupal\user\Access\PermissionAccessCheck @group Routing @group Access

Namespace

Drupal\Tests\user\Unit

Code

public function testAccess($requirements, $access, array $contexts = [], $message = '') {
  $access_result = AccessResult::allowedIf($access)
    ->addCacheContexts($contexts);
  if (!empty($message)) {
    $access_result
      ->setReason($message);
  }
  $user = $this
    ->createMock('Drupal\\Core\\Session\\AccountInterface');
  $user
    ->expects($this
    ->any())
    ->method('hasPermission')
    ->willReturnMap([
    [
      'allowed',
      TRUE,
    ],
    [
      'denied',
      FALSE,
    ],
    [
      'other',
      FALSE,
    ],
  ]);
  $route = new Route('', [], $requirements);
  $this
    ->assertEquals($access_result, $this->accessCheck
    ->access($route, $user));
}