diff --git a/core/modules/hal/tests/src/Functional/EntityResource/FileTest/FileTestHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/FileTest/FileTestHalJsonAnonTest.php new file mode 100644 index 0000000000..c99bd326a2 --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/FileTest/FileTestHalJsonAnonTest.php @@ -0,0 +1,65 @@ +applyHalFieldNormalization($default_normalization); + + return $normalization + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/entity/file/1?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/file', + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + return parent::getNormalizedPostEntity() + [ + '_links' => [ + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/file', + ], + ], + ]; + } + +} diff --git a/core/modules/hal/tests/src/Functional/EntityResource/FileTest/FileTestHalJsonBasicAuthTest.php b/core/modules/hal/tests/src/Functional/EntityResource/FileTest/FileTestHalJsonBasicAuthTest.php new file mode 100644 index 0000000000..376cf8dcaa --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/FileTest/FileTestHalJsonBasicAuthTest.php @@ -0,0 +1,24 @@ +grantPermissionsToTestedRole(['access content', 'administer content']); + break; + case 'POST': + case 'PATCH': + case 'DELETE': + $this->grantPermissionsToTestedRole(['administer content']); + break; + } + } + + /** + * {@inheritdoc} + */ + protected function createEntity() { + $file = File::create([ + 'uid' => 1, + 'filename' => 'drupal.txt', + 'uri' => 'public://drupal.txt', + 'filemime' => 'text/plain', + 'status' => FILE_STATUS_PERMANENT, + ]); + file_put_contents($file->getFileUri(), 'hello world'); + + // Save it, inserting a new record. + $file->save(); + + return $file; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedEntity() { + return [ + 'fid' => [ + ['value' => 1], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + return [ + 'fid' => [ + ['value' => 1], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { + return parent::getExpectedUnauthorizedAccessMessage($method); + } + + switch ($method) { + case 'GET': + return "The 'access content' permission is required."; + case 'POST': + return "The 'administer content' permission is required."; + case 'PATCH': + return "The following permissions are required: 'administer content'."; + case 'DELETE': + return "The following permissions are required: 'administer content'."; + default: + return parent::getExpectedUnauthorizedAccessMessage($method); + } + } + +}