f95ea5ce06bf0da4f56adebcea47e94b33e895a5
[yaffs-website] / web / core / modules / hal / tests / src / Functional / EntityResource / EntityTestLabel / EntityTestLabelHalJsonAnonTest.php
1 <?php
2
3 namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestLabel;
4
5 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
6 use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel\EntityTestLabelResourceTestBase;
8 use Drupal\user\Entity\User;
9
10 /**
11  * @group hal
12  */
13 class EntityTestLabelHalJsonAnonTest extends EntityTestLabelResourceTestBase {
14
15   use HalEntityNormalizationTrait;
16   use AnonResourceTestTrait;
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = ['hal'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected static $format = 'hal_json';
27
28   /**
29    * {@inheritdoc}
30    */
31   protected static $mimeType = 'application/hal+json';
32
33   /**
34    * {@inheritdoc}
35    */
36   protected function getExpectedNormalizedEntity() {
37     $default_normalization = parent::getExpectedNormalizedEntity();
38
39     $normalization = $this->applyHalFieldNormalization($default_normalization);
40
41     $author = User::load(0);
42     return $normalization + [
43       '_links' => [
44         'self' => [
45           'href' => '',
46         ],
47         'type' => [
48           'href' => $this->baseUrl . '/rest/type/entity_test_label/entity_test_label',
49         ],
50         $this->baseUrl . '/rest/relation/entity_test_label/entity_test_label/user_id' => [
51           [
52             'href' => $this->baseUrl . '/user/0?_format=hal_json',
53             'lang' => 'en',
54           ],
55         ],
56       ],
57       '_embedded' => [
58         $this->baseUrl . '/rest/relation/entity_test_label/entity_test_label/user_id' => [
59           [
60             '_links' => [
61               'self' => [
62                 'href' => $this->baseUrl . '/user/0?_format=hal_json',
63               ],
64               'type' => [
65                 'href' => $this->baseUrl . '/rest/type/user/user',
66               ],
67             ],
68             'uuid' => [
69               [
70                 'value' => $author->uuid(),
71               ],
72             ],
73             'lang' => 'en',
74           ],
75         ],
76       ],
77     ];
78   }
79
80   /**
81    * {@inheritdoc}
82    */
83   protected function getNormalizedPostEntity() {
84     return parent::getNormalizedPostEntity() + [
85       '_links' => [
86         'type' => [
87           'href' => $this->baseUrl . '/rest/type/entity_test_label/entity_test_label',
88         ],
89       ],
90     ];
91   }
92
93   /**
94    * {@inheritdoc}
95    */
96   protected function getExpectedCacheContexts() {
97     return [
98       'url.site',
99       'user.permissions',
100     ];
101   }
102
103 }