c786b7b181a4f5cd744166356070ae49f65fc5a7
[yaffs-website] / web / core / modules / aggregator / tests / src / Functional / Hal / ItemHalJsonTestBase.php
1 <?php
2
3 namespace Drupal\Tests\aggregator\Functional\Hal;
4
5 use Drupal\aggregator\Entity\Feed;
6 use Drupal\Tests\aggregator\Functional\Rest\ItemResourceTestBase;
7 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
8 use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
9
10 /**
11  * ResourceTestBase for Item entity.
12  */
13 abstract class ItemHalJsonTestBase extends ItemResourceTestBase {
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     $normalization = $this->applyHalFieldNormalization($default_normalization);
39     $feed = Feed::load($this->entity->getFeedId());
40
41     return $normalization + [
42       '_embedded' => [
43         $this->baseUrl . '/rest/relation/aggregator_item/aggregator_item/fid' => [
44           [
45             '_links' => [
46               'self' => [
47                 'href' => $this->baseUrl . '/aggregator/sources/1?_format=hal_json',
48               ],
49               'type' => [
50                 'href' => $this->baseUrl . '/rest/type/aggregator_feed/aggregator_feed',
51               ],
52             ],
53             'uuid' => [
54               [
55                 'value' => $feed->uuid(),
56               ],
57             ],
58           ],
59         ],
60       ],
61       '_links' => [
62         'self' => [
63           'href' => '',
64         ],
65         'type' => [
66           'href' => $this->baseUrl . '/rest/type/aggregator_item/aggregator_item',
67         ],
68         $this->baseUrl . '/rest/relation/aggregator_item/aggregator_item/fid' => [
69           [
70             'href' => $this->baseUrl . '/aggregator/sources/' . $feed->id() . '?_format=hal_json',
71           ],
72         ],
73       ],
74     ];
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   protected function getNormalizedPostEntity() {
81     return parent::getNormalizedPostEntity() + [
82       '_links' => [
83         'type' => [
84           'href' => $this->baseUrl . '/rest/type/aggregator_item/aggregator_item',
85         ],
86       ],
87     ];
88   }
89
90   /**
91    * {@inheritdoc}
92    */
93   protected function getExpectedCacheContexts() {
94     return [
95       'url.site',
96       'user.permissions',
97     ];
98   }
99
100 }