You are here

public function ExposedFilterAJAXTest::testExposedFiltersInModal in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\ExposedFilterAJAXTest::testExposedFiltersInModal()

Tests if exposed filtering via AJAX works in a modal.

File

core/modules/views/tests/src/FunctionalJavascript/ExposedFilterAJAXTest.php, line 109

Class

ExposedFilterAJAXTest
Tests the basic AJAX functionality of Views exposed forms.

Namespace

Drupal\Tests\views\FunctionalJavascript

Code

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
    ->assertStringContainsString('Page One', $html);
  $this
    ->assertStringContainsString('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
    ->assertStringContainsString('Page One', $html);
  $this
    ->assertStringNotContainsString('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
    ->assertStringContainsString('Page One', $html);
  $this
    ->assertStringContainsString('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
    ->assertStringContainsString('Page One', $html);
  $this
    ->assertStringNotContainsString('Page Two', $html);
}