function PermissionAccessCheckTest::testAccess
Same name in other branches
- 9 core/modules/user/tests/src/Unit/PermissionAccessCheckTest.php \Drupal\Tests\user\Unit\PermissionAccessCheckTest::testAccess()
- 8.9.x core/modules/user/tests/src/Unit/PermissionAccessCheckTest.php \Drupal\Tests\user\Unit\PermissionAccessCheckTest::testAccess()
- 10 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 73
Class
- PermissionAccessCheckTest
- @coversDefaultClass \Drupal\user\Access\PermissionAccessCheck @group Routing @group Access
Namespace
Drupal\Tests\user\UnitCode
public function testAccess($requirements, $access, array $contexts = [], $message = '') : void {
$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));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.