You are here

public function RouteBuilderTest::testRebuildWithOverriddenRouteClass in Drupal 8

Tests routes can use alternative compiler classes.

See also

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

File

core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php, line 286
Contains \Drupal\Tests\Core\Routing\RouteBuilderTest.

Class

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

Namespace

Drupal\Tests\Core\Routing

Code

public function testRebuildWithOverriddenRouteClass() {
  $this->lock
    ->expects($this
    ->once())
    ->method('acquire')
    ->with('router_rebuild')
    ->will($this
    ->returnValue(TRUE));
  $this->yamlDiscovery
    ->expects($this
    ->once())
    ->method('findAll')
    ->will($this
    ->returnValue([
    'test_module' => [
      'test_route.override' => [
        'path' => '/test_route_override',
        'options' => [
          'compiler_class' => 'Class\\Does\\Not\\Exist',
        ],
      ],
      'test_route' => [
        'path' => '/test_route',
      ],
    ],
  ]));
  $container = new ContainerBuilder();
  $container
    ->set('test_module.route_service', new TestRouteSubscriber());

  // Test that routes can have alternative compiler classes.
  $route_collection_filled = new RouteCollection();
  $route_collection_filled
    ->add('test_route.override', new Route('/test_route_override', [], [], [
    'compiler_class' => 'Class\\Does\\Not\\Exist',
  ]));
  $route_collection_filled
    ->add('test_route', new Route('/test_route', [], [], [
    'compiler_class' => RouteCompiler::class,
  ]));
  $route_build_event = new RouteBuildEvent($route_collection_filled);
  $this->dispatcher
    ->expects($this
    ->at(0))
    ->method('dispatch')
    ->with(RoutingEvents::DYNAMIC, $route_build_event);
  $this
    ->assertTrue($this->routeBuilder
    ->rebuild());
}