function RouteBuilderTest::testRebuildWithStaticModuleRoutes

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php \Drupal\Tests\Core\Routing\RouteBuilderTest::testRebuildWithStaticModuleRoutes()
  2. 8.9.x core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php \Drupal\Tests\Core\Routing\RouteBuilderTest::testRebuildWithStaticModuleRoutes()
  3. 11.x core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php \Drupal\Tests\Core\Routing\RouteBuilderTest::testRebuildWithStaticModuleRoutes()

Tests that provided routes by a module is put into the dumper/dispatcher.

See also

\Drupal\Core\Routing\RouteBuilder::rebuild()

File

core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php, line 146

Class

RouteBuilderTest
@coversDefaultClass \Drupal\Core\Routing\RouteBuilder @group Routing

Namespace

Drupal\Tests\Core\Routing

Code

public function testRebuildWithStaticModuleRoutes() : void {
    $this->lock
        ->expects($this->once())
        ->method('acquire')
        ->with('router_rebuild')
        ->willReturn(TRUE);
    $routing_fixtures = new RoutingFixtures();
    $routes = $routing_fixtures->staticSampleRouteCollection();
    $this->yamlDiscovery
        ->expects($this->once())
        ->method('findAll')
        ->willReturn([
        'test_module' => $routes,
    ]);
    $route_collection = $routing_fixtures->sampleRouteCollection();
    foreach ($route_collection->all() as $route) {
        $route->setOption('compiler_class', RouteCompiler::class);
    }
    $route_build_event = new RouteBuildEvent($route_collection);
    // 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);
    // Ensure that the routes are set to the dumper and dumped.
    $this->dumper
        ->expects($this->once())
        ->method('addRoutes')
        ->with($route_collection);
    $this->dumper
        ->expects($this->once())
        ->method('dump')
        ->with();
    $this->assertTrue($this->routeBuilder
        ->rebuild());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.