diff --git a/core/modules/hal/tests/src/Functional/EntityResource/Media/MediaHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/Media/MediaHalJsonAnonTest.php index 2716a95..afa9465 100644 --- a/core/modules/hal/tests/src/Functional/EntityResource/Media/MediaHalJsonAnonTest.php +++ b/core/modules/hal/tests/src/Functional/EntityResource/Media/MediaHalJsonAnonTest.php @@ -42,7 +42,7 @@ protected function getExpectedNormalizedEntity() { $file = File::load(1); $thumbnail = File::load(2); $author = User::load($this->entity->getOwnerId()); - return $normalization + [ + return $normalization + [ '_links' => [ 'self' => [ 'href' => $this->baseUrl . '/media/1?_format=hal_json', @@ -50,7 +50,7 @@ protected function getExpectedNormalizedEntity() { 'type' => [ 'href' => $this->baseUrl . '/rest/type/media/camelids', ], - $this->baseUrl .'/rest/relation/media/camelids/field_media_file_1' => [ + $this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [ [ 'href' => $file->url(), 'lang' => 'en', @@ -61,7 +61,7 @@ protected function getExpectedNormalizedEntity() { 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json', ], ], - $this->baseUrl .'/rest/relation/media/camelids/thumbnail' => [ + $this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [ [ 'href' => $thumbnail->url(), 'lang' => 'en', @@ -75,7 +75,7 @@ protected function getExpectedNormalizedEntity() { ], ], '_embedded' => [ - $this->baseUrl .'/rest/relation/media/camelids/field_media_file_1' => [ + $this->baseUrl . '/rest/relation/media/camelids/field_media_file_1' => [ [ '_links' => [ 'self' => [ @@ -92,9 +92,10 @@ protected function getExpectedNormalizedEntity() { ], ], 'uuid' => [ - ['value' => $file->uuid()] + [ + 'value' => $file->uuid(), + ], ], - ], ], $this->baseUrl . '/rest/relation/media/camelids/revision_user' => [ @@ -108,11 +109,13 @@ protected function getExpectedNormalizedEntity() { ], ], 'uuid' => [ - ['value' => $author->uuid()] + [ + 'value' => $author->uuid(), + ], ], ], ], - $this->baseUrl .'/rest/relation/media/camelids/thumbnail' => [ + $this->baseUrl . '/rest/relation/media/camelids/thumbnail' => [ [ '_links' => [ 'self' => [ @@ -129,9 +132,10 @@ protected function getExpectedNormalizedEntity() { ], ], 'uuid' => [ - ['value' => $thumbnail->uuid()] + [ + 'value' => $thumbnail->uuid(), + ], ], - ], ], $this->baseUrl . '/rest/relation/media/camelids/uid' => [ @@ -145,7 +149,9 @@ protected function getExpectedNormalizedEntity() { ], ], 'uuid' => [ - ['value' => $author->uuid()] + [ + 'value' => $author->uuid(), + ], ], 'lang' => 'en', ], diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php index 7ea80e5..ba1c64d 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php @@ -43,12 +43,15 @@ protected function setUpAuthorization($method) { case 'GET': $this->grantPermissionsToTestedRole(['view media']); break; + case 'POST': $this->grantPermissionsToTestedRole(['create media']); break; + case 'PATCH': $this->grantPermissionsToTestedRole(['update any media']); break; + case 'DELETE': $this->grantPermissionsToTestedRole(['delete any media']); break; @@ -69,25 +72,17 @@ protected function createEntity() { ]); $media_type->save(); // Create the source field. - $source = $media_type->getSource(); - $source_field = $source->getSourceFieldDefinition($media_type); - if (!$source_field) { - $source_field = $source->createSourceField($media_type); - /** @var \Drupal\field\FieldStorageConfigInterface $storage */ - $storage = $source_field->getFieldStorageDefinition(); - $storage->save(); - $source_field->save(); - - $media_type - ->set('source_configuration', [ - 'source_field' => $source_field->getName(), - ]) - ->save(); - } + $source_field = $media_type->getSource()->createSourceField($media_type); + $source_field->getFieldStorageDefinition()->save(); + $source_field->save(); + $media_type + ->set('source_configuration', [ + 'source_field' => $source_field->getName(), + ]) + ->save(); } // Create a file to upload. - simpletest_generate_file('llama.txt', 10, 10); $file = File::create([ 'uri' => 'public://llama.txt', ]); @@ -98,7 +93,7 @@ protected function createEntity() { $media = Media::create([ 'bundle' => 'camelids', 'field_media_file_1' => [ - 'target_id' => $file->id() + 'target_id' => $file->id(), ], // @todo use setName() when https://www.drupal.org/node/2897009 lands. 'name' => 'Llama', @@ -106,9 +101,7 @@ protected function createEntity() { $media->setOwnerId(static::$auth ? $this->account->id() : 0) ->setPublished(TRUE) ->setCreatedTime(123456789) - ->setChangedTime(123456789) ->setRevisionUserId(static::$auth ? $this->account->id() : 0) - ->setRevisionCreationTime(123456789) ->save(); return $media; @@ -123,13 +116,19 @@ protected function getExpectedNormalizedEntity() { $author = User::load($this->entity->getOwnerId()); return [ 'mid' => [ - ['value' => 1], + [ + 'value' => 1, + ], ], 'uuid' => [ - ['value' => $this->entity->uuid()], + [ + 'value' => $this->entity->uuid(), + ], ], 'vid' => [ - ['value' => 1], + [ + 'value' => 1, + ], ], 'langcode' => [ [ @@ -156,7 +155,7 @@ protected function getExpectedNormalizedEntity() { 'target_type' => 'file', 'target_uuid' => $file->uuid(), 'url' => $file->url(), - ] + ], ], 'thumbnail' => [ [ @@ -168,7 +167,7 @@ protected function getExpectedNormalizedEntity() { 'target_uuid' => $thumbnail->uuid(), 'title' => 'Llama', 'url' => $thumbnail->url(), - ] + ], ], 'status' => [ [ @@ -238,10 +237,13 @@ protected function getExpectedUnauthorizedAccessMessage($method) { switch ($method) { case 'GET'; return "The 'view media' permission is required and the media item must be published."; + case 'PATCH': return 'You are not authorized to update this media entity of bundle camelids.'; + case 'DELETE': return 'You are not authorized to delete this media entity of bundle camelids.'; + default: return parent::getExpectedUnauthorizedAccessMessage($method); } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/MediaType/MediaTypeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/MediaType/MediaTypeResourceTestBase.php index e9dd127..ac72737 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/MediaType/MediaTypeResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/MediaType/MediaTypeResourceTestBase.php @@ -75,15 +75,4 @@ protected function getNormalizedPostEntity() { // @todo Update in https://www.drupal.org/node/2300677. } - /** - * {@inheritdoc} - */ - protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - - return "The 'administer media types' permission is required."; - } - }