You are here

public function RoutePreloaderTest::testOnAlterRoutesWithNonAdminRoutes in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php \Drupal\Tests\Core\Routing\RoutePreloaderTest::testOnAlterRoutesWithNonAdminRoutes()

Tests onAlterRoutes with admin routes and non admin routes.

File

core/tests/Drupal/Tests/Core/Routing/RoutePreloaderTest.php, line 109
Contains \Drupal\Tests\Core\Routing\RoutePreloaderTest.

Class

RoutePreloaderTest
@coversDefaultClass \Drupal\Core\Routing\RoutePreloader @group Routing

Namespace

Drupal\Tests\Core\Routing

Code

public function testOnAlterRoutesWithNonAdminRoutes() {
  $event = $this
    ->getMockBuilder('Drupal\\Core\\Routing\\RouteBuildEvent')
    ->disableOriginalConstructor()
    ->getMock();
  $route_collection = new RouteCollection();
  $route_collection
    ->add('test', new Route('/admin/foo', array(
    '_controller' => 'Drupal\\ExampleController',
  )));
  $route_collection
    ->add('test2', new Route('/bar', array(
    '_controller' => 'Drupal\\ExampleController',
  )));

  // Non content routes, like ajax callbacks should be ignored.
  $route_collection
    ->add('test3', new Route('/bar', array(
    '_controller' => 'Drupal\\ExampleController',
  )));
  $event
    ->expects($this
    ->once())
    ->method('getRouteCollection')
    ->will($this
    ->returnValue($route_collection));
  $this->state
    ->expects($this
    ->once())
    ->method('set')
    ->with('routing.non_admin_routes', array(
    'test2',
    'test3',
  ));
  $this->preloader
    ->onAlterRoutes($event);
  $this->preloader
    ->onFinishedRoutes(new Event());
}