protected function UrlGeneratorTest::setUp in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php \Drupal\Tests\Core\Routing\UrlGeneratorTest::setUp()
Overrides UnitTestCase::setUp
1 call to UrlGeneratorTest::setUp()
- MetadataBubblingUrlGeneratorTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ MetadataBubblingUrlGeneratorTest.php
1 method overrides UrlGeneratorTest::setUp()
- MetadataBubblingUrlGeneratorTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Render/ MetadataBubblingUrlGeneratorTest.php
File
- core/
tests/ Drupal/ Tests/ Core/ Routing/ UrlGeneratorTest.php, line 62 - Contains \Drupal\Tests\Core\Routing\UrlGeneratorTest.
Class
- UrlGeneratorTest
- Confirm that the UrlGenerator is functioning properly.
Namespace
Drupal\Tests\Core\RoutingCode
protected function setUp() {
$cache_contexts_manager = $this
->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')
->disableOriginalConstructor()
->getMock();
$cache_contexts_manager
->method('assertValidTokens')
->willReturn(TRUE);
$container = new ContainerBuilder();
$container
->set('cache_contexts_manager', $cache_contexts_manager);
\Drupal::setContainer($container);
$routes = new RouteCollection();
$first_route = new Route('/test/one');
$second_route = new Route('/test/two/{narf}');
$third_route = new Route('/test/two/');
$fourth_route = new Route('/test/four', [], [], [], '', [
'https',
]);
$none_route = new Route('', [], [], [
'_no_path' => TRUE,
]);
$routes
->add('test_1', $first_route);
$routes
->add('test_2', $second_route);
$routes
->add('test_3', $third_route);
$routes
->add('test_4', $fourth_route);
$routes
->add('<none>', $none_route);
// Create a route provider stub.
$provider = $this
->getMockBuilder('Drupal\\Core\\Routing\\RouteProvider')
->disableOriginalConstructor()
->getMock();
// We need to set up return value maps for both the getRouteByName() and the
// getRoutesByNames() method calls on the route provider. The parameters
// are not passed in and default to an empty array.
$route_name_return_map = $routes_names_return_map = array();
$return_map_values = array(
[
'route_name' => 'test_1',
'return' => $first_route,
],
[
'route_name' => 'test_2',
'return' => $second_route,
],
[
'route_name' => 'test_3',
'return' => $third_route,
],
[
'route_name' => 'test_4',
'return' => $fourth_route,
],
[
'route_name' => '<none>',
'return' => $none_route,
],
);
foreach ($return_map_values as $values) {
$route_name_return_map[] = array(
$values['route_name'],
$values['return'],
);
$routes_names_return_map[] = array(
array(
$values['route_name'],
),
$values['return'],
);
}
$provider
->expects($this
->any())
->method('getRouteByName')
->will($this
->returnValueMap($route_name_return_map));
$provider
->expects($this
->any())
->method('getRoutesByNames')
->will($this
->returnValueMap($routes_names_return_map));
// Create an alias manager stub.
$alias_manager = $this
->getMockBuilder('Drupal\\Core\\Path\\AliasManager')
->disableOriginalConstructor()
->getMock();
$alias_manager
->expects($this
->any())
->method('getAliasByPath')
->will($this
->returnCallback(array(
$this,
'aliasManagerCallback',
)));
$this->aliasManager = $alias_manager;
$this->requestStack = new RequestStack();
$request = Request::create('/some/path');
$this->requestStack
->push($request);
$context = new RequestContext();
$context
->fromRequestStack($this->requestStack);
$processor = new PathProcessorAlias($this->aliasManager);
$processor_manager = new PathProcessorManager();
$processor_manager
->addOutbound($processor, 1000);
$this->routeProcessorManager = $this
->getMockBuilder('Drupal\\Core\\RouteProcessor\\RouteProcessorManager')
->disableOriginalConstructor()
->getMock();
$generator = new UrlGenerator($provider, $processor_manager, $this->routeProcessorManager, $this->requestStack, [
'http',
'https',
]);
$generator
->setContext($context);
$this->generator = $generator;
}