annotate core/modules/views/tests/src/FunctionalJavascript/PaginationAJAXTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children c2387f117808
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\views\FunctionalJavascript;
Chris@0 4
Chris@0 5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
Chris@0 6 use Drupal\simpletest\ContentTypeCreationTrait;
Chris@0 7 use Drupal\simpletest\NodeCreationTrait;
Chris@0 8 use Drupal\views\Tests\ViewTestData;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Tests the click sorting AJAX functionality of Views exposed forms.
Chris@0 12 *
Chris@0 13 * @group views
Chris@0 14 */
Chris@0 15 class PaginationAJAXTest extends JavascriptTestBase {
Chris@0 16
Chris@0 17 use ContentTypeCreationTrait;
Chris@0 18 use NodeCreationTrait;
Chris@0 19
Chris@0 20 /**
Chris@0 21 * {@inheritdoc}
Chris@0 22 */
Chris@0 23 public static $modules = ['node', 'views', 'views_test_config'];
Chris@0 24
Chris@0 25 /**
Chris@0 26 * @var array
Chris@0 27 * Test Views to enable.
Chris@0 28 */
Chris@0 29 public static $testViews = ['test_content_ajax'];
Chris@0 30
Chris@0 31 protected $user;
Chris@0 32
Chris@0 33 /**
Chris@0 34 * {@inheritdoc}
Chris@0 35 */
Chris@0 36 protected function setUp() {
Chris@0 37 parent::setUp();
Chris@0 38
Chris@0 39 ViewTestData::createTestViews(self::class, ['views_test_config']);
Chris@0 40
Chris@0 41 // Create a Content type and eleven test nodes.
Chris@0 42 $this->createContentType(['type' => 'page']);
Chris@0 43 for ($i = 1; $i <= 11; $i++) {
Chris@0 44 $this->createNode(['title' => 'Node ' . $i . ' content', 'changed' => $i * 1000]);
Chris@0 45 }
Chris@0 46
Chris@0 47 // Create a user privileged enough to view content.
Chris@0 48 $user = $this->drupalCreateUser([
Chris@0 49 'administer site configuration',
Chris@0 50 'access content',
Chris@0 51 'access content overview',
Chris@0 52 ]);
Chris@0 53 $this->drupalLogin($user);
Chris@0 54 }
Chris@0 55
Chris@0 56 /**
Chris@0 57 * Tests if pagination via AJAX works for the "Content" View.
Chris@0 58 */
Chris@0 59 public function testBasicPagination() {
Chris@0 60 // Visit the content page.
Chris@0 61 $this->drupalGet('test-content-ajax');
Chris@0 62
Chris@0 63 $session_assert = $this->assertSession();
Chris@0 64
Chris@0 65 $page = $this->getSession()->getPage();
Chris@0 66
Chris@0 67 // Set the number of items displayed per page to 5 using the exposed pager.
Chris@0 68 $page->selectFieldOption('edit-items-per-page', 5);
Chris@0 69 $page->pressButton('Filter');
Chris@0 70 $session_assert->assertWaitOnAjaxRequest();
Chris@0 71
Chris@0 72 // Change 'Updated' sorting from descending to ascending.
Chris@0 73 $page->clickLink('Updated');
Chris@0 74 $session_assert->assertWaitOnAjaxRequest();
Chris@0 75
Chris@0 76 // Use the pager by clicking on the links and test if we see the expected
Chris@0 77 // number of rows on each page. For easy targeting the titles of the pager
Chris@0 78 // links are used.
Chris@0 79 /** @var \Behat\Mink\Element\NodeElement[] $rows */
Chris@0 80 $rows = $page->findAll('css', 'tbody tr');
Chris@0 81 $this->assertCount(5, $rows);
Chris@0 82 $this->assertContains('Node 1 content', $rows[0]->getHtml());
Chris@0 83
Chris@0 84 $this->clickLink('Go to page 2');
Chris@0 85 $session_assert->assertWaitOnAjaxRequest();
Chris@0 86 $rows = $page->findAll('css', 'tbody tr');
Chris@0 87 $this->assertCount(5, $rows);
Chris@0 88 $this->assertContains('Node 6 content', $rows[0]->getHtml());
Chris@0 89
Chris@0 90 $this->clickLink('Go to page 3');
Chris@0 91 $session_assert->assertWaitOnAjaxRequest();
Chris@0 92 $rows = $page->findAll('css', 'tbody tr');
Chris@0 93 $this->assertCount(1, $rows);
Chris@0 94 $this->assertContains('Node 11 content', $rows[0]->getHtml());
Chris@0 95
Chris@0 96 // Navigate back to the first page.
Chris@0 97 $this->clickLink('Go to first page');
Chris@0 98 $session_assert->assertWaitOnAjaxRequest();
Chris@0 99 $rows = $page->findAll('css', 'tbody tr');
Chris@0 100 $this->assertCount(5, $rows);
Chris@0 101 $this->assertContains('Node 1 content', $rows[0]->getHtml());
Chris@0 102
Chris@0 103 // Navigate using the 'next' link.
Chris@0 104 $this->clickLink('Go to next page');
Chris@0 105 $session_assert->assertWaitOnAjaxRequest();
Chris@0 106 $rows = $page->findAll('css', 'tbody tr');
Chris@0 107 $this->assertCount(5, $rows);
Chris@0 108 $this->assertContains('Node 6 content', $rows[0]->getHtml());
Chris@0 109
Chris@0 110 // Navigate using the 'last' link.
Chris@0 111 $this->clickLink('Go to last page');
Chris@0 112 $session_assert->assertWaitOnAjaxRequest();
Chris@0 113 $rows = $page->findAll('css', 'tbody tr');
Chris@0 114 $this->assertCount(1, $rows);
Chris@0 115 $this->assertContains('Node 11 content', $rows[0]->getHtml());
Chris@0 116 }
Chris@0 117
Chris@0 118 }