You are here

public function DisplayPageTest::testPageRouterItems in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php \Drupal\Tests\views\Kernel\Plugin\DisplayPageTest::testPageRouterItems()
  2. 9 core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php \Drupal\Tests\views\Kernel\Plugin\DisplayPageTest::testPageRouterItems()

Checks that the router items are properly registered.

File

core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php, line 85

Class

DisplayPageTest
Tests the page display plugin.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testPageRouterItems() {
  $collection = \Drupal::service('views.route_subscriber')
    ->routes();

  // Check the controller defaults.
  foreach ($collection as $id => $route) {
    $this
      ->assertEquals('Drupal\\views\\Routing\\ViewPageController::handle', $route
      ->getDefault('_controller'));
    $id_parts = explode('.', $id);
    $this
      ->assertEquals($id_parts[1], $route
      ->getDefault('view_id'));
    $this
      ->assertEquals($id_parts[2], $route
      ->getDefault('display_id'));
  }

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