function NodeTest::assertNormalizedFieldsAreCached

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

@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 405

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('variation_cache.jsonapi_normalizations')->get([
        'node--camelids',
        $this->entity
            ->uuid(),
        $this->entity
            ->language()
            ->getId(),
    ], new CacheableMetadata());
    $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.