Version 1
[yaffs-website] / web / core / modules / hal / tests / src / Functional / EntityResource / Node / NodeHalJsonAnonTest.php
1 <?php
2
3 namespace Drupal\Tests\hal\Functional\EntityResource\Node;
4
5 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
6 use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
7 use Drupal\Tests\rest\Functional\EntityResource\Node\NodeResourceTestBase;
8 use Drupal\user\Entity\User;
9
10 /**
11  * @group hal
12  */
13 class NodeHalJsonAnonTest extends NodeResourceTestBase {
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 static $patchProtectedFieldNames = [
37     'created',
38     'changed',
39     'promote',
40     'sticky',
41     'revision_timestamp',
42     'revision_uid',
43   ];
44
45   /**
46    * {@inheritdoc}
47    */
48   protected function getExpectedNormalizedEntity() {
49     $default_normalization = parent::getExpectedNormalizedEntity();
50
51     $normalization = $this->applyHalFieldNormalization($default_normalization);
52
53     $author = User::load($this->entity->getOwnerId());
54     return  $normalization + [
55       '_links' => [
56         'self' => [
57           'href' => $this->baseUrl . '/node/1?_format=hal_json',
58         ],
59         'type' => [
60           'href' => $this->baseUrl . '/rest/type/node/camelids',
61         ],
62         $this->baseUrl . '/rest/relation/node/camelids/uid' => [
63           [
64             'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
65             'lang' => 'en',
66           ],
67         ],
68         $this->baseUrl . '/rest/relation/node/camelids/revision_uid' => [
69           [
70             'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
71           ],
72         ],
73       ],
74       '_embedded' => [
75         $this->baseUrl . '/rest/relation/node/camelids/uid' => [
76           [
77             '_links' => [
78               'self' => [
79                 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
80               ],
81               'type' => [
82                 'href' => $this->baseUrl . '/rest/type/user/user',
83               ],
84             ],
85             'uuid' => [
86               ['value' => $author->uuid()]
87             ],
88             'lang' => 'en',
89           ],
90         ],
91         $this->baseUrl . '/rest/relation/node/camelids/revision_uid' => [
92           [
93             '_links' => [
94               'self' => [
95                 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
96               ],
97               'type' => [
98                 'href' => $this->baseUrl . '/rest/type/user/user',
99               ],
100             ],
101             'uuid' => [
102               ['value' => $author->uuid()]
103             ],
104           ],
105         ],
106       ],
107     ];
108   }
109
110   /**
111    * {@inheritdoc}
112    */
113   protected function getNormalizedPostEntity() {
114     return parent::getNormalizedPostEntity() + [
115       '_links' => [
116         'type' => [
117           'href' => $this->baseUrl . '/rest/type/node/camelids',
118         ],
119       ],
120     ];
121   }
122
123 }