You are here

function SearchKeywordsConditionsTest::testSearchKeywordsConditions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/search/src/Tests/SearchKeywordsConditionsTest.php \Drupal\search\Tests\SearchKeywordsConditionsTest::testSearchKeywordsConditions()

Verify the keywords are captured and conditions respected.

File

core/modules/search/src/Tests/SearchKeywordsConditionsTest.php, line 49
Contains \Drupal\search\Tests\SearchKeywordsConditionsTest.

Class

SearchKeywordsConditionsTest
Verify the search without keywords set and extra conditions.

Namespace

Drupal\search\Tests

Code

function testSearchKeywordsConditions() {

  // No keys, not conditions - no results.
  $this
    ->drupalGet('search/dummy_path');
  $this
    ->assertNoText('Dummy search snippet to display');

  // With keys - get results.
  $keys = 'bike shed ' . $this
    ->randomMachineName();
  $this
    ->drupalGet("search/dummy_path", array(
    'query' => array(
      'keys' => $keys,
    ),
  ));
  $this
    ->assertText("Dummy search snippet to display. Keywords: {$keys}");
  $keys = 'blue drop ' . $this
    ->randomMachineName();
  $this
    ->drupalGet("search/dummy_path", array(
    'query' => array(
      'keys' => $keys,
    ),
  ));
  $this
    ->assertText("Dummy search snippet to display. Keywords: {$keys}");

  // Add some conditions and keys.
  $keys = 'moving drop ' . $this
    ->randomMachineName();
  $this
    ->drupalGet("search/dummy_path", array(
    'query' => array(
      'keys' => 'bike',
      'search_conditions' => $keys,
    ),
  ));
  $this
    ->assertText("Dummy search snippet to display.");
  $this
    ->assertRaw(Html::escape(print_r(array(
    'keys' => 'bike',
    'search_conditions' => $keys,
  ), TRUE)));
}