You are here

public function BetterExposedFiltersTest::testSecondaryOptions in Better Exposed Filters 8.5

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

Tests placing exposed filters inside a collapsible field-set.

File

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

Class

BetterExposedFiltersTest
Tests the basic AJAX functionality of BEF exposed forms.

Namespace

Drupal\Tests\better_exposed_filters\FunctionalJavascript

Code

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

  // Enable auto-submit, but disable for text fields.
  $this
    ->setBetterExposedOptions($view, [
    'general' => [
      'allow_secondary' => TRUE,
      'secondary_label' => 'Secondary Options TEST',
    ],
    'sort' => [
      'plugin_id' => 'default',
      'advanced' => [
        'is_secondary' => TRUE,
      ],
    ],
    'pager' => [
      'plugin_id' => 'default',
      'advanced' => [
        'is_secondary' => TRUE,
      ],
    ],
    'filter' => [
      'field_bef_boolean_value' => [
        'plugin_id' => 'default',
        'advanced' => [
          'is_secondary' => TRUE,
        ],
      ],
    ],
  ]);

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

  // Assert our fields are initially hidden inside the collapsible field-set.
  $secondary_options = $page
    ->find('css', '.bef--secondary');
  $this
    ->assertFalse($secondary_options
    ->hasAttribute('open'));
  $secondary_options
    ->hasField('field_bef_boolean_value');

  // Submit form and set a value for the boolean field.
  $secondary_options
    ->click();
  $this
    ->submitForm([
    'field_bef_boolean_value' => 1,
  ], 'Apply');
  $session = $this
    ->getSession();
  $page = $session
    ->getPage();

  // Verify our field-set is open and our fields visible.
  $secondary_options = $page
    ->find('css', '.bef--secondary');
  $this
    ->assertTrue($secondary_options
    ->hasAttribute('open'));
}