function SearchAdvancedSearchFormTest::testFormRefill

Same name in other branches
  1. 9 core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php \Drupal\Tests\search\Functional\SearchAdvancedSearchFormTest::testFormRefill()
  2. 8.9.x core/modules/search/tests/src/Functional/SearchAdvancedSearchFormTest.php \Drupal\Tests\search\Functional\SearchAdvancedSearchFormTest::testFormRefill()
  3. 11.x 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 94

Class

SearchAdvancedSearchFormTest
Indexes content and tests the advanced search form.

Namespace

Drupal\Tests\search\Functional

Code

public function testFormRefill() : void {
    $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);
        }
    }
}

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