Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / tests / src / Functional / Hal / EntityTestHalJsonAnonTest.php
1 <?php
2
3 namespace Drupal\Tests\entity_test\Functional\Hal;
4
5 use Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase;
6 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
7 use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
8 use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait;
9 use Drupal\user\Entity\User;
10
11 /**
12  * @group hal
13  */
14 class EntityTestHalJsonAnonTest extends EntityTestResourceTestBase {
15
16   use HalEntityNormalizationTrait;
17   use AnonResourceTestTrait;
18   use FormatSpecificGetBcRouteTestTrait;
19
20   /**
21    * {@inheritdoc}
22    */
23   public static $modules = ['hal'];
24
25   /**
26    * {@inheritdoc}
27    */
28   protected static $format = 'hal_json';
29
30   /**
31    * {@inheritdoc}
32    */
33   protected static $mimeType = 'application/hal+json';
34
35   /**
36    * {@inheritdoc}
37    */
38   protected function getExpectedNormalizedEntity() {
39     $default_normalization = parent::getExpectedNormalizedEntity();
40
41     $normalization = $this->applyHalFieldNormalization($default_normalization);
42
43     $author = User::load(0);
44     return $normalization + [
45       '_links' => [
46         'self' => [
47           'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
48         ],
49         'type' => [
50           'href' => $this->baseUrl . '/rest/type/entity_test/entity_test',
51         ],
52         $this->baseUrl . '/rest/relation/entity_test/entity_test/user_id' => [
53           [
54             'href' => $this->baseUrl . '/user/0?_format=hal_json',
55             'lang' => 'en',
56           ],
57         ],
58       ],
59       '_embedded' => [
60         $this->baseUrl . '/rest/relation/entity_test/entity_test/user_id' => [
61           [
62             '_links' => [
63               'self' => [
64                 'href' => $this->baseUrl . '/user/0?_format=hal_json',
65               ],
66               'type' => [
67                 'href' => $this->baseUrl . '/rest/type/user/user',
68               ],
69             ],
70             'uuid' => [
71               ['value' => $author->uuid()],
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/entity_test',
88         ],
89       ],
90     ];
91   }
92
93 }