function AccessManagerTest::testCheckException

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testCheckException()
  2. 8.9.x core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php \Drupal\Tests\Core\Access\AccessManagerTest::testCheckException()
  3. 11.x 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 463

Class

AccessManagerTest
@coversDefaultClass \Drupal\Core\Access\AccessManager @group Access

Namespace

Drupal\Tests\Core\Access

Code

public function testCheckException($return_value) : void {
    $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')
        ->willReturn($route);
    $this->paramConverter = $this->createMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
    $this->paramConverter
        ->expects($this->any())
        ->method('convert')
        ->willReturn([]);
    $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')
        ->willReturn($return_value);
    $container->set('test_incorrect_value', $access_check);
    $this->checkProvider = new CheckProvider([], $container);
    $this->checkProvider
        ->addCheckService('test_incorrect_value', 'access');
    $access_manager = new AccessManager($route_provider, $this->paramConverter, $this->argumentsResolverFactory, $this->currentUser, $this->checkProvider);
    $this->expectException(AccessException::class);
    $access_manager->checkNamedRoute('test_incorrect_value', [], $this->account);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.