You are here

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

Tests the checkNamedRoute with upcasted values.

See also

\Drupal\Core\Access\AccessManager::checkNamedRoute()

File

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

Class

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

Namespace

Drupal\Tests\Core\Access

Code

public function testCheckNamedRouteWithUpcastedValues() {
  $this->routeCollection = new RouteCollection();
  $route = new Route('/test-route-1/{value}', array(), 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(
    'value' => 'example',
  ))
    ->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(
    'value' => 'example',
  ), $this->account));
  $this
    ->assertEquals(AccessResult::forbidden(), $this->accessManager
    ->checkNamedRoute('test_route_1', array(
    'value' => 'example',
  ), $this->account, TRUE));
}