1 search.test SearchConfigSettingsForm::testSearchSettingsPage()

Verify the search settings form.

File

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

Class

SearchConfigSettingsForm
Test config page.

Code

function testSearchSettingsPage() {

  // Test that the settings form displays the correct count of items left to index.
  $this->backdropGet('admin/config/search/settings');
  $this->assertText(t('There are @count items left to index.', array('@count' => 0)));

  // Reset indexes and verify the count of items left to index is correct.
  search_reindex();

  // Create a new node to test index rebuilding.
  $body_text = 'Gluten-free.';
  $this->backdropCreateNode(array(
    'body' => array(LANGUAGE_NONE => array(array('value' => $body_text))),
  ));

  $this->backdropGet('admin/config/search/settings');
  $this->assertText(t('There are @count items left to index.', array('@count' => 2)));

  // Test the Rebuild search index button.
  $this->backdropPost('admin/config/search/settings', array(), t('Rebuild search index'));
  $this->assertText(t('This action will rebuild the search index. It may be a lengthy process.'));
  $this->backdropPost('admin/config/search/settings/reindex', array(), t('Rebuild search index'));

  // Test that there are no items left to index.
  $this->backdropGet('admin/config/search/settings');
  $this->assertText(t('There are 0 items left to index.'));

  // Test that the new node was correctly indexed.
  $this->backdropGet('search/node/' . rawurlencode($body_text));
  $this->assertText($body_text, t('New node was correctly indexed after rebuilding'));

  // Test that the form saves with the default values.
  $this->backdropPost('admin/config/search/settings', array(), t('Save configuration'));
  $this->assertText(t('The active search modules have been changed.'), 'Form saves with the default values.');

  // Test that the form does not save with an invalid word length.
  $edit = array(
    'search_minimum_word_size' => $this->randomName(3),
  );
  $this->backdropPost('admin/config/search/settings', $edit, t('Save configuration'));
  $this->assertNoText(t('The active search modules have been changed.'), 'Form does not save with an invalid word length.');

  // Test logging setting. It should be on by default.
  $config = config('search.settings');
  $config->set('search_logging', TRUE)->save();
  $text = $this->randomName(5);
  $this->backdropPost('search/node', array('keys' => $text), t('Search'));
  $this->backdropGet('admin/reports/dblog');
  $this->assertLink('Searched Content for ' . $text . '.', 0, 'Search was logged');

  // Turn off logging.
  $config->set('search_logging', FALSE)->save();
  $text = $this->randomName(5);
  $this->backdropPost('search/node', array('keys' => $text), t('Search'));
  $this->backdropGet('admin/reports/dblog');
  $this->assertNoLink('Searched Content for ' . $text . '.', 'Search was not logged');
}