Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views / tests / src / Kernel / Plugin / ExposedFormRenderTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Kernel\Plugin;
4
5 use Drupal\Component\Utility\Html;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
8 use Drupal\views\Views;
9
10 /**
11  * Tests the exposed form.
12  *
13  * @group views
14  * @see \Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest
15  */
16 class ExposedFormRenderTest extends ViewsKernelTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $testViews = ['test_exposed_form_buttons'];
22
23   /**
24    * {@inheritdoc}
25    */
26   public static $modules = ['node'];
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp($import_test_views = TRUE) {
32     parent::setUp();
33     $this->installEntitySchema('node');
34   }
35
36   /**
37    * Tests the exposed form markup.
38    */
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));
45
46     $this->assertFieldByXpath('//form/@id', Html::cleanCssIdentifier('views-exposed-form-' . $view->storage->id() . '-' . $view->current_display), 'Expected form ID found.');
47
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.');
54   }
55
56   /**
57    * Tests the exposed form raw input.
58    */
59   public function testExposedFormRawInput() {
60     $node_type = NodeType::create(['type' => 'article']);
61     $node_type->save();
62
63     $view = Views::getView('test_exposed_form_buttons');
64     $view->setDisplay();
65     $view->displayHandlers->get('default')->overrideOption('filters', [
66       'type' => [
67         'exposed' => TRUE,
68         'field' => 'type',
69         'id' => 'type',
70         'table' => 'node_field_data',
71         'plugin_id' => 'in_operator',
72         'entity_type' => 'node',
73         'entity_field' => 'type',
74         'expose' => [
75           'identifier' => 'type',
76           'label' => 'Content: Type',
77           'operator_id' => 'type_op',
78           'reduce' => FALSE,
79           'multiple' => FALSE,
80         ],
81       ],
82       'type_with_default_value' => [
83         'exposed' => TRUE,
84         'field' => 'type',
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'],
91         'expose' => [
92           'identifier' => 'type_with_default_value',
93           'label' => 'Content: Type with value',
94           'operator_id' => 'type_op',
95           'reduce' => FALSE,
96           'multiple' => FALSE,
97         ],
98       ],
99       'multiple_types' => [
100         'exposed' => TRUE,
101         'field' => 'type',
102         'id' => 'multiple_types',
103         'table' => 'node_field_data',
104         'plugin_id' => 'in_operator',
105         'entity_type' => 'node',
106         'entity_field' => 'type',
107         'expose' => [
108           'identifier' => 'multiple_types',
109           'label' => 'Content: Type (multiple)',
110           'operator_id' => 'type_op',
111           'reduce' => FALSE,
112           'multiple' => TRUE,
113         ],
114       ],
115       'multiple_types_with_default_value' => [
116         'exposed' => TRUE,
117         'field' => 'type',
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'],
124         'expose' => [
125           'identifier' => 'multiple_types_with_default_value',
126           'label' => 'Content: Type with default value (multiple)',
127           'operator_id' => 'type_op',
128           'reduce' => FALSE,
129           'multiple' => TRUE,
130         ],
131       ],
132     ]);
133     $view->save();
134     $this->executeView($view);
135
136     $expected = [
137       'type' => 'All',
138       'type_with_default_value' => 'article',
139       'multiple_types_with_default_value' => ['article'],
140     ];
141     $this->assertSame($view->exposed_raw_input, $expected);
142   }
143
144 }