You are here

public function ExcerptFieldTest::testSearchExcerptField in Search API 8

Tests that the "Search excerpt" field in entity displays works correctly.

File

tests/src/Functional/ExcerptFieldTest.php, line 56

Class

ExcerptFieldTest
Verifies that the "Search excerpt" field in entity displays works correctly.

Namespace

Drupal\Tests\search_api\Functional

Code

public function testSearchExcerptField() {
  $assertSession = $this
    ->assertSession();
  $path = '/search-api-test-excerpt-field';
  $this
    ->drupalGet($path);
  foreach ($this->ids as $itemId) {
    $assertSession
      ->pageTextContains("Item {$itemId} test excerpt");
  }

  // Visiting the same page a second time retrieves the rendered node from
  // cache, not using the updated test excerpt template.
  $stateKey = 'search_api_test_excerpt_field';
  \Drupal::state()
    ->set($stateKey, 'test--{{item_id}}--excerpt');
  $this
    ->drupalGet($path);
  foreach ($this->ids as $itemId) {
    $assertSession
      ->pageTextContains("Item {$itemId} test excerpt");
    $assertSession
      ->pageTextNotContains("test--{$itemId}--excerpt");
  }

  // Changing the GET parameters does skip the render cache for the nodes.
  $this
    ->drupalGet($path, [
    'query' => [
      'foo' => 'bar',
    ],
  ]);
  foreach ($this->ids as $itemId) {
    $assertSession
      ->pageTextContains("test--{$itemId}--excerpt");
    $assertSession
      ->pageTextNotContains("Item {$itemId} test excerpt");
  }
}