You are here

protected function GoogleAnalyticsSearchTest::createNodeAndIndex in Google Analytics 4.x

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/GoogleAnalyticsSearchTest.php \Drupal\Tests\google_analytics\Functional\GoogleAnalyticsSearchTest::createNodeAndIndex()
  2. 8.2 tests/src/Functional/GoogleAnalyticsSearchTest.php \Drupal\Tests\google_analytics\Functional\GoogleAnalyticsSearchTest::createNodeAndIndex()

Helper function to create the node and reindex search.

@internal

Parameters

string $test_string: Some unique identifying string to add to the text of the node.

Return value

\Drupal\node\NodeInterface The created node.

1 call to GoogleAnalyticsSearchTest::createNodeAndIndex()
GoogleAnalyticsSearchTest::testGoogleAnalyticsSearchTracking in tests/src/Functional/GoogleAnalyticsSearchTest.php
Tests if search tracking is properly added to the page.

File

tests/src/Functional/GoogleAnalyticsSearchTest.php, line 113

Class

GoogleAnalyticsSearchTest
Test search functionality of Google Analytics module.

Namespace

Drupal\Tests\google_analytics\Functional

Code

protected function createNodeAndIndex($test_string) {

  // Create the node.
  $node = $this
    ->drupalCreateNode([
    'title' => "Someone who says {$test_string}!",
    'body' => [
      [
        'value' => "We are the knights who say {$test_string}!",
      ],
    ],
    'type' => 'page',
  ]);

  // Index the node or it cannot found.
  $node_search_plugin = $this->container
    ->get('plugin.manager.search')
    ->createInstance('node_search');

  // Update the search index.
  $node_search_plugin
    ->updateIndex();
  $search_index = \Drupal::service('search.index');
  assert($search_index instanceof SearchIndexInterface);
  return $node;
}