function NodeTest::assertNormalizedFieldsAreCached

Same name 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()
  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.

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

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