public function AccessManagerTest::testCheckNamedRouteWithDefaultValue in Drupal 9
Same name and namespace in other branches
- 8 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 - Contains \Drupal\Tests\Core\Access\AccessManagerTest.
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')
->will($this
->returnValue($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,
])
->will($this
->returnValue([
'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')
->will($this
->returnValue(TRUE));
$access_check
->expects($this
->atLeastOnce())
->method('access')
->will($this
->returnValue(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));
}