public function AccessManagerTest::testCheckException in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testCheckException()
- 10 core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testCheckException()
Tests that an access checker throws an exception for not allowed values.
@dataProvider providerCheckException
File
- core/
tests/ Drupal/ Tests/ Core/ Access/ AccessManagerTest.php, line 476 - Contains \Drupal\Tests\Core\Access\AccessManagerTest.
Class
- AccessManagerTest
- @coversDefaultClass \Drupal\Core\Access\AccessManager @group Access
Namespace
Drupal\Tests\Core\AccessCode
public function testCheckException($return_value) {
$route_provider = $this
->createMock('Drupal\\Core\\Routing\\RouteProviderInterface');
// Setup a test route for each access configuration.
$requirements = [
'_test_incorrect_value' => 'TRUE',
];
$options = [
'_access_checks' => [
'test_incorrect_value',
],
];
$route = new Route('', [], $requirements, $options);
$route_provider
->expects($this
->any())
->method('getRouteByName')
->will($this
->returnValue($route));
$this->paramConverter = $this
->createMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
$this->paramConverter
->expects($this
->any())
->method('convert')
->will($this
->returnValue([]));
$this
->setupAccessArgumentsResolverFactory();
$container = new ContainerBuilder();
// Register a service that will return an incorrect value.
$access_check = $this
->createMock('Drupal\\Tests\\Core\\Access\\TestAccessCheckInterface');
$access_check
->expects($this
->any())
->method('access')
->will($this
->returnValue($return_value));
$container
->set('test_incorrect_value', $access_check);
$access_manager = new AccessManager($route_provider, $this->paramConverter, $this->argumentsResolverFactory, $this->currentUser, $this->checkProvider);
$this->checkProvider
->setContainer($container);
$this->checkProvider
->addCheckService('test_incorrect_value', 'access');
$this
->expectException(AccessException::class);
$access_manager
->checkNamedRoute('test_incorrect_value', [], $this->account);
}