You are here

protected function NodeTest::assertNormalizedFieldsAreCached in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::assertNormalizedFieldsAreCached()
  2. 10 core/modules/jsonapi/tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::assertNormalizedFieldsAreCached()

Checks that the provided field names are the only fields in the cache.

The normalization cache should only have these fields, which build up across responses.

Parameters

string[] $field_names: The field names.

1 call to NodeTest::assertNormalizedFieldsAreCached()
NodeTest::assertCacheableNormalizations in core/modules/jsonapi/tests/src/Functional/NodeTest.php
Asserts that normalizations are cached in an incremental way.

File

core/modules/jsonapi/tests/src/Functional/NodeTest.php, line 402

Class

NodeTest
JSON:API integration test for the "Node" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function assertNormalizedFieldsAreCached($field_names) {
  $cache = \Drupal::service('render_cache')
    ->get([
    '#cache' => [
      'keys' => [
        'node--camelids',
        $this->entity
          ->uuid(),
      ],
      'bin' => 'jsonapi_normalizations',
    ],
  ]);
  $cached_fields = $cache['#data']['fields'];
  $this
    ->assertCount(count($field_names), $cached_fields);
  array_walk($field_names, function ($field_name) use ($cached_fields) {
    $this
      ->assertInstanceOf(CacheableNormalization::class, $cached_fields[$field_name]);
  });
}