1 search.test SearchConfigSettingsForm::testSearchSettingsPage()

Verify the search settings form.

File

core/modules/search/tests/search.test, line 1381
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)));

  // Test the Invalidate search index button.
  $this->backdropPost('admin/config/search/settings', array(), t('Invalidate search index'));
  $this->assertText(t('Are you sure you want to invalidate the search index?'));
  $this->backdropPost('admin/config/search/settings/reindex', array(), t('Invalidate search index'));
  $this->assertText(t('The search index will be invalidated'));
  $this->backdropGet('admin/config/search/settings');
  $this->assertText(t('There is 1 item left to index.'));

  // 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');
}