Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\views\FunctionalJavascript;
|
Chris@0
|
4
|
Chris@17
|
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
Chris@18
|
6 use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
|
Chris@18
|
7 use Drupal\Tests\node\Traits\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@17
|
15 class PaginationAJAXTest extends WebDriverTestBase {
|
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@16
|
89 $link = $page->findLink('Go to page 3');
|
Chris@16
|
90 // Test that no unwanted parameters are added to the URL.
|
Chris@16
|
91 $this->assertEquals('?status=All&type=All&langcode=All&items_per_page=5&order=changed&sort=asc&title=&page=2', $link->getAttribute('href'));
|
Chris@16
|
92 $this->assertNoDuplicateAssetsOnPage();
|
Chris@0
|
93
|
Chris@0
|
94 $this->clickLink('Go to page 3');
|
Chris@0
|
95 $session_assert->assertWaitOnAjaxRequest();
|
Chris@0
|
96 $rows = $page->findAll('css', 'tbody tr');
|
Chris@0
|
97 $this->assertCount(1, $rows);
|
Chris@0
|
98 $this->assertContains('Node 11 content', $rows[0]->getHtml());
|
Chris@0
|
99
|
Chris@0
|
100 // Navigate back to the first page.
|
Chris@0
|
101 $this->clickLink('Go to first page');
|
Chris@0
|
102 $session_assert->assertWaitOnAjaxRequest();
|
Chris@0
|
103 $rows = $page->findAll('css', 'tbody tr');
|
Chris@0
|
104 $this->assertCount(5, $rows);
|
Chris@0
|
105 $this->assertContains('Node 1 content', $rows[0]->getHtml());
|
Chris@0
|
106
|
Chris@0
|
107 // Navigate using the 'next' link.
|
Chris@0
|
108 $this->clickLink('Go to next page');
|
Chris@0
|
109 $session_assert->assertWaitOnAjaxRequest();
|
Chris@0
|
110 $rows = $page->findAll('css', 'tbody tr');
|
Chris@0
|
111 $this->assertCount(5, $rows);
|
Chris@0
|
112 $this->assertContains('Node 6 content', $rows[0]->getHtml());
|
Chris@0
|
113
|
Chris@0
|
114 // Navigate using the 'last' link.
|
Chris@0
|
115 $this->clickLink('Go to last page');
|
Chris@0
|
116 $session_assert->assertWaitOnAjaxRequest();
|
Chris@0
|
117 $rows = $page->findAll('css', 'tbody tr');
|
Chris@0
|
118 $this->assertCount(1, $rows);
|
Chris@0
|
119 $this->assertContains('Node 11 content', $rows[0]->getHtml());
|
Chris@0
|
120 }
|
Chris@0
|
121
|
Chris@16
|
122 /**
|
Chris@16
|
123 * Assert that assets are not loaded twice on a page.
|
Chris@16
|
124 */
|
Chris@16
|
125 protected function assertNoDuplicateAssetsOnPage() {
|
Chris@16
|
126 /** @var \Behat\Mink\Element\NodeElement[] $scripts */
|
Chris@16
|
127 $scripts = $this->getSession()->getPage()->findAll('xpath', '//script');
|
Chris@16
|
128 $script_src = [];
|
Chris@16
|
129 foreach ($scripts as $script) {
|
Chris@16
|
130 $this->assertFalse(in_array($script->getAttribute('src'), $script_src));
|
Chris@16
|
131 $script_src[] = $script->getAttribute('src');
|
Chris@16
|
132 }
|
Chris@16
|
133 }
|
Chris@16
|
134
|
Chris@0
|
135 }
|