View source
<?php
namespace Drupal\Tests\better_exposed_filters\Kernel\Plugin\filter;
use Drupal\Tests\better_exposed_filters\Kernel\BetterExposedFiltersKernelTestBase;
use Drupal\views\Views;
class RadioButtonsFilterWidgetKernelTest extends BetterExposedFiltersKernelTestBase {
public static $testViews = [
'bef_test',
];
public function testExposedCheckboxes() {
$view = Views::getView('bef_test');
$display =& $view->storage
->getDisplay('default');
$display['display_options']['filters']['field_bef_integer_value']['expose']['multiple'] = TRUE;
$display['display_options']['filters']['term_node_tid_depth']['expose']['multiple'] = TRUE;
$display['display_options']['filters']['term_node_tid_depth']['hierarchy'] = TRUE;
$this
->setBetterExposedOptions($view, [
'filter' => [
'field_bef_integer_value' => [
'plugin_id' => 'bef',
],
'term_node_tid_depth' => [
'plugin_id' => 'bef',
],
],
]);
$this
->renderExposedForm($view);
$actual = $this
->xpath('//form//input[@type="checkbox" and starts-with(@name, "field_bef_integer_value")]');
$this
->assertCount(5, $actual, 'Exposed filter "FIELD_BEF_INTEGER" has correct number of exposed checkboxes.');
$actual = $this
->xpath("//form//div[contains(concat(' ',normalize-space(@class),' '),' bef-nested ')]");
$this
->assertCount(1, $actual, 'Exposed filter "TERM_NODE_TID_DEPTH" has bef-nested class');
$actual = $this
->xpath('//form//div[@id="edit-term-node-tid-depth--2"]/div/ul/li/div/input[@type="checkbox" and starts-with(@name, "term_node_tid_depth")]');
$this
->assertCount(3, $actual, 'Exposed filter "TERM_NODE_TID_DEPTH" has correct number of exposed top-level checkboxes.');
$actual = $this
->xpath('//form//div[@id="edit-term-node-tid-depth--2"]/div/ul/li/ul/li/div/input[@type="checkbox" and starts-with(@name, "term_node_tid_depth")]');
$this
->assertCount(5, $actual, 'Exposed filter "TERM_NODE_TID_DEPTH" has correct number of exposed second-level checkboxes.');
$actual = $this
->xpath('//form//div[@id="edit-term-node-tid-depth--2"]/div/ul/li/ul/li/ul/li/div/input[@type="checkbox" and starts-with(@name, "term_node_tid_depth")]');
$this
->assertCount(14, $actual, 'Exposed filter "TERM_NODE_TID_DEPTH" has correct number of exposed third-level checkboxes.');
$view
->destroy();
}
public function testExposedRadioButtons() {
$view = Views::getView('bef_test');
$display =& $view->storage
->getDisplay('default');
$display['display_options']['filters']['term_node_tid_depth']['hierarchy'] = TRUE;
$this
->setBetterExposedOptions($view, [
'filter' => [
'field_bef_boolean_value' => [
'plugin_id' => 'bef',
],
'term_node_tid_depth' => [
'plugin_id' => 'bef',
],
],
]);
$this
->renderExposedForm($view);
$actual = $this
->xpath('//form//input[@type="radio" and @name="field_bef_boolean_value"]');
$this
->assertCount(3, $actual, 'Exposed filter "FIELD_BEF_BOOLEAN" renders as radio buttons.');
$actual = $this
->xpath("//form//div[contains(concat(' ',normalize-space(@class),' '),' bef-nested ')]");
$this
->assertCount(1, $actual, 'Exposed filter "TERM_NODE_TID_DEPTH" has bef-nested class');
$actual = $this
->xpath('//form//div[@id="edit-term-node-tid-depth--2"]/div/ul/li/div/input[@type="radio" and starts-with(@name, "term_node_tid_depth")]');
$this
->assertCount(4, $actual, 'Exposed filter "TERM_NODE_TID_DEPTH" has correct number of exposed top-level radio buttons.');
$actual = $this
->xpath('//form//div[@id="edit-term-node-tid-depth--2"]/div/ul/li/ul/li/div/input[@type="radio" and starts-with(@name, "term_node_tid_depth")]');
$this
->assertCount(5, $actual, 'Exposed filter "TERM_NODE_TID_DEPTH" has correct number of exposed second-level radio buttons.');
$actual = $this
->xpath('//form//div[@id="edit-term-node-tid-depth--2"]/div/ul/li/ul/li/ul/li/div/input[@type="radio" and starts-with(@name, "term_node_tid_depth")]');
$this
->assertCount(14, $actual, 'Exposed filter "TERM_NODE_TID_DEPTH" has correct number of exposed third-level radio buttons.');
$view
->destroy();
}
}