/**
  * @covers ::copyRawVariables()
  */
 public function testCopyRawVariables()
 {
     $route = new Route('/test/{id}');
     $defaults = array(RouteObjectInterface::ROUTE_OBJECT => $route, 'id' => '1');
     // Set one default to mirror another by reference.
     $defaults['bar'] =& $defaults['id'];
     $this->paramConverterManager->expects($this->any())->method('convert')->with($this->isType('array'), $this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Request'))->will($this->returnCallback(function ($defaults) {
         // Convert the mirrored default to another value.
         $defaults['bar'] = '2';
         return $defaults;
     }));
     $expected = new ParameterBag(array('id' => 1));
     $result = $this->paramConversionEnhancer->enhance($defaults, new Request());
     $this->assertEquals($result['_raw_variables'], $expected);
 }
 /**
  * Tests the checkNamedRoute with default values.
  *
  * @covers \Drupal\Core\Access\AccessManager::checkNamedRoute()
  */
 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->urlGenerator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
     $this->urlGenerator->expects($this->any())->method('generate')->with('test_route_1', array())->will($this->returnValueMap($map));
     $this->paramConverter = $this->getMock('Drupal\\Core\\ParamConverter\\ParamConverterManagerInterface');
     $this->paramConverter->expects($this->at(0))->method('convert')->with(array('value' => 'example', RouteObjectInterface::ROUTE_OBJECT => $route))->will($this->returnValue(array('value' => 'upcasted_value')));
     $this->argumentsResolver->expects($this->atLeastOnce())->method('getArguments')->will($this->returnCallback(function ($callable, $route, $request, $account) {
         return array($route);
     }));
     $subrequest = Request::create('/test-route-1/example');
     $this->accessManager = new AccessManager($this->routeProvider, $this->urlGenerator, $this->paramConverter, $this->argumentsResolver, $this->requestStack);
     $this->accessManager->setContainer($this->container);
     $this->requestStack->push(new Request());
     $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(AccessInterface::KILL));
     $subrequest->attributes->set('value', 'upcasted_value');
     $this->container->set('test_access', $access_check);
     $this->accessManager->addCheckService('test_access', 'access');
     $this->accessManager->setChecks($this->routeCollection);
     $this->assertFalse($this->accessManager->checkNamedRoute('test_route_1', array(), $this->account));
 }
 /**
  * Tests that an access checker throws an exception for not allowed values.
  *
  * @dataProvider providerCheckException
  *
  * @expectedException \Drupal\Core\Access\AccessException
  */
 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);
 }