You are here

public function IndexResourceTest::testCacheMetadata in JSON:API Search API 8

Tests cache tag invalidation.

File

tests/src/Functional/IndexResourceTest.php, line 125

Class

IndexResourceTest
Tests index resource..

Namespace

Drupal\Tests\jsonapi_search_api\Functional

Code

public function testCacheMetadata() {
  $request_options = [];
  $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
  $url = Url::fromRoute('jsonapi_search_api.index_database_search_index', [], []);
  $response = $this
    ->request('GET', $url, $request_options);
  $this
    ->assertEquals([
    'MISS',
  ], $response
    ->getHeader('X-Drupal-Cache'));
  $response = $this
    ->request('GET', $url, $request_options);
  $this
    ->assertEquals([
    'HIT',
  ], $response
    ->getHeader('X-Drupal-Cache'));
  $entity_id = count($this->entities) + 1;
  $entity = $this
    ->addTestEntity($entity_id, [
    'name' => 'bar',
    'body' => 'test foobar Case',
    'type' => 'item',
  ]);
  $this
    ->indexItems('database_search_index');
  $response = $this
    ->request('GET', $url, $request_options);
  $this
    ->assertEquals([
    'MISS',
  ], $response
    ->getHeader('X-Drupal-Cache'));
}