3 namespace Drupal\Tests\hal\Functional\EntityResource\EntityTest;
5 use Drupal\Core\Cache\Cache;
6 use Drupal\field\Entity\FieldConfig;
7 use Drupal\field\Entity\FieldStorageConfig;
8 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
9 use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
12 * Test that internal properties are not exposed in the 'hal_json' format.
16 class EntityTestHalJsonInternalPropertyNormalizerTest extends EntityTestHalJsonAnonTest {
18 use AnonResourceTestTrait, HalEntityNormalizationTrait;
23 public static $modules = ['hal'];
28 protected function getExpectedNormalizedEntity() {
29 $default_normalization = parent::getExpectedNormalizedEntity();
31 $normalization = $this->applyHalFieldNormalization($default_normalization);
32 // The 'internal_value' property in test field type will not be returned in
33 // normalization because setInternal(FALSE) was not called for this
35 // @see \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions
36 $normalization['field_test_internal'] = [
38 'value' => 'This value shall not be internal!',
39 'non_internal_value' => 'Computed! This value shall not be internal!',
42 return $normalization;
48 protected function createEntity() {
49 if (!FieldStorageConfig::loadByName('entity_test', 'field_test_internal')) {
50 FieldStorageConfig::create([
51 'entity_type' => 'entity_test',
52 'field_name' => 'field_test_internal',
53 'type' => 'internal_property_test',
55 'translatable' => FALSE,
58 'entity_type' => 'entity_test',
59 'field_name' => 'field_test_internal',
60 'bundle' => 'entity_test',
61 'label' => 'Test field with internal and non-internal properties',
65 $entity = parent::createEntity();
66 $entity->field_test_internal = [
67 'value' => 'This value shall not be internal!',
76 protected function getNormalizedPostEntity() {
77 return parent::getNormalizedPostEntity() + [
78 'field_test_internal' => [
80 'value' => 'This value shall not be internal!',
89 protected function getExpectedCacheContexts() {
90 return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['request_format']);
96 protected function getExpectedCacheTags() {
97 return Cache::mergeTags(parent::getExpectedCacheTags(), ['you_are_it', 'no_tag_backs']);