You are here

public function SearchPreprocessLangcodeTest::testPreprocessStemming in Drupal 8

Same name and namespace in other branches
  1. 9 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 68

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
    ->drupalPostForm('search/node', $edit, 'edit-submit--2');

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

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

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