/**
  * Tests the method for checking access to routes.
  */
 public function testAccess()
 {
     $route = new Route('/foo', array(), array('_entity_access' => 'node.update'));
     $request = new Request();
     $node = $this->getMockBuilder('Drupal\\node\\Entity\\Node')->disableOriginalConstructor()->getMock();
     $node->expects($this->any())->method('access')->will($this->returnValue(TRUE));
     $access_check = new EntityAccessCheck();
     $request->attributes->set('node', $node);
     $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $access = $access_check->access($route, $request, $account);
     $this->assertSame(AccessCheckInterface::ALLOW, $access);
 }
Пример #2
0
 /**
  * Tests the method for checking access to routes.
  */
 public function testAccess()
 {
     $route = new Route('/foo', array(), array('_entity_access' => 'node.update'));
     $upcasted_arguments = new ParameterBag();
     $route_match = $this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface');
     $route_match->expects($this->once())->method('getParameters')->will($this->returnValue($upcasted_arguments));
     $node = $this->getMockBuilder('Drupal\\node\\Entity\\Node')->disableOriginalConstructor()->getMock();
     $node->expects($this->any())->method('access')->will($this->returnValue(AccessResult::allowed()->cachePerPermissions()));
     $access_check = new EntityAccessCheck();
     $upcasted_arguments->set('node', $node);
     $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $access = $access_check->access($route, $route_match, $account);
     $this->assertEquals(AccessResult::allowed()->cachePerPermissions(), $access);
 }
Пример #3
0
 /**
  * @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));
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     // Backup the original requirements.
     $original_requirements = $route->getRequirements();
     // Replace it with our entity access value and run the parent access check.
     $route->setRequirement('_entity_access', $route->getRequirement('_page_access'));
     $access = parent::access($route, $route_match, $account);
     // Restore the original requirements.
     $route->setRequirements($original_requirements);
     return $access;
 }