1 search.test SearchPageText::testSearchText()

Tests the failed search text, and various other text on the search page.


core/modules/search/tests/search.test, line 253
Tests for search.module.


Tests the bike shed text on no results page, and text on the search page.


function testSearchText() {
  $this->assertText(t('Enter your keywords'));
  $title = t('Search') . ' | Backdrop CMS';
  $this->assertTitle($title, 'Search page title is correct');

  $edit = array();
  $edit['keys'] = 'bike shed ' . $this->randomName();
  $this->backdropPost('search/node', $edit, t('Search'));
  $this->assertText(t('Consider loosening your query with OR. bike OR shed will often show more results than bike shed.'), 'Help text is displayed when search returns no results.');
  $this->assertTitle($title, 'Search page title is correct');

  $edit['keys'] = $this->searching_user->name;
  $this->backdropPost('search/user', $edit, t('Search'));
  $this->assertTitle($title, 'Search page title is correct');

  // Test that search keywords containing slashes are correctly loaded
  // from the path and displayed in the search form.
  $arg = $this->randomName() . '/' . $this->randomName();
  $this->backdropGet('search/node/' . $arg);
  $input = $this->xpath("//input[@id='edit-keys' and @value='{$arg}']");
  $this->assertFalse(empty($input), 'Search keys with a / are correctly set as the default value in the search box.');

  // Test a search input exceeding the limit of AND/OR combinations to test
  // the Denial-of-Service protection.
  $limit = config_get('search.settings', 'search_and_or_limit');
  $keys = array();
  for ($i = 0; $i < $limit + 1; $i++) {
    $keys[] = $this->randomName(3);
    if ($i % 2 == 0) {
      $keys[] = 'OR';
  $edit['keys'] = implode(' ', $keys);
  $this->backdropPost('search/node', $edit, t('Search'));
  $this->assertRaw(t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', array('@count' => $limit)));