function SearchKeywordsConditionsTest::testSearchKeywordsConditions

Same name in other branches
  1. 8.9.x core/modules/search/tests/src/Functional/SearchKeywordsConditionsTest.php \Drupal\Tests\search\Functional\SearchKeywordsConditionsTest::testSearchKeywordsConditions()
  2. 10 core/modules/search/tests/src/Functional/SearchKeywordsConditionsTest.php \Drupal\Tests\search\Functional\SearchKeywordsConditionsTest::testSearchKeywordsConditions()
  3. 11.x core/modules/search/tests/src/Functional/SearchKeywordsConditionsTest.php \Drupal\Tests\search\Functional\SearchKeywordsConditionsTest::testSearchKeywordsConditions()

Verify the keywords are captured and conditions respected.

File

core/modules/search/tests/src/Functional/SearchKeywordsConditionsTest.php, line 61

Class

SearchKeywordsConditionsTest
Verify the search without keywords set and extra conditions.

Namespace

Drupal\Tests\search\Functional

Code

public function testSearchKeywordsConditions() {
    // No keys, not conditions - no results.
    $this->drupalGet('search/dummy_path');
    $this->assertSession()
        ->pageTextNotContains('Dummy search snippet to display');
    // With keys - get results.
    $keys = 'bike shed ' . $this->randomMachineName();
    $this->drupalGet("search/dummy_path", [
        'query' => [
            'keys' => $keys,
        ],
    ]);
    $this->assertSession()
        ->pageTextContains("Dummy search snippet to display. Keywords: {$keys}");
    $keys = 'blue drop ' . $this->randomMachineName();
    $this->drupalGet("search/dummy_path", [
        'query' => [
            'keys' => $keys,
        ],
    ]);
    $this->assertSession()
        ->pageTextContains("Dummy search snippet to display. Keywords: {$keys}");
    // Add some conditions and keys.
    $keys = 'moving drop ' . $this->randomMachineName();
    $this->drupalGet("search/dummy_path", [
        'query' => [
            'keys' => 'bike',
            'search_conditions' => $keys,
        ],
    ]);
    $this->assertSession()
        ->pageTextContains("Dummy search snippet to display.");
    $this->assertSession()
        ->responseContains(Html::escape(print_r([
        'keys' => 'bike',
        'search_conditions' => $keys,
    ], TRUE)));
}

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