function ExposedFormRenderTest::testExposedFormRender

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php \Drupal\Tests\views\Kernel\Plugin\ExposedFormRenderTest::testExposedFormRender()
  2. 10 core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php \Drupal\Tests\views\Kernel\Plugin\ExposedFormRenderTest::testExposedFormRender()
  3. 11.x core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php \Drupal\Tests\views\Kernel\Plugin\ExposedFormRenderTest::testExposedFormRender()

Tests the exposed form markup.

File

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

Class

ExposedFormRenderTest
Tests the exposed form.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testExposedFormRender() {
    $view = Views::getView('test_exposed_form_buttons');
    $this->executeView($view);
    $exposed_form = $view->display_handler
        ->getPlugin('exposed_form');
    $output = $exposed_form->renderExposedForm();
    $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
    $this->assertFieldByXpath('//form/@id', Html::cleanCssIdentifier('views-exposed-form-' . $view->storage
        ->id() . '-' . $view->current_display), 'Expected form ID found.');
    $view->setDisplay('page_1');
    $expected_action = $view->display_handler
        ->getUrlInfo()
        ->toString();
    $this->assertFieldByXPath('//form/@action', $expected_action, 'The expected value for the action attribute was found.');
    // Make sure the description is shown.
    $result = $this->xpath('//form//div[contains(@id, "edit-type--2--description") and normalize-space(text())="Exposed description"]');
    $this->assertCount(1, $result, 'Filter description was found.');
}

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