function SearchPreprocessLangcodeTest::testPreprocessLangcode

Same name and namespace in other branches
  1. 9 core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php \Drupal\Tests\search\Functional\SearchPreprocessLangcodeTest::testPreprocessLangcode()
  2. 10 core/modules/search/tests/src/Functional/SearchPreprocessLangcodeTest.php \Drupal\Tests\search\Functional\SearchPreprocessLangcodeTest::testPreprocessLangcode()
  3. 11.x 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 48

Class

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

Namespace

Drupal\Tests\search\Functional

Code

public function testPreprocessLangcode() {
    // 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->drupalPostForm('search/node', $edit, 'edit-submit--2');
    // Checks if the langcode message has been set by hook_search_preprocess().
    $this->assertText('Langcode Preprocess Test: en');
}

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