Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / FunctionalJavascript / ExposedFilterAJAXTest.php
1 <?php
2
3 namespace Drupal\Tests\views\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6 use Drupal\simpletest\ContentTypeCreationTrait;
7 use Drupal\simpletest\NodeCreationTrait;
8
9 /**
10  * Tests the basic AJAX functionality of Views exposed forms.
11  *
12  * @group views
13  */
14 class ExposedFilterAJAXTest extends WebDriverTestBase {
15
16   use ContentTypeCreationTrait;
17   use NodeCreationTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = ['node', 'views', 'views_test_modal'];
23
24   /**
25    * {@inheritdoc}
26    */
27   protected function setUp() {
28     parent::setUp();
29
30     // Enable AJAX on the /admin/content View.
31     \Drupal::configFactory()->getEditable('views.view.content')
32       ->set('display.default.display_options.use_ajax', TRUE)
33       ->save();
34
35     // Create a Content type and two test nodes.
36     $this->createContentType(['type' => 'page']);
37     $this->createNode(['title' => 'Page One']);
38     $this->createNode(['title' => 'Page Two']);
39
40     // Create a user privileged enough to use exposed filters and view content.
41     $user = $this->drupalCreateUser([
42       'administer site configuration',
43       'access content',
44       'access content overview',
45       'edit any page content',
46     ]);
47     $this->drupalLogin($user);
48   }
49
50   /**
51    * Tests if exposed filtering via AJAX works for the "Content" View.
52    */
53   public function testExposedFiltering() {
54     // Visit the View page.
55     $this->drupalGet('admin/content');
56
57     $session = $this->getSession();
58
59     // Ensure that the Content we're testing for is present.
60     $html = $session->getPage()->getHtml();
61     $this->assertContains('Page One', $html);
62     $this->assertContains('Page Two', $html);
63
64     // Search for "Page One".
65     $this->submitForm(['title' => 'Page One'], t('Filter'));
66     $this->assertSession()->assertWaitOnAjaxRequest();
67
68     // Verify that only the "Page One" Node is present.
69     $html = $session->getPage()->getHtml();
70     $this->assertContains('Page One', $html);
71     $this->assertNotContains('Page Two', $html);
72
73     // Search for "Page Two".
74     $this->submitForm(['title' => 'Page Two'], t('Filter'));
75     $this->assertSession()->assertWaitOnAjaxRequest();
76
77     // Verify that only the "Page Two" Node is present.
78     $html = $session->getPage()->getHtml();
79     $this->assertContains('Page Two', $html);
80     $this->assertNotContains('Page One', $html);
81
82     // Submit bulk actions form to ensure that the previous AJAX submit does not
83     // break it.
84     $this->submitForm([
85       'action' => 'node_make_sticky_action',
86       'node_bulk_form[0]' => TRUE,
87     ], t('Apply to selected items'));
88
89     // Verify that the action was performed.
90     $this->assertSession()->pageTextContains('Make content sticky was applied to 1 item.');
91
92     // Reset the form.
93     $this->submitForm([], t('Reset'));
94     $this->assertSession()->assertWaitOnAjaxRequest();
95
96     $this->assertSession()->pageTextContains('Page One');
97     $this->assertSession()->pageTextContains('Page Two');
98     $this->assertFalse($session->getPage()->hasButton('Reset'));
99   }
100
101   /**
102    * Tests if exposed filtering via AJAX works in a modal.
103    */
104   public function testExposedFiltersInModal() {
105     $this->drupalGet('views-test-modal/modal');
106
107     $assert = $this->assertSession();
108
109     $assert->elementExists('named', ['link', 'Administer content'])->click();
110     $dialog = $assert->waitForElementVisible('css', '.views-test-modal');
111
112     $session = $this->getSession();
113     // Ensure that the Content we're testing for is present.
114     $html = $session->getPage()->getHtml();
115     $this->assertContains('Page One', $html);
116     $this->assertContains('Page Two', $html);
117
118     // Search for "Page One".
119     $session->getPage()->fillField('title', 'Page One');
120     $assert->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Filter');
121     $this->assertSession()->assertWaitOnAjaxRequest();
122
123     // Verify that only the "Page One" Node is present.
124     $html = $session->getPage()->getHtml();
125     $this->assertContains('Page One', $html);
126     $this->assertNotContains('Page Two', $html);
127
128     // Close and re-open the modal.
129     $assert->buttonExists('Close', $dialog)->press();
130     $assert->elementExists('named', ['link', 'Administer content'])->click();
131     $assert->waitForElementVisible('css', '.views-test-modal');
132
133     // Ensure that the Content we're testing for is present.
134     $html = $session->getPage()->getHtml();
135     $this->assertContains('Page One', $html);
136     $this->assertContains('Page Two', $html);
137
138     // Search for "Page One".
139     $session->getPage()->fillField('title', 'Page One');
140     $assert->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Filter');
141     $this->assertSession()->assertWaitOnAjaxRequest();
142
143     // Verify that only the "Page One" Node is present.
144     $html = $session->getPage()->getHtml();
145     $this->assertContains('Page One', $html);
146     $this->assertNotContains('Page Two', $html);
147   }
148
149 }