3 namespace Drupal\Tests\file\Functional\Hal;
5 use Drupal\Tests\rest\Functional\FileUploadResourceTestBase;
6 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
9 * Tests binary data file upload route for HAL JSON.
11 abstract class FileUploadHalJsonTestBase extends FileUploadResourceTestBase {
13 use HalEntityNormalizationTrait;
18 public static $modules = ['hal'];
23 protected static $format = 'hal_json';
28 protected static $mimeType = 'application/hal+json';
33 protected function getExpectedNormalizedEntity($fid = 1, $expected_filename = 'example.txt', $expected_as_filename = FALSE) {
34 $normalization = parent::getExpectedNormalizedEntity($fid, $expected_filename, $expected_as_filename);
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.
40 // The HAL normalization adds entity reference fields to '_links' and
42 unset($normalization['uid']);
44 return $normalization + [
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']),
54 'href' => $this->baseUrl . '/rest/type/file/file',
56 $this->baseUrl . '/rest/relation/file/file/uid' => [
57 ['href' => $this->baseUrl . '/user/' . $this->account->id() . '?_format=hal_json'],
61 $this->baseUrl . '/rest/relation/file/file/uid' => [
65 'href' => $this->baseUrl . '/user/' . $this->account->id() . '?_format=hal_json',
68 'href' => $this->baseUrl . '/rest/type/user/user',
73 'value' => $this->account->uuid(),
85 * @see \Drupal\Tests\hal\Functional\EntityResource\EntityTest\EntityTestHalJsonAnonTest::getNormalizedPostEntity()
87 protected function getNormalizedPostEntity() {
88 return parent::getNormalizedPostEntity() + [
91 'href' => $this->baseUrl . '/rest/type/entity_test/entity_test',