function SearchPreprocessLangcodeTest::testPreprocessStemming

Same name in other branches
  1. 9 core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php \Drupal\Tests\search\Functional\SearchPreprocessLangcodeTest::testPreprocessStemming()
  2. 8.9.x core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php \Drupal\Tests\search\Functional\SearchPreprocessLangcodeTest::testPreprocessStemming()
  3. 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 74

Class

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

Namespace

Drupal\Tests\search\Functional

Code

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.