summaryrefslogtreecommitdiffstats
path: root/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel')
-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
4 files changed, 243 insertions, 0 deletions
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);
+ }
+ }
+
+}