afa9465f53e7205b43b8820afbc846e24ed8d3ac
[yaffs-website] / web / core / modules / hal / tests / src / Functional / EntityResource / Media / MediaHalJsonAnonTest.php
1 <?php
2
3 namespace Drupal\Tests\hal\Functional\EntityResource\Media;
4
5 use Drupal\file\Entity\File;
6 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
7 use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
8 use Drupal\Tests\rest\Functional\EntityResource\Media\MediaResourceTestBase;
9 use Drupal\user\Entity\User;
10
11 /**
12  * @group hal
13  */
14 class MediaHalJsonAnonTest extends MediaResourceTestBase {
15
16   use HalEntityNormalizationTrait;
17   use AnonResourceTestTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = ['hal'];
23
24   /**
25    * {@inheritdoc}
26    */
27   protected static $format = 'hal_json';
28
29   /**
30    * {@inheritdoc}
31    */
32   protected static $mimeType = 'application/hal+json';
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function getExpectedNormalizedEntity() {
38     $default_normalization = parent::getExpectedNormalizedEntity();
39
40     $normalization = $this->applyHalFieldNormalization($default_normalization);
41
42     $file = File::load(1);
43     $thumbnail = File::load(2);
44     $author = User::load($this->entity->getOwnerId());
45     return $normalization + [
46       '_links' => [
47         'self' => [
48           'href' => $this->baseUrl . '/media/1?_format=hal_json',
49         ],
50         'type' => [
51           'href' => $this->baseUrl . '/rest/type/media/camelids',
52         ],
53         $this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [
54           [
55             'href' => $file->url(),
56             'lang' => 'en',
57           ],
58         ],
59         $this->baseUrl . '/rest/relation/media/camelids/revision_user' => [
60           [
61             'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
62           ],
63         ],
64         $this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [
65           [
66             'href' => $thumbnail->url(),
67             'lang' => 'en',
68           ],
69         ],
70         $this->baseUrl . '/rest/relation/media/camelids/uid' => [
71           [
72             'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
73             'lang' => 'en',
74           ],
75         ],
76       ],
77       '_embedded' => [
78         $this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [
79           [
80             '_links' => [
81               'self' => [
82                 'href' => $file->url(),
83               ],
84               'type' => [
85                 'href' => $this->baseUrl . '/rest/type/file/file',
86               ],
87             ],
88             'lang' => 'en',
89             'uri' => [
90               [
91                 'value' => $file->url(),
92               ],
93             ],
94             'uuid' => [
95               [
96                 'value' => $file->uuid(),
97               ],
98             ],
99           ],
100         ],
101         $this->baseUrl . '/rest/relation/media/camelids/revision_user' => [
102           [
103             '_links' => [
104               'self' => [
105                 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
106               ],
107               'type' => [
108                 'href' => $this->baseUrl . '/rest/type/user/user',
109               ],
110             ],
111             'uuid' => [
112               [
113                 'value' => $author->uuid(),
114               ],
115             ],
116           ],
117         ],
118         $this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [
119           [
120             '_links' => [
121               'self' => [
122                 'href' => $thumbnail->url(),
123               ],
124               'type' => [
125                 'href' => $this->baseUrl . '/rest/type/file/file',
126               ],
127             ],
128             'lang' => 'en',
129             'uri' => [
130               [
131                 'value' => $thumbnail->url(),
132               ],
133             ],
134             'uuid' => [
135               [
136                 'value' => $thumbnail->uuid(),
137               ],
138             ],
139           ],
140         ],
141         $this->baseUrl . '/rest/relation/media/camelids/uid' => [
142           [
143             '_links' => [
144               'self' => [
145                 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
146               ],
147               'type' => [
148                 'href' => $this->baseUrl . '/rest/type/user/user',
149               ],
150             ],
151             'uuid' => [
152               [
153                 'value' => $author->uuid(),
154               ],
155             ],
156             'lang' => 'en',
157           ],
158         ],
159       ],
160     ];
161   }
162
163   /**
164    * {@inheritdoc}
165    */
166   protected function getNormalizedPostEntity() {
167     return parent::getNormalizedPostEntity() + [
168       '_links' => [
169         'type' => [
170           'href' => $this->baseUrl . '/rest/type/media/camelids',
171         ],
172       ],
173     ];
174   }
175
176 }