function SearchPreprocessLangcodeTest::testPreprocessStemming
Tests stemming for hook_search_preprocess().
File
- 
              core/modules/ search/ tests/ src/ Functional/ SearchPreprocessLangcodeTest.php, line 74 
Class
- SearchPreprocessLangcodeTest
- Tests that the search preprocessing uses the correct language code.
Namespace
Drupal\Tests\search\FunctionalCode
public function testPreprocessStemming() : void {
  // 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');
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
