function AccessManagerTest::testSetChecksWithDynamicAccessChecker
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testSetChecksWithDynamicAccessChecker()
- 10 core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testSetChecksWithDynamicAccessChecker()
- 11.x core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testSetChecksWithDynamicAccessChecker()
Tests setChecks with a dynamic access checker.
File
-
core/
tests/ Drupal/ Tests/ Core/ Access/ AccessManagerTest.php, line 159
Class
- AccessManagerTest
- @coversDefaultClass \Drupal\Core\Access\AccessManager @group Access
Namespace
Drupal\Tests\Core\AccessCode
public function testSetChecksWithDynamicAccessChecker() {
// Setup the access manager.
$this->accessManager = new AccessManager($this->routeProvider, $this->paramConverter, $this->argumentsResolverFactory, $this->currentUser, $this->checkProvider);
// Setup the dynamic access checker.
$access_check = $this->createMock('Drupal\\Tests\\Core\\Access\\TestAccessCheckInterface');
$this->container
->set('test_access', $access_check);
$this->container
->setParameter('dynamic_access_check_services', [
'test_access',
]);
$this->checkProvider
->addCheckService('test_access', 'access');
$route = new Route('/test-path', [], [
'_foo' => '1',
'_bar' => '1',
]);
$route2 = new Route('/test-path', [], [
'_foo' => '1',
'_bar' => '2',
]);
$collection = new RouteCollection();
$collection->add('test_route', $route);
$collection->add('test_route2', $route2);
$access_check->expects($this->exactly(2))
->method('applies')
->with($this->isInstanceOf('Symfony\\Component\\Routing\\Route'))
->willReturnCallback(function (Route $route) {
return $route->getRequirement('_bar') == 2;
});
$this->checkProvider
->setChecks($collection);
$this->assertEmpty($route->getOption('_access_checks'));
$this->assertEquals([
'test_access',
], $route2->getOption('_access_checks'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.