You are here

public function ExposedFormRenderTest::testExposedFormRawInput in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php \Drupal\Tests\views\Kernel\Plugin\ExposedFormRenderTest::testExposedFormRawInput()

Tests the exposed form raw input.

File

core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php, line 59

Class

ExposedFormRenderTest
Tests the exposed form.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testExposedFormRawInput() {
  $node_type = NodeType::create([
    'type' => 'article',
  ]);
  $node_type
    ->save();
  $view = Views::getView('test_exposed_form_buttons');
  $view
    ->setDisplay();
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', [
    'type' => [
      'exposed' => TRUE,
      'field' => 'type',
      'id' => 'type',
      'table' => 'node_field_data',
      'plugin_id' => 'in_operator',
      'entity_type' => 'node',
      'entity_field' => 'type',
      'expose' => [
        'identifier' => 'type',
        'label' => 'Content: Type',
        'operator_id' => 'type_op',
        'reduce' => FALSE,
        'multiple' => FALSE,
      ],
    ],
    'type_with_default_value' => [
      'exposed' => TRUE,
      'field' => 'type',
      'id' => 'type_with_default_value',
      'table' => 'node_field_data',
      'plugin_id' => 'in_operator',
      'entity_type' => 'node',
      'entity_field' => 'type',
      'value' => [
        'article',
        'article',
      ],
      'expose' => [
        'identifier' => 'type_with_default_value',
        'label' => 'Content: Type with value',
        'operator_id' => 'type_op',
        'reduce' => FALSE,
        'multiple' => FALSE,
      ],
    ],
    'multiple_types' => [
      'exposed' => TRUE,
      'field' => 'type',
      'id' => 'multiple_types',
      'table' => 'node_field_data',
      'plugin_id' => 'in_operator',
      'entity_type' => 'node',
      'entity_field' => 'type',
      'expose' => [
        'identifier' => 'multiple_types',
        'label' => 'Content: Type (multiple)',
        'operator_id' => 'type_op',
        'reduce' => FALSE,
        'multiple' => TRUE,
      ],
    ],
    'multiple_types_with_default_value' => [
      'exposed' => TRUE,
      'field' => 'type',
      'id' => 'multiple_types_with_default_value',
      'table' => 'node_field_data',
      'plugin_id' => 'in_operator',
      'entity_type' => 'node',
      'entity_field' => 'type',
      'value' => [
        'article',
        'article',
      ],
      'expose' => [
        'identifier' => 'multiple_types_with_default_value',
        'label' => 'Content: Type with default value (multiple)',
        'operator_id' => 'type_op',
        'reduce' => FALSE,
        'multiple' => TRUE,
      ],
    ],
  ]);
  $view
    ->save();
  $this
    ->executeView($view);
  $expected = [
    'type' => 'All',
    'type_with_default_value' => 'article',
    'multiple_types_with_default_value' => [
      'article' => 'article',
    ],
  ];
  $this
    ->assertSame($view->exposed_raw_input, $expected);
}