function SearchPreprocessLangcodeTest::testPreprocessStemming in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/search/src/Tests/SearchPreprocessLangcodeTest.php \Drupal\search\Tests\SearchPreprocessLangcodeTest::testPreprocessStemming()
Tests stemming for hook_search_preprocess().
File
- core/modules/ search/ src/ Tests/ SearchPreprocessLangcodeTest.php, line 70 
- Contains \Drupal\search\Tests\SearchPreprocessLangcodeTest.
Class
- SearchPreprocessLangcodeTest
- Tests that the search preprocessing uses the correct language code.
Namespace
Drupal\search\TestsCode
function testPreprocessStemming() {
  // Create a node.
  $this->node = $this
    ->drupalCreateNode(array(
    'title' => 'we are testing',
    '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 title of the node with a POST query.
  $edit = array(
    'or' => 'testing',
  );
  $this
    ->drupalPostForm('search/node', $edit, t('Advanced search'));
  // Check if the node has been found.
  $this
    ->assertText('Search results');
  $this
    ->assertText('we are testing');
  // Search for the same node using a different query.
  $edit = array(
    'or' => 'test',
  );
  $this
    ->drupalPostForm('search/node', $edit, t('Advanced search'));
  // Check if the node has been found.
  $this
    ->assertText('Search results');
  $this
    ->assertText('we are testing');
}