function EntityAccessCheckTest::testAccessWithTypePlaceholder

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php \Drupal\Tests\Core\Entity\EntityAccessCheckTest::testAccessWithTypePlaceholder()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php \Drupal\Tests\Core\Entity\EntityAccessCheckTest::testAccessWithTypePlaceholder()
  3. 10 core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php \Drupal\Tests\Core\Entity\EntityAccessCheckTest::testAccessWithTypePlaceholder()

@covers ::access

File

core/tests/Drupal/Tests/Core/Entity/EntityAccessCheckTest.php, line 69

Class

EntityAccessCheckTest
Unit test of entity access checking system.

Namespace

Drupal\Tests\Core\Entity

Code

public function testAccessWithTypePlaceholder() : void {
  $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->createRouteMatchForObject($node);
  $access_check = new EntityAccessCheck();
  $this->assertEquals(AccessResult::allowed(), $access_check->access($route, $route_match, $account));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.