function UrlGeneratorTest::setUp
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php \Drupal\Tests\Core\Routing\UrlGeneratorTest::setUp()
- 10 core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php \Drupal\Tests\Core\Routing\UrlGeneratorTest::setUp()
- 11.x 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 81
Class
- UrlGeneratorTest
- Confirm that the UrlGenerator is functioning properly.
Namespace
Drupal\Tests\Core\RoutingCode
protected function setUp() : void {
$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 = [];
$return_map_values = [
[
'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[] = [
$values['route_name'],
$values['return'],
];
$routes_names_return_map[] = [
[
$values['route_name'],
],
$values['return'],
];
}
$this->provider = $provider;
$this->provider
->expects($this->any())
->method('getRouteByName')
->willReturnMap($route_name_return_map);
$provider->expects($this->any())
->method('getRoutesByNames')
->willReturnMap($routes_names_return_map);
// Create an alias manager stub.
$alias_manager = $this->getMockBuilder('Drupal\\path_alias\\AliasManager')
->disableOriginalConstructor()
->getMock();
$alias_manager->expects($this->any())
->method('getAliasByPath')
->willReturnCallback([
$this,
'aliasManagerCallback',
]);
$this->aliasManager = $alias_manager;
$this->requestStack = new RequestStack();
$request = Request::create('/some/path');
$this->requestStack
->push($request);
$this->context = new RequestContext();
$this->context
->fromRequestStack($this->requestStack);
$processor = new AliasPathProcessor($this->aliasManager);
$processor_manager = new PathProcessorManager();
$processor_manager->addOutbound($processor, 1000);
$this->processorManager = $processor_manager;
$this->routeProcessorManager = $this->getMockBuilder('Drupal\\Core\\RouteProcessor\\RouteProcessorManager')
->disableOriginalConstructor()
->getMock();
$generator = new UrlGenerator($this->provider, $processor_manager, $this->routeProcessorManager, $this->requestStack, [
'http',
'https',
]);
$generator->setContext($this->context);
$this->generator = $generator;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.