class EntityAccessCheckTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php \Drupal\Tests\Core\Entity\EntityAccessCheckTest
Unit test of entity access checking system.
@coversDefaultClass \Drupal\Core\Entity\EntityAccessCheck
@group Access @group Entity
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Entity\EntityAccessCheckTest
Expanded class hierarchy of EntityAccessCheckTest
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityAccessCheckTest.php, line 29 - Contains \Drupal\Tests\Core\Entity\EntityAccessCheckTest.
Namespace
Drupal\Tests\Core\EntityView source
class EntityAccessCheckTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$cache_contexts_manager = $this
->prophesize(CacheContextsManager::class)
->reveal();
$container = new Container();
$container
->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);
}
/**
* Tests the method for checking access to routes.
*/
public function testAccess() {
$route = new Route('/foo/{var_name}', [], [
'_entity_access' => 'var_name.update',
], [
'parameters' => [
'var_name' => [
'type' => 'entity:node',
],
],
]);
/** @var \Drupal\Core\Session\AccountInterface $account */
$account = $this
->prophesize(AccountInterface::class)
->reveal();
/** @var \Drupal\node\NodeInterface|\Prophecy\Prophecy\ObjectProphecy $route_match */
$node = $this
->prophesize(NodeInterface::class);
$node
->access('update', $account, TRUE)
->willReturn(AccessResult::allowed());
$node = $node
->reveal();
/** @var \Drupal\Core\Routing\RouteMatchInterface|\Prophecy\Prophecy\ObjectProphecy $route_match */
$route_match = $this
->prophesize(RouteMatchInterface::class);
$route_match
->getRawParameters()
->willReturn(new ParameterBag([
'var_name' => 1,
]));
$route_match
->getParameters()
->willReturn(new ParameterBag([
'var_name' => $node,
]));
$route_match = $route_match
->reveal();
$access_check = new EntityAccessCheck();
$this
->assertEquals(AccessResult::allowed(), $access_check
->access($route, $route_match, $account));
}
/**
* @covers ::access
*/
public function testAccessWithTypePlaceholder() {
$route = new Route('/foo/{entity_type}/{var_name}', [], [
'_entity_access' => 'var_name.update',
], [
'parameters' => [
'var_name' => [
'type' => 'entity:{entity_type}',
],
],
]);
/** @var \Drupal\Core\Session\AccountInterface $account */
$account = $this
->prophesize(AccountInterface::class)
->reveal();
/** @var \Drupal\node\NodeInterface|\Prophecy\Prophecy\ObjectProphecy $node */
$node = $this
->prophesize(NodeInterface::class);
$node
->access('update', $account, TRUE)
->willReturn(AccessResult::allowed());
$node = $node
->reveal();
/** @var \Drupal\Core\Routing\RouteMatchInterface|\Prophecy\Prophecy\ObjectProphecy $route_match */
$route_match = $this
->prophesize(RouteMatchInterface::class);
$route_match
->getRawParameters()
->willReturn(new ParameterBag([
'entity_type' => 'node',
'var_name' => 1,
]));
$route_match
->getParameters()
->willReturn(new ParameterBag([
'entity_type' => 'node',
'var_name' => $node,
]));
$route_match = $route_match
->reveal();
$access_check = new EntityAccessCheck();
$this
->assertEquals(AccessResult::allowed(), $access_check
->access($route, $route_match, $account));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityAccessCheckTest:: |
protected | function |
Overrides UnitTestCase:: |
|
EntityAccessCheckTest:: |
public | function | Tests the method for checking access to routes. | |
EntityAccessCheckTest:: |
public | function | @covers ::access | |
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. |