function ViewPageControllerTest::testPageController

Same name in other branches
  1. 9 core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php \Drupal\Tests\views\Unit\Routing\ViewPageControllerTest::testPageController()
  2. 8.9.x core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php \Drupal\Tests\views\Unit\Routing\ViewPageControllerTest::testPageController()
  3. 11.x core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php \Drupal\Tests\views\Unit\Routing\ViewPageControllerTest::testPageController()

Tests the page controller.

File

core/modules/views/tests/src/Unit/Routing/ViewPageControllerTest.php, line 52

Class

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

Namespace

Drupal\Tests\views\Unit\Routing

Code

public function testPageController() : void {
    $build = [
        '#type' => 'view',
        '#name' => 'test_page_view',
        '#display_id' => 'default',
        '#embed' => FALSE,
        '#arguments' => [],
        '#cache' => [
            'keys' => [
                'view',
                'test_page_view',
                'display',
                'default',
            ],
        ],
    ] + $this->defaultRenderArray;
    $request = new Request();
    $request->attributes
        ->set('view_id', 'test_page_view');
    $request->attributes
        ->set('display_id', 'default');
    $options = [
        '_view_display_plugin_class' => '\\Drupal\\views\\Plugin\\views\\display\\Page',
    ];
    $request->attributes
        ->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test', [
        'view_id' => 'test_page_view',
        'display_id' => 'default',
    ], [], $options));
    $route_match = RouteMatch::createFromRequest($request);
    $output = $this->pageController
        ->handle($route_match->getParameter('view_id'), $route_match->getParameter('display_id'), $route_match);
    $this->assertIsArray($output);
    $this->assertEquals($build, $output);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.