function SearchPreprocessLangcodeTest::testPreprocessLangcode

Same name in other branches
  1. 9 core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php \Drupal\Tests\search\Functional\SearchPreprocessLangcodeTest::testPreprocessLangcode()
  2. 8.9.x core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php \Drupal\Tests\search\Functional\SearchPreprocessLangcodeTest::testPreprocessLangcode()
  3. 10 core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php \Drupal\Tests\search\Functional\SearchPreprocessLangcodeTest::testPreprocessLangcode()

Tests that hook_search_preprocess() returns the correct langcode.

File

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

Class

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

Namespace

Drupal\Tests\search\Functional

Code

public function testPreprocessLangcode() : void {
    // Create a node.
    $this->node = $this->drupalCreateNode([
        '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 additional text that is added by the preprocess
    // function. If you search for text that is in the node, preprocess is
    // not invoked on the node during the search excerpt generation.
    $edit = [
        'or' => 'Additional text',
    ];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'edit-submit--2');
    // Checks if the langcode message has been set by hook_search_preprocess().
    $this->assertSession()
        ->pageTextContains('Langcode Preprocess Test: en');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.