You are here

public function CacheabilityTest::testViewsCacheAddRemoveContent in Search API 8

Tests that indexing or deleting items clears the cache.

File

tests/src/Functional/CacheabilityTest.php, line 121

Class

CacheabilityTest
Tests the cacheability metadata of Search API.

Namespace

Drupal\Tests\search_api\Functional

Code

public function testViewsCacheAddRemoveContent() {
  $entity = $this
    ->addTestEntity(6, [
    'name' => 'Fresh node',
    'body' => 'test foobar Case',
    'type' => 'item',
  ]);

  // Prime page cache before indexing.
  $this
    ->drupalGet('search-api-test-search-view-caching-tag');
  $this
    ->assertSession()
    ->pageTextContains('Displaying 5 search results');
  $this
    ->indexItems($this->indexId);

  // Check that the newly indexed node is visible on the search index.
  $this
    ->drupalGet('search-api-test-search-view-caching-tag');
  $this
    ->assertSession()
    ->pageTextContains('Displaying 6 search results');
  $entity
    ->delete();

  // Check that the deleted entity is now no longer shown.
  $this
    ->drupalGet('search-api-test-search-view-caching-tag');
  $this
    ->assertSession()
    ->pageTextContains('Displaying 5 search results');
}