function EntityBundleAccessCheckTest::testRouteAccess

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityBundleAccessCheckTest.php \Drupal\Tests\Core\Entity\EntityBundleAccessCheckTest::testRouteAccess()

@covers ::access

@dataProvider getBundleAndAccessResult

File

core/tests/Drupal/Tests/Core/Entity/EntityBundleAccessCheckTest.php, line 74

Class

EntityBundleAccessCheckTest
Unit test of entity access checking system.

Namespace

Drupal\Tests\Core\Entity

Code

public function testRouteAccess($bundle, $access_requirement, $access_result) {
    $route = new Route('/foo/{node}', [], [
        '_entity_bundles' => $access_requirement,
    ], [
        'parameters' => [
            'node' => [
                'type' => 'entity:node',
            ],
        ],
    ]);
    
    /** @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->bundle()
        ->willReturn($bundle);
    $node->getCacheContexts()
        ->willReturn([]);
    $node->getCacheTags()
        ->willReturn([]);
    $node->getCacheMaxAge()
        ->willReturn(-1);
    $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([
        'node' => 1,
    ]));
    $route_match->getParameters()
        ->willReturn(new ParameterBag([
        'node' => $node,
    ]));
    $route_match = $route_match->reveal();
    $access_check = new EntityBundleAccessCheck();
    $this->assertEquals($access_result, $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.