public function DisplayPageTest::testPageRouterItems

Checks that the router items are properly registered

File

drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php, line 97
Contains \Drupal\views\Tests\Plugin\DisplayPageTest.

Class

DisplayPageTest
Tests the page display plugin.

Namespace

Drupal\views\Tests\Plugin

Code

public function testPageRouterItems() {
  $subscriber = new RouteSubscriber();
  $collection = new RouteCollection();
  $subscriber
    ->dynamicRoutes(new RouteBuildEvent($collection, 'dynamic_routes'));

  // Check the controller defaults.
  foreach ($collection as $id => $route) {
    if (strpos($id, 'test_page_display_route') === 0) {
      $this
        ->assertEqual($route
        ->getDefault('_controller'), 'Drupal\\views\\Routing\\ViewPageController::handle');
      $this
        ->assertEqual($route
        ->getDefault('view_id'), 'test_page_display_route');
      $this
        ->assertEqual($route
        ->getDefault('display_id'), str_replace('test_page_display_route.', '', $id));
    }
  }

  // Check the generated patterns and default values.
  $route = $collection
    ->get('view.test_page_display_route.page_1');
  $this
    ->assertEqual($route
    ->getPath(), '/test_route_without_arguments');
  $route = $collection
    ->get('view.test_page_display_route.page_2');
  $this
    ->assertEqual($route
    ->getPath(), '/test_route_with_argument/{arg_id}');
  $this
    ->assertTrue($route
    ->hasDefault('arg_id'), 'A default value is set for the optional argument id.');
  $route = $collection
    ->get('view.test_page_display_route.page_3');
  $this
    ->assertEqual($route
    ->getPath(), '/test_route_with_argument/{arg_id}/suffix');
  $this
    ->assertFalse($route
    ->hasDefault('arg_id'), 'No default value is set for the required argument id.');
  $route = $collection
    ->get('view.test_page_display_route.page_4');
  $this
    ->assertEqual($route
    ->getPath(), '/test_route_with_argument/{arg_id}/suffix/{arg_id_2}');
  $this
    ->assertFalse($route
    ->hasDefault('arg_id'), 'No default value is set for the required argument id.');
  $this
    ->assertTrue($route
    ->hasDefault('arg_id_2'), 'A default value is set for the optional argument id_2.');
  $route = $collection
    ->get('view.test_page_display_route.page_5');
  $this
    ->assertEqual($route
    ->getPath(), '/test_route_with_argument/{arg_id}/{arg_id_2}');
  $this
    ->assertTrue($route
    ->hasDefault('arg_id'), 'A default value is set for the optional argument id.');
  $this
    ->assertTrue($route
    ->hasDefault('arg_id_2'), 'A default value is set for the optional argument id_2.');
  $route = $collection
    ->get('view.test_page_display_route.page_6');
  $this
    ->assertEqual($route
    ->getPath(), '/test_route_with_argument/{arg_id}/{arg_id_2}');
  $this
    ->assertFalse($route
    ->hasDefault('arg_id'), 'No default value is set for the required argument id.');
  $this
    ->assertFalse($route
    ->hasDefault('arg_id_2'), 'No default value is set for the required argument id_2.');
}