More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / modules / hal / tests / src / Functional / EntityResource / Comment / CommentHalJsonTestBase.php
1 <?php
2
3 namespace Drupal\Tests\hal\Functional\EntityResource\Comment;
4
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
7 use Drupal\Tests\rest\Functional\EntityResource\Comment\CommentResourceTestBase;
8 use Drupal\user\Entity\User;
9
10 abstract class CommentHalJsonTestBase extends CommentResourceTestBase {
11
12   use HalEntityNormalizationTrait;
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['hal'];
18
19   /**
20    * {@inheritdoc}
21    */
22   protected static $format = 'hal_json';
23
24   /**
25    * {@inheritdoc}
26    */
27   protected static $mimeType = 'application/hal+json';
28
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function getExpectedNormalizedEntity() {
34     $default_normalization = parent::getExpectedNormalizedEntity();
35
36     $normalization = $this->applyHalFieldNormalization($default_normalization);
37
38     // Because \Drupal\comment\Entity\Comment::getOwner() generates an in-memory
39     // User entity without a UUID, we cannot use it.
40     $author = User::load($this->entity->getOwnerId());
41     $commented_entity = EntityTest::load(1);
42     return $normalization + [
43       '_links' => [
44         'self' => [
45           'href' => $this->baseUrl . '/comment/1?_format=hal_json',
46         ],
47         'type' => [
48           'href' => $this->baseUrl . '/rest/type/comment/comment',
49         ],
50         $this->baseUrl . '/rest/relation/comment/comment/entity_id' => [
51           [
52             'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
53           ],
54         ],
55         $this->baseUrl . '/rest/relation/comment/comment/uid' => [
56           [
57             'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
58             'lang' => 'en',
59           ],
60         ],
61       ],
62       '_embedded' => [
63         $this->baseUrl . '/rest/relation/comment/comment/entity_id' => [
64           [
65             '_links' => [
66               'self' => [
67                 'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
68               ],
69               'type' => [
70                 'href' => $this->baseUrl . '/rest/type/entity_test/bar',
71               ],
72             ],
73             'uuid' => [
74               ['value' => $commented_entity->uuid()]
75             ],
76           ],
77         ],
78         $this->baseUrl . '/rest/relation/comment/comment/uid' => [
79           [
80             '_links' => [
81               'self' => [
82                 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
83               ],
84               'type' => [
85                 'href' => $this->baseUrl . '/rest/type/user/user',
86               ],
87             ],
88             'uuid' => [
89               ['value' => $author->uuid()]
90             ],
91             'lang' => 'en',
92           ],
93         ],
94       ],
95     ];
96   }
97
98   /**
99    * {@inheritdoc}
100    */
101   protected function getNormalizedPostEntity() {
102     return parent::getNormalizedPostEntity() + [
103       '_links' => [
104         'type' => [
105           'href' => $this->baseUrl . '/rest/type/comment/comment',
106         ],
107       ],
108     ];
109   }
110
111 }