You are here

public function AccessManagerTest::testCheckNamedRouteWithDefaultValue 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::testCheckNamedRouteWithDefaultValue()

Tests the checkNamedRoute with default values.

@covers ::checkNamedRoute

File

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

Class

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

Namespace

Drupal\Tests\Core\Access

Code

public function testCheckNamedRouteWithDefaultValue() {
  $this->routeCollection = new RouteCollection();
  $route = new Route('/test-route-1/{value}', array(
    'value' => 'example',
  ), array(
    '_test_access' => 'TRUE',
  ));
  $this->routeCollection
    ->add('test_route_1', $route);
  $this->routeProvider = $this
    ->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');
  $this->routeProvider
    ->expects($this
    ->any())
    ->method('getRouteByName')
    ->with('test_route_1', array())
    ->will($this
    ->returnValue($route));
  $map = array();
  $map[] = array(
    'test_route_1',
    array(
      'value' => 'example',
    ),
    '/test-route-1/example',
  );
  $this->paramConverter = $this
    ->getMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
  $this->paramConverter
    ->expects($this
    ->atLeastOnce())
    ->method('convert')
    ->with(array(
    'value' => 'example',
    RouteObjectInterface::ROUTE_NAME => 'test_route_1',
    RouteObjectInterface::ROUTE_OBJECT => $route,
  ))
    ->will($this
    ->returnValue(array(
    'value' => 'upcasted_value',
  )));
  $this
    ->setupAccessArgumentsResolverFactory($this
    ->exactly(2))
    ->with($this
    ->callback(function ($route_match) {
    return $route_match
      ->getParameters()
      ->get('value') == 'upcasted_value';
  }));
  $this->accessManager = new AccessManager($this->routeProvider, $this->paramConverter, $this->argumentsResolverFactory, $this->currentUser, $this->checkProvider);
  $access_check = $this
    ->getMock('Drupal\\Tests\\Core\\Access\\TestAccessCheckInterface');
  $access_check
    ->expects($this
    ->atLeastOnce())
    ->method('applies')
    ->will($this
    ->returnValue(TRUE));
  $access_check
    ->expects($this
    ->atLeastOnce())
    ->method('access')
    ->will($this
    ->returnValue(AccessResult::forbidden()));
  $this->container
    ->set('test_access', $access_check);
  $this->checkProvider
    ->addCheckService('test_access', 'access');
  $this->checkProvider
    ->setChecks($this->routeCollection);
  $this
    ->assertEquals(FALSE, $this->accessManager
    ->checkNamedRoute('test_route_1', array(), $this->account));
  $this
    ->assertEquals(AccessResult::forbidden(), $this->accessManager
    ->checkNamedRoute('test_route_1', array(), $this->account, TRUE));
}