public function AccessManagerTest::testSetChecksWithDynamicAccessChecker in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 157 - Contains \Drupal\Tests\Core\Access\AccessManagerTest.
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
->getMock('Drupal\\Tests\\Core\\Access\\TestAccessCheckInterface');
$this->container
->set('test_access', $access_check);
$this->checkProvider
->addCheckService('test_access', 'access');
$route = new Route('/test-path', array(), array(
'_foo' => '1',
'_bar' => '1',
));
$route2 = new Route('/test-path', array(), array(
'_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'))
->will($this
->returnCallback(function (Route $route) {
return $route
->getRequirement('_bar') == 2;
}));
$this->checkProvider
->setChecks($collection);
$this
->assertEmpty($route
->getOption('_access_checks'));
$this
->assertEquals(array(
'test_access',
), $route2
->getOption('_access_checks'));
}