3 namespace Drupal\Tests\views\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6 use Drupal\simpletest\ContentTypeCreationTrait;
7 use Drupal\simpletest\NodeCreationTrait;
10 * Tests the basic AJAX functionality of Views exposed forms.
14 class ExposedFilterAJAXTest extends WebDriverTestBase {
16 use ContentTypeCreationTrait;
17 use NodeCreationTrait;
22 public static $modules = ['node', 'views', 'views_test_modal'];
27 protected function setUp() {
30 // Enable AJAX on the /admin/content View.
31 \Drupal::configFactory()->getEditable('views.view.content')
32 ->set('display.default.display_options.use_ajax', TRUE)
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']);
40 // Create a user privileged enough to use exposed filters and view content.
41 $user = $this->drupalCreateUser([
42 'administer site configuration',
44 'access content overview',
45 'edit any page content',
47 $this->drupalLogin($user);
51 * Tests if exposed filtering via AJAX works for the "Content" View.
53 public function testExposedFiltering() {
54 // Visit the View page.
55 $this->drupalGet('admin/content');
57 $session = $this->getSession();
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);
64 // Search for "Page One".
65 $this->submitForm(['title' => 'Page One'], t('Filter'));
66 $this->assertSession()->assertWaitOnAjaxRequest();
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);
73 // Search for "Page Two".
74 $this->submitForm(['title' => 'Page Two'], t('Filter'));
75 $this->assertSession()->assertWaitOnAjaxRequest();
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);
82 // Submit bulk actions form to ensure that the previous AJAX submit does not
85 'action' => 'node_make_sticky_action',
86 'node_bulk_form[0]' => TRUE,
87 ], t('Apply to selected items'));
89 // Verify that the action was performed.
90 $this->assertSession()->pageTextContains('Make content sticky was applied to 1 item.');
93 $this->submitForm([], t('Reset'));
94 $this->assertSession()->assertWaitOnAjaxRequest();
96 $this->assertSession()->pageTextContains('Page One');
97 $this->assertSession()->pageTextContains('Page Two');
98 $this->assertFalse($session->getPage()->hasButton('Reset'));
102 * Tests if exposed filtering via AJAX works in a modal.
104 public function testExposedFiltersInModal() {
105 $this->drupalGet('views-test-modal/modal');
107 $assert = $this->assertSession();
109 $assert->elementExists('named', ['link', 'Administer content'])->click();
110 $dialog = $assert->waitForElementVisible('css', '.views-test-modal');
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);
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();
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);
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');
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);
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();
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);