You are here

public function BetterExposedFiltersTest::testAutoSubmit in Better Exposed Filters 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/FunctionalJavascript/BetterExposedFiltersTest.php \Drupal\Tests\better_exposed_filters\FunctionalJavascript\BetterExposedFiltersTest::testAutoSubmit()

Tests if filtering via auto-submit works.

File

tests/src/FunctionalJavascript/BetterExposedFiltersTest.php, line 72

Class

BetterExposedFiltersTest
Tests the basic AJAX functionality of BEF exposed forms.

Namespace

Drupal\Tests\better_exposed_filters\FunctionalJavascript

Code

public function testAutoSubmit() {
  $view = Views::getView('bef_test');
  $display =& $view->storage
    ->getDisplay('default');

  // Enable auto-submit, but disable for text fields.
  $this
    ->setBetterExposedOptions($view, [
    'general' => [
      'autosubmit' => TRUE,
      'autosubmit_exclude_textfield' => TRUE,
    ],
  ]);

  // Visit the bef-test page.
  $this
    ->drupalGet('bef-test');
  $session = $this
    ->getSession();
  $page = $session
    ->getPage();

  // Ensure that the content we're testing for is present.
  $html = $page
    ->getHtml();
  $this
    ->assertContains('Page One', $html);
  $this
    ->assertContains('Page Two', $html);

  // Search for "Page One".
  $field_bef_integer = $page
    ->findField('field_bef_integer_value');
  $field_bef_integer
    ->setValue('1');
  $field_bef_integer
    ->blur();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Verify that only the "Page One" Node is present.
  $html = $page
    ->getHtml();
  $this
    ->assertContains('Page One', $html);
  $this
    ->assertNotContains('Page Two', $html);

  // Enter value in email field.
  $field_bef_email = $page
    ->find('css', '.form-item-field-bef-email-value input');
  $field_bef_email
    ->setValue('qwerty@test.com');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Verify nothing has changed.
  $this
    ->assertContains('Page One', $html);
  $this
    ->assertNotContains('Page Two', $html);

  // Submit form.
  $this
    ->submitForm([], 'Apply');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Verify no results are visible.
  $html = $page
    ->getHtml();
  $this
    ->assertNotContains('Page One', $html);
  $this
    ->assertNotContains('Page Two', $html);
}