function ExposedFormRenderTest::testExposedFormRawInput

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php \Drupal\Tests\views\Kernel\Plugin\ExposedFormRenderTest::testExposedFormRawInput()
  2. 8.9.x core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php \Drupal\Tests\views\Kernel\Plugin\ExposedFormRenderTest::testExposedFormRawInput()
  3. 10 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 65

Class

ExposedFormRenderTest
Tests the exposed form.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testExposedFormRawInput() : void {
    NodeType::create([
        'type' => 'article',
        'name' => 'Article',
    ])->save();
    // Build the form state.
    $form = [];
    $view = Views::getView('test_exposed_admin_ui');
    $view->setDisplay();
    $this->executeView($view);
    $form_state = new FormState();
    $form_state->set('view', $view);
    $form_state->setValue('type', 'article');
    // Mock the exposed form.
    $exposed_form_cache = $this->createMock(ExposedFormCache::class);
    $current_path_stack = $this->createMock(CurrentPathStack::class);
    $exposed_form = new ViewsExposedForm($exposed_form_cache, $current_path_stack);
    $exposed_form->submitForm($form, $form_state);
    $updated_view = $form_state->get('view');
    $expected = [
        'type' => 'article',
    ];
    $this->assertSame($updated_view->exposed_raw_input, $expected);
    $form_state->setValue('type', [
        'article',
        'page',
    ]);
    $exposed_form->submitForm($form, $form_state);
    $updated_view = $form_state->get('view');
    $expected = [
        'type' => [
            'article',
            'page',
        ],
    ];
    $this->assertSame($updated_view->exposed_raw_input, $expected);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.