You are here

function SearchPreprocessLangcodeTest::testPreprocessLangcode in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/search/src/Tests/SearchPreprocessLangcodeTest.php \Drupal\search\Tests\SearchPreprocessLangcodeTest::testPreprocessLangcode()

Tests that hook_search_preprocess() returns the correct langcode.

File

core/modules/search/src/Tests/SearchPreprocessLangcodeTest.php, line 45
Contains \Drupal\search\Tests\SearchPreprocessLangcodeTest.

Class

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

Namespace

Drupal\search\Tests

Code

function testPreprocessLangcode() {

  // Create a node.
  $this->node = $this
    ->drupalCreateNode(array(
    'body' => array(
      array(),
    ),
    'langcode' => 'en',
  ));

  // First update the index. This does the initial processing.
  $this->container
    ->get('plugin.manager.search')
    ->createInstance('node_search')
    ->updateIndex();

  // Then, run the shutdown function. Testing is a unique case where indexing
  // and searching has to happen in the same request, so running the shutdown
  // function manually is needed to finish the indexing process.
  search_update_totals();

  // 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 = array(
    'or' => 'Additional text',
  );
  $this
    ->drupalPostForm('search/node', $edit, t('Advanced search'));

  // Checks if the langcode message has been set by hook_search_preprocess().
  $this
    ->assertText('Langcode Preprocess Test: en');
}