function ViewAjaxControllerTest::testAjaxViewWithPager

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

Tests a valid view with a pager.

File

core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php, line 333

Class

ViewAjaxControllerTest
@coversDefaultClass \Drupal\views\Controller\ViewAjaxController @group views

Namespace

Drupal\Tests\views\Unit\Controller

Code

public function testAjaxViewWithPager() : void {
    $request = new Request();
    $request->request
        ->set('view_name', 'test_view');
    $request->request
        ->set('view_display_id', 'page_1');
    $dom_id = $this->randomMachineName(20);
    $request->request
        ->set('view_dom_id', $dom_id);
    $request->request
        ->set('pager_element', '0');
    [
        $view,
        $executable,
    ] = $this->setupValidMocks();
    $display_handler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')
        ->disableOriginalConstructor()
        ->getMock();
    $display_handler->expects($this->once())
        ->method('setOption')
        ->with($this->equalTo('pager_element'));
    $display_collection = $this->getMockBuilder('Drupal\\views\\DisplayPluginCollection')
        ->disableOriginalConstructor()
        ->getMock();
    $display_collection->expects($this->any())
        ->method('get')
        ->with('page_1')
        ->willReturn($display_handler);
    $executable->displayHandlers = $display_collection;
    $response = $this->viewAjaxController
        ->ajaxView($request);
    $this->assertInstanceOf(ViewAjaxResponse::class, $response);
    $commands = $this->getCommands($response);
    $this->assertEquals('scrollTop', $commands[0]['command']);
    $this->assertEquals('.js-view-dom-id-' . $dom_id, $commands[0]['selector']);
    $this->assertViewResultCommand($response, 1);
}

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