Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / file / tests / src / Functional / Hal / FileUploadHalJsonTestBase.php
1 <?php
2
3 namespace Drupal\Tests\file\Functional\Hal;
4
5 use Drupal\Tests\rest\Functional\FileUploadResourceTestBase;
6 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
7
8 /**
9  * Tests binary data file upload route for HAL JSON.
10  */
11 abstract class FileUploadHalJsonTestBase extends FileUploadResourceTestBase {
12
13   use HalEntityNormalizationTrait;
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['hal'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected static $format = 'hal_json';
24
25   /**
26    * {@inheritdoc}
27    */
28   protected static $mimeType = 'application/hal+json';
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function getExpectedNormalizedEntity($fid = 1, $expected_filename = 'example.txt', $expected_as_filename = FALSE) {
34     $normalization = parent::getExpectedNormalizedEntity($fid, $expected_filename, $expected_as_filename);
35
36     // Cannot use applyHalFieldNormalization() as it uses the $entity property
37     // from the test class, which in the case of file upload tests, is the
38     // parent entity test entity for the file that's created.
39
40     // The HAL normalization adds entity reference fields to '_links' and
41     // '_embedded'.
42     unset($normalization['uid']);
43
44     return $normalization + [
45       '_links' => [
46         'self' => [
47           // @todo This can use a proper link once
48           // https://www.drupal.org/project/drupal/issues/2907402 is complete.
49           // This link matches what is generated from from File::url(), a
50           // resource URL is currently not available.
51           'href' => file_create_url($normalization['uri'][0]['value']),
52         ],
53         'type' => [
54           'href' => $this->baseUrl . '/rest/type/file/file',
55         ],
56         $this->baseUrl . '/rest/relation/file/file/uid' => [
57           ['href' => $this->baseUrl . '/user/' . $this->account->id() . '?_format=hal_json'],
58         ],
59       ],
60       '_embedded' => [
61         $this->baseUrl . '/rest/relation/file/file/uid' => [
62           [
63             '_links' => [
64               'self' => [
65                 'href' => $this->baseUrl . '/user/' . $this->account->id() . '?_format=hal_json',
66               ],
67               'type' => [
68                 'href' => $this->baseUrl . '/rest/type/user/user',
69               ],
70             ],
71             'uuid' => [
72               [
73                 'value' => $this->account->uuid(),
74               ],
75             ],
76           ],
77         ],
78       ],
79     ];
80   }
81
82   /**
83    * {@inheritdoc}
84    *
85    * @see \Drupal\Tests\hal\Functional\EntityResource\EntityTest\EntityTestHalJsonAnonTest::getNormalizedPostEntity()
86    */
87   protected function getNormalizedPostEntity() {
88     return parent::getNormalizedPostEntity() + [
89       '_links' => [
90         'type' => [
91           'href' => $this->baseUrl . '/rest/type/entity_test/entity_test',
92         ],
93       ],
94     ];
95   }
96
97 }