You are here

public function SearchConfigSettingsFormTest::testSearchSettingsPage in Drupal 9

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

Verifies the search settings form.

File

core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php, line 87

Class

SearchConfigSettingsFormTest
Verify the search config settings form.

Namespace

Drupal\Tests\search\Functional

Code

public function testSearchSettingsPage() {

  // Test that the settings form displays the correct count of items left to index.
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->assertSession()
    ->pageTextContains('There are 0 items left to index.');

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

  // Test that the form saves with the default values.
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->submitForm([], 'Save configuration');
  $this
    ->assertSession()
    ->pageTextContains('The configuration options have been saved.');

  // Test that the form does not save with an invalid word length.
  $edit = [
    'minimum_word_size' => $this
      ->randomMachineName(3),
  ];
  $this
    ->drupalGet('admin/config/search/pages');
  $this
    ->submitForm($edit, 'Save configuration');
  $this
    ->assertSession()
    ->pageTextNotContains('The configuration options have been saved.');

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

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