More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / modules / hal / tests / src / Functional / EntityResource / EntityTest / EntityTestHalJsonInternalPropertyNormalizerTest.php
1 <?php
2
3 namespace Drupal\Tests\hal\Functional\EntityResource\EntityTest;
4
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;
10
11 /**
12  * Test that internal properties are not exposed in the 'hal_json' format.
13  *
14  * @group hal
15  */
16 class EntityTestHalJsonInternalPropertyNormalizerTest extends EntityTestHalJsonAnonTest {
17
18   use AnonResourceTestTrait, HalEntityNormalizationTrait;
19
20   /**
21    * {@inheritdoc}
22    */
23   public static $modules = ['hal'];
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function getExpectedNormalizedEntity() {
29     $default_normalization = parent::getExpectedNormalizedEntity();
30
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
34     // property.
35     // @see \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions
36     $normalization['field_test_internal'] = [
37       [
38         'value' => 'This value shall not be internal!',
39         'non_internal_value' => 'Computed! This value shall not be internal!',
40       ],
41     ];
42     return $normalization;
43   }
44
45   /**
46    * {@inheritdoc}
47    */
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',
54         'cardinality' => 1,
55         'translatable' => FALSE,
56       ])->save();
57       FieldConfig::create([
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',
62       ])->save();
63     }
64
65     $entity = parent::createEntity();
66     $entity->field_test_internal = [
67       'value' => 'This value shall not be internal!',
68     ];
69     $entity->save();
70     return $entity;
71   }
72
73   /**
74    * {@inheritdoc}
75    */
76   protected function getNormalizedPostEntity() {
77     return parent::getNormalizedPostEntity() + [
78       'field_test_internal' => [
79         [
80           'value' => 'This value shall not be internal!',
81         ],
82       ],
83     ];
84   }
85
86   /**
87    * {@inheritdoc}
88    */
89   protected function getExpectedCacheContexts() {
90     return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['request_format']);
91   }
92
93   /**
94    * {@inheritdoc}
95    */
96   protected function getExpectedCacheTags() {
97     return Cache::mergeTags(parent::getExpectedCacheTags(), ['you_are_it', 'no_tag_backs']);
98   }
99
100 }