public function EntityAccessCheckTest::testAccess 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::testAccess()
Tests the method for checking access to routes.
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityAccessCheckTest.php, line 44 - Contains \Drupal\Tests\Core\Entity\EntityAccessCheckTest.
Class
- EntityAccessCheckTest
- Unit test of entity access checking system.
Namespace
Drupal\Tests\Core\EntityCode
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));
}