You are here

public function ViewAjaxControllerTest::testAjaxViewWithPager in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php \Drupal\Tests\views\Unit\Controller\ViewAjaxControllerTest::testAjaxViewWithPager()
  2. 9 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 316

Class

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

Namespace

Drupal\Tests\views\Unit\Controller

Code

public function testAjaxViewWithPager() {
  $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', '0')
    ->with($this
    ->equalTo('pager_element'));
  $display_collection = $this
    ->getMockBuilder('Drupal\\views\\DisplayPluginCollection')
    ->disableOriginalConstructor()
    ->getMock();
  $display_collection
    ->expects($this
    ->any())
    ->method('get')
    ->with('page_1')
    ->will($this
    ->returnValue($display_handler));
  $executable->displayHandlers = $display_collection;
  $response = $this->viewAjaxController
    ->ajaxView($request);
  $this
    ->assertInstanceOf(ViewAjaxResponse::class, $response);
  $commands = $this
    ->getCommands($response);
  $this
    ->assertEquals('viewsScrollTop', $commands[0]['command']);
  $this
    ->assertEquals('.js-view-dom-id-' . $dom_id, $commands[0]['selector']);
  $this
    ->assertViewResultCommand($response, 1);
}