You are here

SingleFilterWidgetKernelTest.php in Better Exposed Filters 8.5

Same filename and directory in other branches
  1. 8.4 tests/src/Kernel/Plugin/filter/SingleFilterWidgetKernelTest.php

File

tests/src/Kernel/Plugin/filter/SingleFilterWidgetKernelTest.php
View source
<?php

namespace Drupal\Tests\better_exposed_filters\Kernel\Plugin\filter;

use Drupal\Tests\better_exposed_filters\Kernel\BetterExposedFiltersKernelTestBase;
use Drupal\views\Views;

/**
 * Tests the options of a single on/off filter widget.
 *
 * @group better_exposed_filters
 *
 * @see \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\FilterWidgetBase
 */
class SingleFilterWidgetKernelTest extends BetterExposedFiltersKernelTestBase {

  /**
   * {@inheritdoc}
   */
  public static $testViews = [
    'bef_test',
  ];

  /**
   * Tests hiding element with single option.
   */
  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();
  }

}

Classes

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