diff --git a/core/lib/Drupal/Core/Access/AccessManager.php b/core/lib/Drupal/Core/Access/AccessManager.php index 3618631..ae68e82 100644 --- a/core/lib/Drupal/Core/Access/AccessManager.php +++ b/core/lib/Drupal/Core/Access/AccessManager.php @@ -95,7 +95,7 @@ protected function applies(Route $route) { * The incoming request object. * * @return bool - * Returns TRUE if the user has access to the route, else FALSE. + * Returns TRUE if the user has access to the route, otherwise FALSE. * * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * If any access check denies access or none explicitly approve. @@ -135,17 +135,14 @@ protected function checkAnd(array $checks, Route $route, Request $request) { } $service_access = $this->checks[$service_id]->access($route, $request); - if ($service_access === AccessCheckInterface::KILL) { - $access = FALSE; - break; + if ($service_access === AccessCheckInterface::ALLOW) { + $access = TRUE; } - if ($service_access === AccessCheckInterface::DENY) { + else { + // On both KILL and DENY stop. $access = FALSE; break; } - if ($service_access === AccessCheckInterface::ALLOW) { - $access = TRUE; - } } return $access; diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index 5a952e7..4aea076 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -117,16 +117,14 @@ public function testCheck() { } /** - * Test \Drupal\Core\Access\AccessManager::check() with conjunctions. + * Provides data for the conjunction test. + * + * @return array + * An array of data for check conjunctions. + * + * @see \Drupal\Tests\Core\Access\AccessManagerTest::testCHeckConjunctions() */ - public function testCheckConjunctions() { - $this->setupAccessChecker(); - $access_check = new DefinedTestAccessCheck(); - $this->container->register('test_access_defined', $access_check); - $this->accessManager->addCheckService('test_access_defined'); - - $request = new Request(); - + public function checkConjunctionsProvider() { $access_configurations = array(); $access_configurations[] = array( 'conjunction' => 'AND', @@ -213,29 +211,38 @@ public function testCheckConjunctions() { 'expected' => FALSE, ); - $expected = array(); - foreach ($access_configurations as $config) { - // Setup a test route for each access configuration. - $name = $config['name']; - $requirements = array( - '_access' => static::convertAccessCheckInterfaceToString($config['condition_one']), - '_test_access' => static::convertAccessCheckInterfaceToString($config['condition_two']), - ); - $options = array('_access_conjunction' => $config['conjunction']); - $this->routeCollection->add($name, new Route($name, array(), $requirements, $options)); - - $expected[$name] = $config['expected']; - } + return $access_configurations; + } - $this->accessManager->setChecks($this->routeCollection); + /** + * Test \Drupal\Core\Access\AccessManager::check() with conjunctions. + * + * @dataProvider checkConjunctionsProvider + */ + public function testCheckConjunctions($conjunction, $name, $condition_one, $condition_two, $expected_access) { + $this->setupAccessChecker(); + $access_check = new DefinedTestAccessCheck(); + $this->container->register('test_access_defined', $access_check); + $this->accessManager->addCheckService('test_access_defined'); - foreach ($expected as $route_name => $expected_access) { - $this->assertSame($this->accessManager->check($this->routeCollection->get($route_name), $request), $expected_access); - } + $request = new Request(); + + $route_collection = new RouteCollection(); + // Setup a test route for each access configuration. + $requirements = array( + '_access' => static::convertAccessCheckInterfaceToString($condition_one), + '_test_access' => static::convertAccessCheckInterfaceToString($condition_two), + ); + $options = array('_access_conjunction' => $conjunction); + $route = new Route($name, array(), $requirements, $options); + $route_collection->add($name, $route); + + $this->accessManager->setChecks($route_collection); + $this->assertSame($this->accessManager->check($route, $request), $expected_access); } /** - * Little helper function to convert AccessCheckInterface constants to string. + * Converts AccessCheckInterface constants to a string. * * @param mixed $constant * The access constant which is tested, so either