You are here

public function SearchPreprocessLangcodeTest::testPreprocessLangcode in Drupal 9

Same name and namespace in other branches
  1. 8 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()

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
    ->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');
}