X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fmedia%2Ftests%2Fsrc%2FFunctional%2FHal%2FMediaHalJsonAnonTest.php;fp=web%2Fcore%2Fmodules%2Fmedia%2Ftests%2Fsrc%2FFunctional%2FHal%2FMediaHalJsonAnonTest.php;h=5b8de2dacb897d3606c3a7b4c1ce73c64900f9fc;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/modules/media/tests/src/Functional/Hal/MediaHalJsonAnonTest.php b/web/core/modules/media/tests/src/Functional/Hal/MediaHalJsonAnonTest.php new file mode 100644 index 000000000..5b8de2dac --- /dev/null +++ b/web/core/modules/media/tests/src/Functional/Hal/MediaHalJsonAnonTest.php @@ -0,0 +1,228 @@ +applyHalFieldNormalization($default_normalization); + + $file = File::load(1); + $thumbnail = File::load(2); + $author = User::load($this->entity->getOwnerId()); + return $normalization + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/media/1?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/media/camelids', + ], + $this->baseUrl . '/rest/relation/media/camelids/field_media_file' => [ + [ + 'href' => $file->url(), + 'lang' => 'en', + ], + ], + $this->baseUrl . '/rest/relation/media/camelids/revision_user' => [ + [ + 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json', + ], + ], + $this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [ + [ + 'href' => $thumbnail->url(), + 'lang' => 'en', + ], + ], + $this->baseUrl . '/rest/relation/media/camelids/uid' => [ + [ + 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json', + 'lang' => 'en', + ], + ], + ], + '_embedded' => [ + $this->baseUrl . '/rest/relation/media/camelids/field_media_file' => [ + [ + '_links' => [ + 'self' => [ + 'href' => $file->url(), + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/file/file', + ], + ], + 'lang' => 'en', + 'uuid' => [ + [ + 'value' => $file->uuid(), + ], + ], + ], + ], + $this->baseUrl . '/rest/relation/media/camelids/revision_user' => [ + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/user/user', + ], + ], + 'uuid' => [ + [ + 'value' => $author->uuid(), + ], + ], + ], + ], + $this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [ + [ + '_links' => [ + 'self' => [ + 'href' => $thumbnail->url(), + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/file/file', + ], + ], + 'lang' => 'en', + 'uuid' => [ + [ + 'value' => $thumbnail->uuid(), + ], + ], + ], + ], + $this->baseUrl . '/rest/relation/media/camelids/uid' => [ + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/user/user', + ], + ], + 'uuid' => [ + [ + 'value' => $author->uuid(), + ], + ], + 'lang' => 'en', + ], + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedFileEntity() { + $normalization = parent::getExpectedNormalizedFileEntity(); + + $owner = static::$auth ? $this->account : User::load(0); + + // Cannot use applyHalFieldNormalization() as it uses the $entity property + // from the test class, which in the case of file upload tests, is the + // parent entity test entity for the file that's created. + + // The HAL normalization adds entity reference fields to '_links' and + // '_embedded'. + unset($normalization['uid']); + + return $normalization + [ + '_links' => [ + 'self' => [ + // @todo This can use a proper link once + // https://www.drupal.org/project/drupal/issues/2907402 is complete. + // This link matches what is generated from from File::url(), a + // resource URL is currently not available. + 'href' => file_create_url($normalization['uri'][0]['value']), + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/file/file', + ], + $this->baseUrl . '/rest/relation/file/file/uid' => [ + ['href' => $this->baseUrl . '/user/' . $owner->id() . '?_format=hal_json'], + ], + ], + '_embedded' => [ + $this->baseUrl . '/rest/relation/file/file/uid' => [ + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/user/' . $owner->id() . '?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/user/user', + ], + ], + 'uuid' => [ + [ + 'value' => $owner->uuid(), + ], + ], + ], + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + return parent::getNormalizedPostEntity() + [ + '_links' => [ + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/media/camelids', + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedCacheTags() { + return Cache::mergeTags(parent::getExpectedCacheTags(), ['config:hal.settings']); + } + +}