function SearchMultilingualEntityTest::testSearchingMultilingualFieldValues

Tests searching nodes with multiple languages.

File

drupal/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php, line 112
Definition of Drupal\search\Tests\SearchMultilingualEntityTest.

Class

SearchMultilingualEntityTest
Tests entities with multilingual fields.

Namespace

Drupal\search\Tests

Code

function testSearchingMultilingualFieldValues() {

  // Update the index and then run the shutdown method.
  // See testIndexingThrottle() for further explanation.
  node_update_index();
  search_update_totals();
  foreach ($this->searchable_nodes as $node) {

    // Each searchable node that we created contains values in the body field
    // in one or more languages. Let's pick the last language variant from the
    // body array and execute a search using that as a search keyword.
    $body_language_variant = end($node->body);
    $search_result = node_search_execute($body_language_variant[0]['value']);

    // See whether we get the same node as a result.
    $sts = $this
      ->assertTrue(!empty($search_result[0]['node']->nid) && $search_result[0]['node']->nid == $node->nid, 'The search has resulted the correct node.');
  }
}