function NodeTest::assertNormalizedFieldsAreCached

Same name in other branches
  1. 8.9.x 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()
  3. 11.x 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.

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 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]);
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.