EntityTestJsonInternalPropertyNormalizerTest.php in Drupal 10
File
core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestJsonInternalPropertyNormalizerTest.php
View source
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Core\Cache\Cache;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
class EntityTestJsonInternalPropertyNormalizerTest extends EntityTestResourceTestBase {
use AnonResourceTestTrait;
protected static $format = 'json';
protected static $mimeType = 'application/json';
protected $defaultTheme = 'stark';
protected function getExpectedNormalizedEntity() {
$expected = parent::getExpectedNormalizedEntity();
$expected['field_test_internal'] = [
[
'value' => 'This value shall not be internal!',
'non_internal_value' => 'Computed! This value shall not be internal!',
],
];
return $expected;
}
protected function createEntity() {
if (!FieldStorageConfig::loadByName('entity_test', 'field_test_internal')) {
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'type' => 'internal_property_test',
'cardinality' => 1,
'translatable' => FALSE,
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'bundle' => 'entity_test',
'label' => 'Test field with internal and non-internal properties',
])
->save();
}
$entity = parent::createEntity();
$entity->field_test_internal = [
'value' => 'This value shall not be internal!',
];
$entity
->save();
return $entity;
}
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'field_test_internal' => [
[
'value' => 'This value shall not be internal!',
],
],
];
}
protected function getExpectedCacheContexts() {
return Cache::mergeContexts(parent::getExpectedCacheContexts(), [
'request_format',
]);
}
protected function getExpectedCacheTags() {
return Cache::mergeTags(parent::getExpectedCacheTags(), [
'you_are_it',
'no_tag_backs',
]);
}
}