You are here

public function SearchPreprocessLangcodeTest::testPreprocessStemming in Drupal 9

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

Tests stemming for hook_search_preprocess().

File

core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php, line 69

Class

SearchPreprocessLangcodeTest
Tests that the search preprocessing uses the correct language code.

Namespace

Drupal\Tests\search\Functional

Code

public function testPreprocessStemming() {

  // Create a node.
  $this->node = $this
    ->drupalCreateNode([
    'title' => 'we are testing',
    'body' => [
      [],
    ],
    'langcode' => 'en',
  ]);

  // First update the index. This does the initial processing.
  $this->container
    ->get('plugin.manager.search')
    ->createInstance('node_search')
    ->updateIndex();

  // Search for the title of the node with a POST query.
  $edit = [
    'or' => 'testing',
  ];
  $this
    ->drupalGet('search/node');
  $this
    ->submitForm($edit, 'edit-submit--2');

  // Check if the node has been found.
  $this
    ->assertSession()
    ->pageTextContains('Search results');
  $this
    ->assertSession()
    ->pageTextContains('we are testing');

  // Search for the same node using a different query.
  $edit = [
    'or' => 'test',
  ];
  $this
    ->drupalGet('search/node');
  $this
    ->submitForm($edit, 'edit-submit--2');

  // Check if the node has been found.
  $this
    ->assertSession()
    ->pageTextContains('Search results');
  $this
    ->assertSession()
    ->pageTextContains('we are testing');
}