You are here

public function ExposedFormTest::testInputRequired in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testInputRequired()

Tests the input required exposed form type.

File

core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php, line 300

Class

ExposedFormTest
Tests exposed forms functionality.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testInputRequired() {
  $view = View::load('test_exposed_form_buttons');
  $display =& $view
    ->getDisplay('default');
  $display['display_options']['exposed_form']['type'] = 'input_required';
  $view
    ->save();
  $this
    ->drupalGet('test_exposed_form_buttons');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->helperButtonHasLabel('edit-submit-test-exposed-form-buttons', 'Apply');

  // Ensure that no results are displayed by default when no input is
  // provided.
  $this
    ->assertSession()
    ->elementNotExists('xpath', "//div[contains(@class, 'views-row')]");
  $this
    ->drupalGet('test_exposed_form_buttons', [
    'query' => [
      'type' => 'article',
    ],
  ]);

  // Ensure that results are displayed by default when input is provided.
  $this
    ->assertSession()
    ->elementsCount('xpath', "//div[contains(@class, 'views-row')]", 5);
}