You are here

public function SingleFilterWidgetKernelTest::testSingleExposedCheckbox in Better Exposed Filters 8.5

Same name and namespace in other branches
  1. 8.4 tests/src/Kernel/Plugin/filter/SingleFilterWidgetKernelTest.php \Drupal\Tests\better_exposed_filters\Kernel\Plugin\filter\SingleFilterWidgetKernelTest::testSingleExposedCheckbox()

Tests hiding element with single option.

File

tests/src/Kernel/Plugin/filter/SingleFilterWidgetKernelTest.php, line 25

Class

SingleFilterWidgetKernelTest
Tests the options of a single on/off filter widget.

Namespace

Drupal\Tests\better_exposed_filters\Kernel\Plugin\filter

Code

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

  // Change exposed filter "field_bef_boolean" to single on/off (i.e.
  // 'bef_single').
  $this
    ->setBetterExposedOptions($view, [
    'filter' => [
      'field_bef_boolean_value' => [
        'plugin_id' => 'bef_single',
      ],
    ],
  ]);

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

  // Check our "FIELD_BEF_BOOLEAN" filter is rendered as a single checkbox.
  $actual = $this
    ->xpath('//form//input[@type="checkbox" and starts-with(@name, "field_bef_boolean_value")]');
  $this
    ->assertCount(1, $actual, 'Exposed filter "FIELD_BEF_BOOLEAN" is rendered as a checkbox.');
  $view
    ->destroy();
}