public function testCacheableComputedField() { $context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY
] =
new CacheableMetadata();
$entity = EntityTestComputedField::
create();
$normalized =
$this->serializer->
normalize($entity, NULL,
$context);
$this->
assertEquals('computed test cacheable string field',
$normalized['computed_test_cacheable_string_field'
][0
]['value'
]);
$this->
assertInstanceOf(CacheableDependencyInterface::
class,
$context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY
]);
// See \Drupal\entity_test\Plugin\Field\ComputedTestCacheableStringItemList::computeValue().
$this->
assertEquals($context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY
]->
getCacheContexts(),
['url.query_args:computed_test_cacheable_string_field'
]);
$this->
assertEquals($context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY
]->
getCacheTags(),
['field:computed_test_cacheable_string_field'
]);
$this->
assertEquals($context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY
]->
getCacheMaxAge(), 800
);
}}