You are here

protected function NodeTest::assertNormalizedFieldsAreCached in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::assertNormalizedFieldsAreCached()
  2. 9 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.

@internal

Parameters

string[] $field_names: The field names.

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Functional

Code

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