function RouteBuilderTest::testRebuildWithProviderBasedRoutes
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php \Drupal\Tests\Core\Routing\RouteBuilderTest::testRebuildWithProviderBasedRoutes()
- 8.9.x core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php \Drupal\Tests\Core\Routing\RouteBuilderTest::testRebuildWithProviderBasedRoutes()
- 11.x core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php \Drupal\Tests\Core\Routing\RouteBuilderTest::testRebuildWithProviderBasedRoutes()
Tests the rebuild with routes provided by a callback.
See also
\Drupal\Core\Routing\RouteBuilder::rebuild()
File
-
core/
tests/ Drupal/ Tests/ Core/ Routing/ RouteBuilderTest.php, line 192
Class
- RouteBuilderTest
- @coversDefaultClass \Drupal\Core\Routing\RouteBuilder @group Routing
Namespace
Drupal\Tests\Core\RoutingCode
public function testRebuildWithProviderBasedRoutes() : void {
$this->lock
->expects($this->once())
->method('acquire')
->with('router_rebuild')
->willReturn(TRUE);
$this->yamlDiscovery
->expects($this->once())
->method('findAll')
->willReturn([
'test_module' => [
'route_callbacks' => [
'\\Drupal\\Tests\\Core\\Routing\\TestRouteSubscriber::routesFromArray',
'test_module.route_service:routesFromCollection',
],
],
]);
$container = new ContainerBuilder();
$container->set('test_module.route_service', new TestRouteSubscriber());
$this->controllerResolver
->expects($this->any())
->method('getControllerFromDefinition')
->willReturnCallback(function ($controller) use ($container) {
$count = substr_count($controller, ':');
if ($count == 1) {
[
$service,
$method,
] = explode(':', $controller, 2);
$object = $container->get($service);
}
else {
[
$class,
$method,
] = explode('::', $controller, 2);
$object = new $class();
}
return [
$object,
$method,
];
});
$route_collection_filled = new RouteCollection();
$route_collection_filled->add('test_route.1', new Route('/test-route/1'));
$route_collection_filled->add('test_route.2', new Route('/test-route/2'));
$route_build_event = new RouteBuildEvent($route_collection_filled);
// Ensure that the alter routes events are fired.
$this->dispatcher
->dispatch($route_build_event, RoutingEvents::DYNAMIC)
->shouldBeCalled();
$this->dispatcher
->dispatch($route_build_event, RoutingEvents::ALTER)
->shouldBeCalled();
// Ensure that access checks are set.
$this->checkProvider
->expects($this->once())
->method('setChecks')
->with($route_collection_filled);
// Ensure that the routes are set to the dumper and dumped.
$this->dumper
->expects($this->once())
->method('addRoutes')
->with($route_collection_filled);
$this->dumper
->expects($this->once())
->method('dump');
$this->assertTrue($this->routeBuilder
->rebuild());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.