namespace Drupal\Tests\views\FunctionalJavascript;
-use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\simpletest\NodeCreationTrait;
*
* @group views
*/
-class ExposedFilterAJAXTest extends JavascriptTestBase {
+class ExposedFilterAJAXTest extends WebDriverTestBase {
use ContentTypeCreationTrait;
use NodeCreationTrait;
/**
* {@inheritdoc}
*/
- public static $modules = ['node', 'views'];
+ public static $modules = ['node', 'views', 'views_test_modal'];
/**
- * Tests if exposed filtering via AJAX works for the "Content" View.
+ * {@inheritdoc}
*/
- public function testExposedFiltering() {
+ protected function setUp() {
+ parent::setUp();
+
// Enable AJAX on the /admin/content View.
\Drupal::configFactory()->getEditable('views.view.content')
->set('display.default.display_options.use_ajax', TRUE)
'administer site configuration',
'access content',
'access content overview',
+ 'edit any page content',
]);
$this->drupalLogin($user);
+ }
+ /**
+ * Tests if exposed filtering via AJAX works for the "Content" View.
+ */
+ public function testExposedFiltering() {
// Visit the View page.
$this->drupalGet('admin/content');
$this->assertContains('Page Two', $html);
$this->assertNotContains('Page One', $html);
+ // Submit bulk actions form to ensure that the previous AJAX submit does not
+ // break it.
+ $this->submitForm([
+ 'action' => 'node_make_sticky_action',
+ 'node_bulk_form[0]' => TRUE,
+ ], t('Apply to selected items'));
+
+ // Verify that the action was performed.
+ $this->assertSession()->pageTextContains('Make content sticky was applied to 1 item.');
+
// Reset the form.
$this->submitForm([], t('Reset'));
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertFalse($session->getPage()->hasButton('Reset'));
}
+ /**
+ * Tests if exposed filtering via AJAX works in a modal.
+ */
+ public function testExposedFiltersInModal() {
+ $this->drupalGet('views-test-modal/modal');
+
+ $assert = $this->assertSession();
+
+ $assert->elementExists('named', ['link', 'Administer content'])->click();
+ $dialog = $assert->waitForElementVisible('css', '.views-test-modal');
+
+ $session = $this->getSession();
+ // Ensure that the Content we're testing for is present.
+ $html = $session->getPage()->getHtml();
+ $this->assertContains('Page One', $html);
+ $this->assertContains('Page Two', $html);
+
+ // Search for "Page One".
+ $session->getPage()->fillField('title', 'Page One');
+ $assert->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Filter');
+ $this->assertSession()->assertWaitOnAjaxRequest();
+
+ // Verify that only the "Page One" Node is present.
+ $html = $session->getPage()->getHtml();
+ $this->assertContains('Page One', $html);
+ $this->assertNotContains('Page Two', $html);
+
+ // Close and re-open the modal.
+ $assert->buttonExists('Close', $dialog)->press();
+ $assert->elementExists('named', ['link', 'Administer content'])->click();
+ $assert->waitForElementVisible('css', '.views-test-modal');
+
+ // Ensure that the Content we're testing for is present.
+ $html = $session->getPage()->getHtml();
+ $this->assertContains('Page One', $html);
+ $this->assertContains('Page Two', $html);
+
+ // Search for "Page One".
+ $session->getPage()->fillField('title', 'Page One');
+ $assert->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Filter');
+ $this->assertSession()->assertWaitOnAjaxRequest();
+
+ // Verify that only the "Page One" Node is present.
+ $html = $session->getPage()->getHtml();
+ $this->assertContains('Page One', $html);
+ $this->assertNotContains('Page Two', $html);
+ }
+
}