974aa2da424f7701bf1c6db25b377d7c46484b14
[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\JavascriptTestBase;
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 JavascriptTestBase {
15
16   use ContentTypeCreationTrait;
17   use NodeCreationTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = ['node', 'views'];
23
24   /**
25    * Tests if exposed filtering via AJAX works for the "Content" View.
26    */
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)
31       ->save();
32
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']);
37
38     // Create a user privileged enough to use exposed filters and view content.
39     $user = $this->drupalCreateUser([
40       'administer site configuration',
41       'access content',
42       'access content overview',
43     ]);
44     $this->drupalLogin($user);
45
46     // Visit the View page.
47     $this->drupalGet('admin/content');
48
49     $session = $this->getSession();
50
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);
55
56     // Search for "Page One".
57     $this->submitForm(['title' => 'Page One'], t('Filter'));
58     $this->assertSession()->assertWaitOnAjaxRequest();
59
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);
64
65     // Search for "Page Two".
66     $this->submitForm(['title' => 'Page Two'], t('Filter'));
67     $this->assertSession()->assertWaitOnAjaxRequest();
68
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);
73
74     // Reset the form.
75     $this->submitForm([], t('Reset'));
76     $this->assertSession()->assertWaitOnAjaxRequest();
77
78     $this->assertSession()->pageTextContains('Page One');
79     $this->assertSession()->pageTextContains('Page Two');
80     $this->assertFalse($session->getPage()->hasButton('Reset'));
81   }
82
83 }