3 namespace Drupal\Tests\views\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
6 use Drupal\simpletest\ContentTypeCreationTrait;
7 use Drupal\simpletest\NodeCreationTrait;
10 * Tests the basic AJAX functionality of Views exposed forms.
14 class ExposedFilterAJAXTest extends JavascriptTestBase {
16 use ContentTypeCreationTrait;
17 use NodeCreationTrait;
22 public static $modules = ['node', 'views'];
25 * Tests if exposed filtering via AJAX works for the "Content" View.
27 public function testExposedFiltering() {
28 // Enable AJAX on the /admin/content View.
29 \Drupal::configFactory()->getEditable('views.view.content')
30 ->set('display.default.display_options.use_ajax', TRUE)
33 // Create a Content type and two test nodes.
34 $this->createContentType(['type' => 'page']);
35 $this->createNode(['title' => 'Page One']);
36 $this->createNode(['title' => 'Page Two']);
38 // Create a user privileged enough to use exposed filters and view content.
39 $user = $this->drupalCreateUser([
40 'administer site configuration',
42 'access content overview',
44 $this->drupalLogin($user);
46 // Visit the View page.
47 $this->drupalGet('admin/content');
49 $session = $this->getSession();
51 // Ensure that the Content we're testing for is present.
52 $html = $session->getPage()->getHtml();
53 $this->assertContains('Page One', $html);
54 $this->assertContains('Page Two', $html);
56 // Search for "Page One".
57 $this->submitForm(['title' => 'Page One'], t('Filter'));
58 $this->assertSession()->assertWaitOnAjaxRequest();
60 // Verify that only the "Page One" Node is present.
61 $html = $session->getPage()->getHtml();
62 $this->assertContains('Page One', $html);
63 $this->assertNotContains('Page Two', $html);
65 // Search for "Page Two".
66 $this->submitForm(['title' => 'Page Two'], t('Filter'));
67 $this->assertSession()->assertWaitOnAjaxRequest();
69 // Verify that only the "Page Two" Node is present.
70 $html = $session->getPage()->getHtml();
71 $this->assertContains('Page Two', $html);
72 $this->assertNotContains('Page One', $html);
75 $this->submitForm([], t('Reset'));
76 $this->assertSession()->assertWaitOnAjaxRequest();
78 $this->assertSession()->pageTextContains('Page One');
79 $this->assertSession()->pageTextContains('Page Two');
80 $this->assertFalse($session->getPage()->hasButton('Reset'));