class PermissionAccessCheckTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/user/tests/src/Unit/PermissionAccessCheckTest.php \Drupal\Tests\user\Unit\PermissionAccessCheckTest
@coversDefaultClass \Drupal\user\Access\PermissionAccessCheck @group Routing @group AccessF
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\user\Unit\PermissionAccessCheckTest
Expanded class hierarchy of PermissionAccessCheckTest
File
- core/
modules/ user/ tests/ src/ Unit/ PermissionAccessCheckTest.php, line 22 - Contains \Drupal\Tests\user\Unit\PermissionAccessCheckTest.
Namespace
Drupal\Tests\user\UnitView source
class PermissionAccessCheckTest extends UnitTestCase {
/**
* The tested access checker.
*
* @var \Drupal\user\Access\PermissionAccessCheck
*/
public $accessCheck;
/**
* The dependency injection container.
*
* @var \Symfony\Component\DependencyInjection\ContainerBuilder
*/
protected $container;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->container = new ContainerBuilder();
$cache_contexts_manager = $this
->prophesize(CacheContextsManager::class);
$cache_contexts_manager
->assertValidTokens()
->willReturn(TRUE);
$cache_contexts_manager
->reveal();
$this->container
->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($this->container);
$this->accessCheck = new PermissionAccessCheck();
}
/**
* Provides data for the testAccess method.
*
* @return array
*/
public function providerTestAccess() {
return [
[
[],
FALSE,
],
[
[
'_permission' => 'allowed',
],
TRUE,
[
'user.permissions',
],
],
[
[
'_permission' => 'denied',
],
FALSE,
[
'user.permissions',
],
],
[
[
'_permission' => 'allowed+denied',
],
TRUE,
[
'user.permissions',
],
],
[
[
'_permission' => 'allowed+denied+other',
],
TRUE,
[
'user.permissions',
],
],
[
[
'_permission' => 'allowed,denied',
],
FALSE,
[
'user.permissions',
],
],
];
}
/**
* Tests the access check method.
*
* @dataProvider providerTestAccess
* @covers ::access
*/
public function testAccess($requirements, $access, array $contexts = []) {
$access_result = AccessResult::allowedIf($access)
->addCacheContexts($contexts);
$user = $this
->getMock('Drupal\\Core\\Session\\AccountInterface');
$user
->expects($this
->any())
->method('hasPermission')
->will($this
->returnValueMap([
[
'allowed',
TRUE,
],
[
'denied',
FALSE,
],
[
'other',
FALSE,
],
]));
$route = new Route('', [], $requirements);
$this
->assertEquals($access_result, $this->accessCheck
->access($route, $user));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PermissionAccessCheckTest:: |
public | property | The tested access checker. | |
PermissionAccessCheckTest:: |
protected | property | The dependency injection container. | |
PermissionAccessCheckTest:: |
public | function | Provides data for the testAccess method. | |
PermissionAccessCheckTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PermissionAccessCheckTest:: |
public | function | Tests the access check method. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |