3 namespace Drupal\Tests\views\Kernel\Plugin;
5 use Drupal\Component\Utility\Html;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
8 use Drupal\views\Views;
11 * Tests the exposed form.
14 * @see \Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest
16 class ExposedFormRenderTest extends ViewsKernelTestBase {
21 public static $testViews = ['test_exposed_form_buttons'];
26 public static $modules = ['node'];
31 protected function setUp($import_test_views = TRUE) {
33 $this->installEntitySchema('node');
37 * Tests the exposed form markup.
39 public function testExposedFormRender() {
40 $view = Views::getView('test_exposed_form_buttons');
41 $this->executeView($view);
42 $exposed_form = $view->display_handler->getPlugin('exposed_form');
43 $output = $exposed_form->renderExposedForm();
44 $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
46 $this->assertFieldByXpath('//form/@id', Html::cleanCssIdentifier('views-exposed-form-' . $view->storage->id() . '-' . $view->current_display), 'Expected form ID found.');
48 $view->setDisplay('page_1');
49 $expected_action = $view->display_handler->getUrlInfo()->toString();
50 $this->assertFieldByXPath('//form/@action', $expected_action, 'The expected value for the action attribute was found.');
51 // Make sure the description is shown.
52 $result = $this->xpath('//form//div[contains(@id, :id) and normalize-space(text())=:description]', [':id' => 'edit-type--description', ':description' => t('Exposed description')]);
53 $this->assertEqual(count($result), 1, 'Filter description was found.');
57 * Tests the exposed form raw input.
59 public function testExposedFormRawInput() {
60 $node_type = NodeType::create(['type' => 'article']);
63 $view = Views::getView('test_exposed_form_buttons');
65 $view->displayHandlers->get('default')->overrideOption('filters', [
70 'table' => 'node_field_data',
71 'plugin_id' => 'in_operator',
72 'entity_type' => 'node',
73 'entity_field' => 'type',
75 'identifier' => 'type',
76 'label' => 'Content: Type',
77 'operator_id' => 'type_op',
82 'type_with_default_value' => [
85 'id' => 'type_with_default_value',
86 'table' => 'node_field_data',
87 'plugin_id' => 'in_operator',
88 'entity_type' => 'node',
89 'entity_field' => 'type',
90 'value' => ['article', 'article'],
92 'identifier' => 'type_with_default_value',
93 'label' => 'Content: Type with value',
94 'operator_id' => 'type_op',
102 'id' => 'multiple_types',
103 'table' => 'node_field_data',
104 'plugin_id' => 'in_operator',
105 'entity_type' => 'node',
106 'entity_field' => 'type',
108 'identifier' => 'multiple_types',
109 'label' => 'Content: Type (multiple)',
110 'operator_id' => 'type_op',
115 'multiple_types_with_default_value' => [
118 'id' => 'multiple_types_with_default_value',
119 'table' => 'node_field_data',
120 'plugin_id' => 'in_operator',
121 'entity_type' => 'node',
122 'entity_field' => 'type',
123 'value' => ['article', 'article'],
125 'identifier' => 'multiple_types_with_default_value',
126 'label' => 'Content: Type with default value (multiple)',
127 'operator_id' => 'type_op',
134 $this->executeView($view);
138 'type_with_default_value' => 'article',
139 'multiple_types_with_default_value' => ['article'],
141 $this->assertSame($view->exposed_raw_input, $expected);