You are here

function SearchConfigSettingsFormTest::testSearchSettingsPage in Zircon Profile 8

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

Verifies the search settings form.

File

core/modules/search/src/Tests/SearchConfigSettingsFormTest.php, line 68
Contains \Drupal\search\Tests\SearchConfigSettingsFormTest.

Class

SearchConfigSettingsFormTest
Verify the search config settings form.

Namespace

Drupal\search\Tests

Code

function testSearchSettingsPage() {

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

  // Test the re-index button.
  $this
    ->drupalPostForm('admin/config/search/pages', array(), t('Re-index site'));
  $this
    ->assertText(t('Are you sure you want to re-index the site'));
  $this
    ->drupalPostForm('admin/config/search/pages/reindex', array(), t('Re-index site'));
  $this
    ->assertText(t('All search indexes will be rebuilt'));
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->assertText(t('There is 1 item left to index.'));

  // Test that the form saves with the default values.
  $this
    ->drupalPostForm('admin/config/search/pages', array(), t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved.'), 'Form saves with the default values.');

  // Test that the form does not save with an invalid word length.
  $edit = array(
    'minimum_word_size' => $this
      ->randomMachineName(3),
  );
  $this
    ->drupalPostForm('admin/config/search/pages', $edit, t('Save configuration'));
  $this
    ->assertNoText(t('The configuration options have been saved.'), 'Form does not save with an invalid word length.');

  // Test logging setting. It should be off by default.
  $text = $this
    ->randomMachineName(5);
  $this
    ->drupalPostForm('search/node', array(
    'keys' => $text,
  ), t('Search'));
  $this
    ->drupalGet('admin/reports/dblog');
  $this
    ->assertNoLink('Searched Content for ' . $text . '.', 'Search was not logged');

  // Turn on logging.
  $edit = array(
    'logging' => TRUE,
  );
  $this
    ->drupalPostForm('admin/config/search/pages', $edit, t('Save configuration'));
  $text = $this
    ->randomMachineName(5);
  $this
    ->drupalPostForm('search/node', array(
    'keys' => $text,
  ), t('Search'));
  $this
    ->drupalGet('admin/reports/dblog');
  $this
    ->assertLink('Searched Content for ' . $text . '.', 0, 'Search was logged');
}