3 namespace Drupal\Tests\entity_test\Functional\Rest;
5 use Drupal\Core\Cache\Cache;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\field\Entity\FieldStorageConfig;
8 use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
11 * Test that internal properties are not exposed in the 'json' format.
15 class EntityTestJsonInternalPropertyNormalizerTest extends EntityTestResourceTestBase {
17 use AnonResourceTestTrait;
22 protected static $format = 'json';
27 protected static $mimeType = 'application/json';
32 protected function getExpectedNormalizedEntity() {
33 $expected = parent::getExpectedNormalizedEntity();
34 // The 'internal_value' property in test field type is not exposed in the
35 // normalization because setInternal(FALSE) was not called for this
37 // @see \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions
38 $expected['field_test_internal'] = [
40 'value' => 'This value shall not be internal!',
41 'non_internal_value' => 'Computed! This value shall not be internal!',
50 protected function createEntity() {
51 if (!FieldStorageConfig::loadByName('entity_test', 'field_test_internal')) {
52 FieldStorageConfig::create([
53 'entity_type' => 'entity_test',
54 'field_name' => 'field_test_internal',
55 'type' => 'internal_property_test',
57 'translatable' => FALSE,
60 'entity_type' => 'entity_test',
61 'field_name' => 'field_test_internal',
62 'bundle' => 'entity_test',
63 'label' => 'Test field with internal and non-internal properties',
67 $entity = parent::createEntity();
68 $entity->field_test_internal = [
69 'value' => 'This value shall not be internal!',
78 protected function getNormalizedPostEntity() {
79 return parent::getNormalizedPostEntity() + [
80 'field_test_internal' => [
82 'value' => 'This value shall not be internal!',
91 protected function getExpectedCacheContexts() {
92 return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['request_format']);
98 protected function getExpectedCacheTags() {
99 return Cache::mergeTags(parent::getExpectedCacheTags(), ['you_are_it', 'no_tag_backs']);