You are here

function SearchNodeUpdateAndDeletionTest::testSearchIndexUpdateOnNodeChange in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/search/src/Tests/SearchNodeUpdateAndDeletionTest.php \Drupal\search\Tests\SearchNodeUpdateAndDeletionTest::testSearchIndexUpdateOnNodeChange()

Tests that the search index info is properly updated when a node changes.

File

core/modules/search/src/Tests/SearchNodeUpdateAndDeletionTest.php, line 41
Contains \Drupal\search\Tests\SearchNodeUpdateAndDeletionTest.

Class

SearchNodeUpdateAndDeletionTest
Tests search index is updated properly when nodes are removed or updated.

Namespace

Drupal\search\Tests

Code

function testSearchIndexUpdateOnNodeChange() {

  // Create a node.
  $node = $this
    ->drupalCreateNode(array(
    'title' => 'Someone who says Ni!',
    'body' => array(
      array(
        'value' => "We are the knights who say Ni!",
      ),
    ),
    'type' => 'page',
  ));
  $node_search_plugin = $this->container
    ->get('plugin.manager.search')
    ->createInstance('node_search');

  // Update the search index.
  $node_search_plugin
    ->updateIndex();
  search_update_totals();

  // Search the node to verify it appears in search results
  $edit = array(
    'keys' => 'knights',
  );
  $this
    ->drupalPostForm('search/node', $edit, t('Search'));
  $this
    ->assertText($node
    ->label());

  // Update the node
  $node->body->value = "We want a shrubbery!";
  $node
    ->save();

  // Run indexer again
  $node_search_plugin
    ->updateIndex();
  search_update_totals();

  // Search again to verify the new text appears in test results.
  $edit = array(
    'keys' => 'shrubbery',
  );
  $this
    ->drupalPostForm('search/node', $edit, t('Search'));
  $this
    ->assertText($node
    ->label());
}