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. 10 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 142

Class

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

Namespace

Drupal\Tests\Core\Routing

Code

public function testRebuildWithStaticModuleRoutes() {
    $this->lock
        ->expects($this->once())
        ->method('acquire')
        ->with('router_rebuild')
        ->will($this->returnValue(TRUE));
    $routing_fixtures = new RoutingFixtures();
    $routes = $routing_fixtures->staticSampleRouteCollection();
    $this->yamlDiscovery
        ->expects($this->once())
        ->method('findAll')
        ->will($this->returnValue([
        '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
        ->expects($this->at(0))
        ->method('dispatch')
        ->with(RoutingEvents::DYNAMIC, $route_build_event);
    $this->dispatcher
        ->expects($this->at(1))
        ->method('dispatch')
        ->with(RoutingEvents::ALTER, $route_build_event);
    // 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->at(0))
        ->method('addRoutes')
        ->with($route_collection);
    $this->dumper
        ->expects($this->at(1))
        ->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.