You are here

public function ViewPageControllerTest::testHandleWithArgumentsWithoutOverridden in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php \Drupal\Tests\views\Unit\Routing\ViewPageControllerTest::testHandleWithArgumentsWithoutOverridden()

Tests the page controller with arguments on a non overridden page view.

File

core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php, line 79
Contains \Drupal\Tests\views\Unit\Routing\ViewPageControllerTest.

Class

ViewPageControllerTest
@coversDefaultClass \Drupal\views\Routing\ViewPageController @group views

Namespace

Drupal\Tests\views\Unit\Routing

Code

public function testHandleWithArgumentsWithoutOverridden() {
  $request = new Request();
  $request->attributes
    ->set('view_id', 'test_page_view');
  $request->attributes
    ->set('display_id', 'page_1');

  // Add the argument to the request.
  $request->attributes
    ->set('arg_0', 'test-argument');
  $options = [
    '_view_argument_map' => [
      'arg_0' => 'arg_0',
    ],
    '_view_display_plugin_class' => '\\Drupal\\views\\Plugin\\views\\display\\Page',
  ];
  $request->attributes
    ->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test/{arg_0}', [
    'view_id' => 'test_page_view',
    'display_id' => 'default',
  ], [], $options));
  $route_match = RouteMatch::createFromRequest($request);
  $result = $this->pageController
    ->handle($route_match
    ->getParameter('view_id'), $route_match
    ->getParameter('display_id'), $route_match);
  $build = [
    '#type' => 'view',
    '#name' => 'test_page_view',
    '#display_id' => 'page_1',
    '#embed' => FALSE,
    '#arguments' => [
      'test-argument',
    ],
    '#cache' => [
      'keys' => [
        'view',
        'test_page_view',
        'display',
        'page_1',
        'args',
        'test-argument',
      ],
    ],
  ] + $this->defaultRenderArray;
  $this
    ->assertEquals($build, $result);
}