You are here

public function HiddenFilterWidgetKernelTest::testMultipleExposedHiddenElement in Better Exposed Filters 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/Kernel/Plugin/filter/HiddenFilterWidgetKernelTest.php \Drupal\Tests\better_exposed_filters\Kernel\Plugin\filter\HiddenFilterWidgetKernelTest::testMultipleExposedHiddenElement()

Tests hiding element with multiple options.

File

tests/src/Kernel/Plugin/filter/HiddenFilterWidgetKernelTest.php, line 51

Class

HiddenFilterWidgetKernelTest
Tests the options of a hidden filter widget.

Namespace

Drupal\Tests\better_exposed_filters\Kernel\Plugin\filter

Code

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

  // Set filter to "multiple".
  $display['display_options']['filters']['field_bef_integer_value']['expose']['multiple'] = TRUE;

  // Change exposed filter "field_bef_integer" to hidden (i.e. 'bef_hidden').
  $this
    ->setBetterExposedOptions($view, [
    'filter' => [
      'field_bef_integer_value' => [
        'plugin_id' => 'bef_hidden',
      ],
    ],
  ]);

  // Render the exposed form.
  $this
    ->renderExposedForm($view);

  // Check our "FIELD_BEF_INTEGER" filter is rendered as a hidden element.
  $actual = $this
    ->xpath('//form//label[@type="label" and starts-with(@for, "edit-field-bef-integer-value")]');
  $this
    ->assertCount(0, $actual, 'Exposed filter "FIELD_BEF_INTEGER" is hidden.');
  $actual = $this
    ->xpath('//form//input[@type="hidden" and starts-with(@name, "field_bef_integer_value")]');
  $this
    ->assertCount(0, $actual, 'Exposed filter "FIELD_BEF_INTEGER" has no selected values.');
}