Chris@0: createContentType(['type' => 'page']); Chris@0: for ($i = 1; $i <= 11; $i++) { Chris@0: $this->createNode(['title' => 'Node ' . $i . ' content', 'changed' => $i * 1000]); Chris@0: } Chris@0: Chris@0: // Create a user privileged enough to view content. Chris@0: $user = $this->drupalCreateUser([ Chris@0: 'administer site configuration', Chris@0: 'access content', Chris@0: 'access content overview', Chris@0: ]); Chris@0: $this->drupalLogin($user); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests if pagination via AJAX works for the "Content" View. Chris@0: */ Chris@0: public function testBasicPagination() { Chris@0: // Visit the content page. Chris@0: $this->drupalGet('test-content-ajax'); Chris@0: Chris@0: $session_assert = $this->assertSession(); Chris@0: Chris@0: $page = $this->getSession()->getPage(); Chris@0: Chris@0: // Set the number of items displayed per page to 5 using the exposed pager. Chris@0: $page->selectFieldOption('edit-items-per-page', 5); Chris@0: $page->pressButton('Filter'); Chris@0: $session_assert->assertWaitOnAjaxRequest(); Chris@0: Chris@0: // Change 'Updated' sorting from descending to ascending. Chris@0: $page->clickLink('Updated'); Chris@0: $session_assert->assertWaitOnAjaxRequest(); Chris@0: Chris@0: // Use the pager by clicking on the links and test if we see the expected Chris@0: // number of rows on each page. For easy targeting the titles of the pager Chris@0: // links are used. Chris@0: /** @var \Behat\Mink\Element\NodeElement[] $rows */ Chris@0: $rows = $page->findAll('css', 'tbody tr'); Chris@0: $this->assertCount(5, $rows); Chris@0: $this->assertContains('Node 1 content', $rows[0]->getHtml()); Chris@0: Chris@0: $this->clickLink('Go to page 2'); Chris@0: $session_assert->assertWaitOnAjaxRequest(); Chris@0: $rows = $page->findAll('css', 'tbody tr'); Chris@0: $this->assertCount(5, $rows); Chris@0: $this->assertContains('Node 6 content', $rows[0]->getHtml()); Chris@16: $link = $page->findLink('Go to page 3'); Chris@16: // Test that no unwanted parameters are added to the URL. Chris@16: $this->assertEquals('?status=All&type=All&langcode=All&items_per_page=5&order=changed&sort=asc&title=&page=2', $link->getAttribute('href')); Chris@16: $this->assertNoDuplicateAssetsOnPage(); Chris@0: Chris@0: $this->clickLink('Go to page 3'); Chris@0: $session_assert->assertWaitOnAjaxRequest(); Chris@0: $rows = $page->findAll('css', 'tbody tr'); Chris@0: $this->assertCount(1, $rows); Chris@0: $this->assertContains('Node 11 content', $rows[0]->getHtml()); Chris@0: Chris@0: // Navigate back to the first page. Chris@0: $this->clickLink('Go to first page'); Chris@0: $session_assert->assertWaitOnAjaxRequest(); Chris@0: $rows = $page->findAll('css', 'tbody tr'); Chris@0: $this->assertCount(5, $rows); Chris@0: $this->assertContains('Node 1 content', $rows[0]->getHtml()); Chris@0: Chris@0: // Navigate using the 'next' link. Chris@0: $this->clickLink('Go to next page'); Chris@0: $session_assert->assertWaitOnAjaxRequest(); Chris@0: $rows = $page->findAll('css', 'tbody tr'); Chris@0: $this->assertCount(5, $rows); Chris@0: $this->assertContains('Node 6 content', $rows[0]->getHtml()); Chris@0: Chris@0: // Navigate using the 'last' link. Chris@0: $this->clickLink('Go to last page'); Chris@0: $session_assert->assertWaitOnAjaxRequest(); Chris@0: $rows = $page->findAll('css', 'tbody tr'); Chris@0: $this->assertCount(1, $rows); Chris@0: $this->assertContains('Node 11 content', $rows[0]->getHtml()); Chris@0: } Chris@0: Chris@16: /** Chris@16: * Assert that assets are not loaded twice on a page. Chris@16: */ Chris@16: protected function assertNoDuplicateAssetsOnPage() { Chris@16: /** @var \Behat\Mink\Element\NodeElement[] $scripts */ Chris@16: $scripts = $this->getSession()->getPage()->findAll('xpath', '//script'); Chris@16: $script_src = []; Chris@16: foreach ($scripts as $script) { Chris@16: $this->assertFalse(in_array($script->getAttribute('src'), $script_src)); Chris@16: $script_src[] = $script->getAttribute('src'); Chris@16: } Chris@16: } Chris@16: Chris@0: }