You are here

public function SearchAdvancedSearchFormTest::testFormRefill in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php \Drupal\Tests\search\Functional\SearchAdvancedSearchFormTest::testFormRefill()
  2. 10 core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php \Drupal\Tests\search\Functional\SearchAdvancedSearchFormTest::testFormRefill()

Tests that after submitting the advanced search form, the form is refilled.

File

core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php, line 89

Class

SearchAdvancedSearchFormTest
Indexes content and tests the advanced search form.

Namespace

Drupal\Tests\search\Functional

Code

public function testFormRefill() {
  $edit = [
    'keys' => 'cat',
    'or' => 'dog gerbil',
    'phrase' => 'pets are nice',
    'negative' => 'fish snake',
    'type[page]' => 'page',
  ];
  $this
    ->drupalGet('search/node');
  $this
    ->submitForm($edit, 'edit-submit--2');

  // Test that the encoded query appears in the page title. Only test the
  // part not including the quote, because assertText() cannot seem to find
  // the quote marks successfully.
  $this
    ->assertSession()
    ->pageTextContains('Search for cat dog OR gerbil -fish -snake');

  // Verify that all of the form fields are filled out.
  foreach ($edit as $key => $value) {
    if ($key != 'type[page]') {
      $this
        ->assertSession()
        ->fieldValueEquals($key, $value);
    }
    else {
      $this
        ->assertSession()
        ->checkboxChecked($key);
    }
  }

  // Now test by submitting the or/not part of the query in the main
  // search box, and verify that the advanced form is not filled out.
  // (It shouldn't be filled out unless you submit values in those fields.)
  $edit2 = [
    'keys' => 'cat dog OR gerbil -fish -snake',
  ];
  $this
    ->drupalGet('search/node');
  $this
    ->submitForm($edit2, 'edit-submit--2');
  $this
    ->assertSession()
    ->pageTextContains('Search for cat dog OR gerbil -fish -snake');
  foreach ($edit as $key => $value) {
    if ($key != 'type[page]') {
      $this
        ->assertSession()
        ->fieldValueNotEquals($key, $value);
    }
  }
}