function AccessManagerTest::testCheckNamedRouteWithDefaultValue
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testCheckNamedRouteWithDefaultValue()
- 10 core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testCheckNamedRouteWithDefaultValue()
- 11.x core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testCheckNamedRouteWithDefaultValue()
Tests the checkNamedRoute with default values.
@covers ::checkNamedRoute
File
-
core/
tests/ Drupal/ Tests/ Core/ Access/ AccessManagerTest.php, line 406
Class
- AccessManagerTest
- @coversDefaultClass \Drupal\Core\Access\AccessManager @group Access
Namespace
Drupal\Tests\Core\AccessCode
public function testCheckNamedRouteWithDefaultValue() {
$this->routeCollection = new RouteCollection();
$route = new Route('/test-route-1/{value}', [
'value' => 'example',
], [
'_test_access' => 'TRUE',
]);
$this->routeCollection
->add('test_route_1', $route);
$this->routeProvider = $this->createMock('Drupal\\Core\\Routing\\RouteProviderInterface');
$this->routeProvider
->expects($this->any())
->method('getRouteByName')
->with('test_route_1')
->willReturn($route);
$map[] = [
'test_route_1',
[
'value' => 'example',
],
'/test-route-1/example',
];
$this->paramConverter = $this->createMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
$this->paramConverter
->expects($this->atLeastOnce())
->method('convert')
->with([
'value' => 'example',
RouteObjectInterface::ROUTE_NAME => 'test_route_1',
RouteObjectInterface::ROUTE_OBJECT => $route,
])
->willReturn([
'value' => 'upcasted_value',
]);
$this->setupAccessArgumentsResolverFactory($this->exactly(2))
->with($this->callback(function ($route_match) {
return $route_match->getParameters()
->get('value') == 'upcasted_value';
}));
$this->accessManager = new AccessManager($this->routeProvider, $this->paramConverter, $this->argumentsResolverFactory, $this->currentUser, $this->checkProvider);
$access_check = $this->createMock('Drupal\\Tests\\Core\\Access\\TestAccessCheckInterface');
$access_check->expects($this->atLeastOnce())
->method('applies')
->willReturn(TRUE);
$access_check->expects($this->atLeastOnce())
->method('access')
->willReturn(AccessResult::forbidden());
$this->container
->set('test_access', $access_check);
$this->container
->setParameter('dynamic_access_check_services', [
'test_access',
]);
$this->checkProvider
->addCheckService('test_access', 'access');
$this->checkProvider
->setChecks($this->routeCollection);
$this->assertEquals(FALSE, $this->accessManager
->checkNamedRoute('test_route_1', [], $this->account));
$this->assertEquals(AccessResult::forbidden(), $this->accessManager
->checkNamedRoute('test_route_1', [], $this->account, TRUE));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.