function PaginationAJAXTest::testBasicPagination
Same name in other branches
- 9 core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\PaginationAJAXTest::testBasicPagination()
- 8.9.x core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\PaginationAJAXTest::testBasicPagination()
- 10 core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\PaginationAJAXTest::testBasicPagination()
Tests if pagination via AJAX works for the "Content" View.
File
-
core/
modules/ views/ tests/ src/ FunctionalJavascript/ PaginationAJAXTest.php, line 70
Class
- PaginationAJAXTest
- Tests the click sorting AJAX functionality of Views exposed forms.
Namespace
Drupal\Tests\views\FunctionalJavascriptCode
public function testBasicPagination() : void {
// Visit the content page.
$this->drupalGet('test-content-ajax');
$session_assert = $this->assertSession();
$page = $this->getSession()
->getPage();
$settings = $this->getDrupalSettings();
// Make sure that the view_path is set correctly.
$expected_view_path = '/test-content-ajax';
$this->assertEquals($expected_view_path, current($settings['views']['ajaxViews'])['view_path']);
// Set the number of items displayed per page to 5 using the exposed pager.
$page->selectFieldOption('edit-items-per-page', '5');
$page->pressButton('Filter');
$session_assert->assertWaitOnAjaxRequest();
// Change 'Updated' sorting from descending to ascending.
$page->clickLink('Updated');
$session_assert->assertWaitOnAjaxRequest();
// Use the pager by clicking on the links and test if we see the expected
// number of rows on each page. For easy targeting the titles of the pager
// links are used.
/** @var \Behat\Mink\Element\NodeElement[] $rows */
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
$this->clickLink('Go to page 2');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
$link = $page->findLink('Go to page 3');
$this->assertNoDuplicateAssetsOnPage();
// Test that no unwanted parameters are added to the URL.
$this->assertEquals('?status=All&type=All&title=&items_per_page=5&order=changed&sort=asc&page=2', $link->getAttribute('href'));
$this->clickLink('Go to page 3');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(1, $rows);
$this->assertStringContainsString('Node 11 content', $rows[0]->getHtml());
// Navigate back to the first page.
$this->clickLink('Go to first page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());
// Navigate using the 'next' link.
$this->clickLink('Go to next page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
// Navigate using the 'last' link.
$this->clickLink('Go to last page');
$session_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(1, $rows);
$this->assertStringContainsString('Node 11 content', $rows[0]->getHtml());
// Make sure the AJAX calls don't change the view_path.
$settings = $this->getDrupalSettings();
$this->assertEquals($expected_view_path, current($settings['views']['ajaxViews'])['view_path']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.