summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-03-27 09:30:26 +0100
committerAlex Pott2017-03-27 09:30:26 +0100
commit0edd07b2f9e0eca6d7b775fa8b233ece7c306464 (patch)
treeec509550b7566cd8debfbceaa4825396a84cf11e
parent48261599246bb9369e79ae4ec4b11de6de01e5b8 (diff)
Issue #2853211 by vaplas, Wim Leers, arshadcn: EntityResource::post() incorrectly assumes that every entity type has a canonical URL
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonAnonTest.php103
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonBasicAuthTest.php24
-rw-r--r--core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonCookieTest.php19
-rw-r--r--core/modules/rest/src/Plugin/rest/resource/EntityResource.php8
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php91
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonAnonTest.php24
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonBasicAuthTest.php34
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonCookieTest.php29
-rw-r--r--core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelResourceTestBase.php156
9 files changed, 445 insertions, 43 deletions
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonAnonTest.php
new file mode 100644
index 0000000..f95ea5c
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonAnonTest.php
@@ -0,0 +1,103 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestLabel;
+
+use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
+use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
+use Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel\EntityTestLabelResourceTestBase;
+use Drupal\user\Entity\User;
+
+/**
+ * @group hal
+ */
+class EntityTestLabelHalJsonAnonTest extends EntityTestLabelResourceTestBase {
+
+ use HalEntityNormalizationTrait;
+ use AnonResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['hal'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'hal_json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/hal+json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExpectedNormalizedEntity() {
+ $default_normalization = parent::getExpectedNormalizedEntity();
+
+ $normalization = $this->applyHalFieldNormalization($default_normalization);
+
+ $author = User::load(0);
+ return $normalization + [
+ '_links' => [
+ 'self' => [
+ 'href' => '',
+ ],
+ 'type' => [
+ 'href' => $this->baseUrl . '/rest/type/entity_test_label/entity_test_label',
+ ],
+ $this->baseUrl . '/rest/relation/entity_test_label/entity_test_label/user_id' => [
+ [
+ 'href' => $this->baseUrl . '/user/0?_format=hal_json',
+ 'lang' => 'en',
+ ],
+ ],
+ ],
+ '_embedded' => [
+ $this->baseUrl . '/rest/relation/entity_test_label/entity_test_label/user_id' => [
+ [
+ '_links' => [
+ 'self' => [
+ 'href' => $this->baseUrl . '/user/0?_format=hal_json',
+ ],
+ 'type' => [
+ 'href' => $this->baseUrl . '/rest/type/user/user',
+ ],
+ ],
+ 'uuid' => [
+ [
+ 'value' => $author->uuid(),
+ ],
+ ],
+ 'lang' => 'en',
+ ],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getNormalizedPostEntity() {
+ return parent::getNormalizedPostEntity() + [
+ '_links' => [
+ 'type' => [
+ 'href' => $this->baseUrl . '/rest/type/entity_test_label/entity_test_label',
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExpectedCacheContexts() {
+ return [
+ 'url.site',
+ 'user.permissions',
+ ];
+ }
+
+}
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonBasicAuthTest.php b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonBasicAuthTest.php
new file mode 100644
index 0000000..b3824aa
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonBasicAuthTest.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestLabel;
+
+use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
+
+/**
+ * @group hal
+ */
+class EntityTestLabelHalJsonBasicAuthTest extends EntityTestLabelHalJsonAnonTest {
+
+ use BasicAuthResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['basic_auth'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'basic_auth';
+
+}
diff --git a/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonCookieTest.php b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonCookieTest.php
new file mode 100644
index 0000000..fa74cb3
--- /dev/null
+++ b/core/modules/hal/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelHalJsonCookieTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Drupal\Tests\hal\Functional\EntityResource\EntityTestLabel;
+
+use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
+
+/**
+ * @group hal
+ */
+class EntityTestLabelHalJsonCookieTest extends EntityTestLabelHalJsonAnonTest {
+
+ use CookieResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'cookie';
+
+}
diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
index a4162b5..9b1d15f 100644
--- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -189,8 +189,12 @@ class EntityResource extends ResourceBase implements DependentPluginInterface {
// 201 Created responses return the newly created entity in the response
// body. These responses are not cacheable, so we add no cacheability
// metadata here.
- $url = $entity->urlInfo('canonical', ['absolute' => TRUE])->toString(TRUE);
- return new ModifiedResourceResponse($entity, 201, ['Location' => $url->getGeneratedUrl()]);
+ $headers = [];
+ if (in_array('canonical', $entity->uriRelationships(), TRUE)) {
+ $url = $entity->urlInfo('canonical', ['absolute' => TRUE])->toString(TRUE);
+ $headers['Location'] = $url->getGeneratedUrl();
+ }
+ return new ModifiedResourceResponse($entity, 201, $headers);
}
catch (EntityStorageException $e) {
throw new HttpException(500, 'Internal Server Error', $e);
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
index 713d403..4a8c304 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
@@ -610,15 +610,11 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
$request_options = [];
- // DX: 404 when resource not provisioned, but HTML if canonical route.
+ // DX: 404 when resource not provisioned. HTML response because missing
+ // ?_format query string.
$response = $this->request('POST', $url, $request_options);
- if ($has_canonical_url) {
- $this->assertSame(404, $response->getStatusCode());
- $this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type'));
- }
- else {
- $this->assertResourceErrorResponse(404, 'No route found for "GET ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response);
- }
+ $this->assertSame(404, $response->getStatusCode());
+ $this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type'));
$url->setOption('query', ['_format' => static::$format]);
@@ -634,16 +630,12 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
$url->setOption('query', []);
- // DX: 415 when no Content-Type request header, plain text if canonical URL.
+ // DX: 415 when no Content-Type request header. HTML response because
+ // missing ?_format query string.
$response = $this->request('POST', $url, $request_options);
- if ($has_canonical_url) {
- $this->assertSame(415, $response->getStatusCode());
- $this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type'));
- $this->assertContains(htmlspecialchars('No "Content-Type" request header specified'), (string) $response->getBody());
- }
- else {
- $this->assertResourceErrorResponse(415, 'No "Content-Type" request header specified', $response);
- }
+ $this->assertSame(415, $response->getStatusCode());
+ $this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type'));
+ $this->assertContains(htmlspecialchars('No "Content-Type" request header specified'), (string) $response->getBody());
$url->setOption('query', ['_format' => static::$format]);
@@ -741,8 +733,13 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
// 201 for well-formed request.
$response = $this->request('POST', $url, $request_options);
$this->assertResourceResponse(201, FALSE, $response);
- $location = $this->entityStorage->load(static::$firstCreatedEntityId)->toUrl('canonical')->setAbsolute(TRUE)->toString();
- $this->assertSame([$location], $response->getHeader('Location'));
+ if ($has_canonical_url) {
+ $location = $this->entityStorage->load(static::$firstCreatedEntityId)->toUrl('canonical')->setAbsolute(TRUE)->toString();
+ $this->assertSame([$location], $response->getHeader('Location'));
+ }
+ else {
+ $this->assertSame([], $response->getHeader('Location'));
+ }
$this->assertFalse($response->hasHeader('X-Drupal-Cache'));
@@ -762,8 +759,13 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
// 201 for well-formed request.
$response = $this->request('POST', $url, $request_options);
$this->assertResourceResponse(201, FALSE, $response);
- $location = $this->entityStorage->load(static::$secondCreatedEntityId)->toUrl('canonical')->setAbsolute(TRUE)->toString();
- $this->assertSame([$location], $response->getHeader('Location'));
+ if ($has_canonical_url) {
+ $location = $this->entityStorage->load(static::$secondCreatedEntityId)->toUrl('canonical')->setAbsolute(TRUE)->toString();
+ $this->assertSame([$location], $response->getHeader('Location'));
+ }
+ else {
+ $this->assertSame([], $response->getHeader('Location'));
+ }
$this->assertFalse($response->hasHeader('X-Drupal-Cache'));
}
@@ -796,7 +798,8 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
$request_options = [];
- // DX: 404 when resource not provisioned, but 405 if canonical route.
+ // DX: 404 when resource not provisioned, 405 if canonical route. Plain text
+ // or HTML response because missing ?_format query string.
$response = $this->request('PATCH', $url, $request_options);
if ($has_canonical_url) {
$this->assertSame(405, $response->getStatusCode());
@@ -804,17 +807,22 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
$this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type'));
}
else {
- $this->assertResourceErrorResponse(404, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response);
+ $this->assertSame(404, $response->getStatusCode());
+ $this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type'));
}
$url->setOption('query', ['_format' => static::$format]);
- // DX: 405 when resource not provisioned.
+ // DX: 404 when resource not provisioned, 405 if canonical route.
$response = $this->request('PATCH', $url, $request_options);
- $this->assertSame(['GET, POST, HEAD'], $response->getHeader('Allow'));
- $this->assertResourceErrorResponse(405, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response);
+ if ($has_canonical_url) {
+ $this->assertResourceErrorResponse(405, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response);
+ }
+ else {
+ $this->assertResourceErrorResponse(404, 'No route found for "PATCH ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response);
+ }
$this->provisionEntityResource();
@@ -822,16 +830,11 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
$url->setOption('query', []);
- // DX: 415 when no Content-Type request header, but HTML if canonical route.
+ // DX: 415 when no Content-Type request header.
$response = $this->request('PATCH', $url, $request_options);
- if ($has_canonical_url) {
- $this->assertSame(415, $response->getStatusCode());
- $this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type'));
- $this->assertTrue(FALSE !== strpos((string) $response->getBody(), htmlspecialchars('No "Content-Type" request header specified')));
- }
- else {
- $this->assertResourceErrorResponse(415, 'No "Content-Type" request header specified', $response);
- }
+ $this->assertSame(415, $response->getStatusCode());
+ $this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type'));
+ $this->assertTrue(FALSE !== strpos((string) $response->getBody(), htmlspecialchars('No "Content-Type" request header specified')));
$url->setOption('query', ['_format' => static::$format]);
@@ -990,7 +993,8 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
$request_options = [];
- // DX: 404 when resource not provisioned, but 405 if canonical route.
+ // DX: 404 when resource not provisioned, but 405 if canonical route. Plain
+ // text or HTML response because missing ?_format query string.
$response = $this->request('DELETE', $url, $request_options);
if ($has_canonical_url) {
$this->assertSame(405, $response->getStatusCode());
@@ -998,18 +1002,23 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
$this->assertSame(['text/plain; charset=UTF-8'], $response->getHeader('Content-Type'));
}
else {
- $this->assertResourceErrorResponse(404, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response);
+ $this->assertSame(404, $response->getStatusCode());
+ $this->assertSame(['text/html; charset=UTF-8'], $response->getHeader('Content-Type'));
}
$url->setOption('query', ['_format' => static::$format]);
- // DX: 405 when resource not provisioned.
+ // DX: 404 when resource not provisioned, 405 if canonical route.
$response = $this->request('DELETE', $url, $request_options);
- $this->assertSame(['GET, POST, HEAD'], $response->getHeader('Allow'));
- $this->assertResourceErrorResponse(405, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response);
-
+ if ($has_canonical_url) {
+ $this->assertSame(['GET, POST, HEAD'], $response->getHeader('Allow'));
+ $this->assertResourceErrorResponse(405, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '": Method Not Allowed (Allow: GET, POST, HEAD)', $response);
+ }
+ else {
+ $this->assertResourceErrorResponse(404, 'No route found for "DELETE ' . str_replace($this->baseUrl, '', $this->getUrl()->setAbsolute()->toString()) . '"', $response);
+ }
$this->provisionEntityResource();
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonAnonTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonAnonTest.php
new file mode 100644
index 0000000..10c4ec4
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonAnonTest.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel;
+
+use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
+
+/**
+ * @group rest
+ */
+class EntityTestLabelJsonAnonTest extends EntityTestLabelResourceTestBase {
+
+ use AnonResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/json';
+
+}
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonBasicAuthTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonBasicAuthTest.php
new file mode 100644
index 0000000..2a43e03
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonBasicAuthTest.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel;
+
+use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
+
+/**
+ * @group rest
+ */
+class EntityTestLabelJsonBasicAuthTest extends EntityTestLabelResourceTestBase {
+
+ use BasicAuthResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['basic_auth'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'basic_auth';
+
+}
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonCookieTest.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonCookieTest.php
new file mode 100644
index 0000000..2fec09d
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelJsonCookieTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel;
+
+use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
+
+/**
+ * @group rest
+ */
+class EntityTestLabelJsonCookieTest extends EntityTestLabelResourceTestBase {
+
+ use CookieResourceTestTrait;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $format = 'json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $mimeType = 'application/json';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $auth = 'cookie';
+
+}
diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelResourceTestBase.php
new file mode 100644
index 0000000..d030787
--- /dev/null
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelResourceTestBase.php
@@ -0,0 +1,156 @@
+<?php
+
+namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel;
+
+use Drupal\entity_test\Entity\EntityTestLabel;
+use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
+use Drupal\user\Entity\User;
+
+abstract class EntityTestLabelResourceTestBase extends EntityResourceTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['entity_test'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $entityTypeId = 'entity_test_label';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected static $patchProtectedFieldNames = [];
+
+ /**
+ * @var \Drupal\entity_test\Entity\EntityTestLabel
+ */
+ protected $entity;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUpAuthorization($method) {
+ switch ($method) {
+ case 'GET':
+ $this->grantPermissionsToTestedRole(['view test entity']);
+ break;
+ case 'POST':
+ $this->grantPermissionsToTestedRole([
+ 'administer entity_test content',
+ 'administer entity_test_with_bundle content',
+ 'create entity_test entity_test_with_bundle entities',
+ ]);
+ break;
+ case 'PATCH':
+ case 'DELETE':
+ $this->grantPermissionsToTestedRole(['administer entity_test content']);
+ break;
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function createEntity() {
+ $entity_test_label = EntityTestLabel::create([
+ 'name' => 'label_llama',
+ ]);
+ $entity_test_label->setOwnerId(0);
+ $entity_test_label->save();
+ return $entity_test_label;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExpectedNormalizedEntity() {
+ $author = User::load(0);
+ $normalization = [
+ 'uuid' => [
+ [
+ 'value' => $this->entity->uuid(),
+ ],
+ ],
+ 'id' => [
+ [
+ 'value' => (int) $this->entity->id(),
+ ],
+ ],
+ 'langcode' => [
+ [
+ 'value' => 'en',
+ ],
+ ],
+ 'type' => [
+ [
+ 'value' => 'entity_test_label',
+ ],
+ ],
+ 'name' => [
+ [
+ 'value' => 'label_llama',
+ ],
+ ],
+ 'created' => [
+ [
+ 'value' => (int) $this->entity->get('created')->value,
+ ],
+ ],
+ 'user_id' => [
+ [
+ 'target_id' => (int) $author->id(),
+ 'target_type' => 'user',
+ 'target_uuid' => $author->uuid(),
+ 'url' => $author->toUrl()->toString(),
+ ],
+ ],
+ ];
+
+ return $normalization;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getNormalizedPostEntity() {
+ return [
+ 'type' => 'entity_test_label',
+ 'name' => [
+ [
+ 'value' => 'label_llama',
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExpectedCacheContexts() {
+ return ['user.permissions'];
+ }
+
+ /**
+ * {@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 'view test entity' permission is required.";
+ case 'POST':
+ return "The following permissions are required: 'administer entity_test content' OR 'administer entity_test_with_bundle content' OR 'create entity_test_label entity_test_with_bundle entities'.";
+ case 'PATCH':
+ case 'DELETE':
+ return "The 'administer entity_test content' permission is required.";
+ default:
+ return parent::getExpectedUnauthorizedAccessMessage($method);
+ }
+ }
+
+}