You are here

public function AccessManagerTest::testCheckException in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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

@expectedException \Drupal\Core\Access\AccessException

File

core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php, line 480
Contains \Drupal\Tests\Core\Access\AccessManagerTest.

Class

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

Namespace

Drupal\Tests\Core\Access

Code

public function testCheckException($return_value) {
  $route_provider = $this
    ->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');

  // Setup a test route for each access configuration.
  $requirements = array(
    '_test_incorrect_value' => 'TRUE',
  );
  $options = array(
    '_access_checks' => array(
      'test_incorrect_value',
    ),
  );
  $route = new Route('', array(), $requirements, $options);
  $route_provider
    ->expects($this
    ->any())
    ->method('getRouteByName')
    ->will($this
    ->returnValue($route));
  $this->paramConverter = $this
    ->getMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
  $this->paramConverter
    ->expects($this
    ->any())
    ->method('convert')
    ->will($this
    ->returnValue(array()));
  $this
    ->setupAccessArgumentsResolverFactory();
  $container = new ContainerBuilder();

  // Register a service that will return an incorrect value.
  $access_check = $this
    ->getMock('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');
  $access_manager
    ->checkNamedRoute('test_incorrect_value', array(), $this->account);
}