3 namespace Drupal\Tests\hal\Functional\EntityResource\Media;
5 use Drupal\file\Entity\File;
6 use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
7 use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
8 use Drupal\Tests\rest\Functional\EntityResource\Media\MediaResourceTestBase;
9 use Drupal\user\Entity\User;
14 class MediaHalJsonAnonTest extends MediaResourceTestBase {
16 use HalEntityNormalizationTrait;
17 use AnonResourceTestTrait;
22 public static $modules = ['hal'];
27 protected static $format = 'hal_json';
32 protected static $mimeType = 'application/hal+json';
37 protected function getExpectedNormalizedEntity() {
38 $default_normalization = parent::getExpectedNormalizedEntity();
40 $normalization = $this->applyHalFieldNormalization($default_normalization);
42 $file = File::load(1);
43 $thumbnail = File::load(2);
44 $author = User::load($this->entity->getOwnerId());
45 return $normalization + [
48 'href' => $this->baseUrl . '/media/1?_format=hal_json',
51 'href' => $this->baseUrl . '/rest/type/media/camelids',
53 $this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [
55 'href' => $file->url(),
59 $this->baseUrl . '/rest/relation/media/camelids/revision_user' => [
61 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
64 $this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [
66 'href' => $thumbnail->url(),
70 $this->baseUrl . '/rest/relation/media/camelids/uid' => [
72 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
78 $this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [
82 'href' => $file->url(),
85 'href' => $this->baseUrl . '/rest/type/file/file',
91 'value' => $file->url(),
96 'value' => $file->uuid(),
101 $this->baseUrl . '/rest/relation/media/camelids/revision_user' => [
105 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
108 'href' => $this->baseUrl . '/rest/type/user/user',
113 'value' => $author->uuid(),
118 $this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [
122 'href' => $thumbnail->url(),
125 'href' => $this->baseUrl . '/rest/type/file/file',
131 'value' => $thumbnail->url(),
136 'value' => $thumbnail->uuid(),
141 $this->baseUrl . '/rest/relation/media/camelids/uid' => [
145 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json',
148 'href' => $this->baseUrl . '/rest/type/user/user',
153 'value' => $author->uuid(),
166 protected function getNormalizedPostEntity() {
167 return parent::getNormalizedPostEntity() + [
170 'href' => $this->baseUrl . '/rest/type/media/camelids',