3 namespace Drupal\Tests\rest\Functional\EntityResource\EntityTest;
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
7 use Drupal\user\Entity\User;
9 abstract class EntityTestResourceTestBase extends EntityResourceTestBase {
14 public static $modules = ['entity_test'];
19 protected static $entityTypeId = 'entity_test';
24 protected static $patchProtectedFieldNames = [];
27 * @var \Drupal\entity_test\Entity\EntityTest
34 protected function setUpAuthorization($method) {
37 $this->grantPermissionsToTestedRole(['view test entity']);
40 $this->grantPermissionsToTestedRole(['create entity_test entity_test_with_bundle entities']);
44 $this->grantPermissionsToTestedRole(['administer entity_test content']);
52 protected function createEntity() {
53 $entity_test = EntityTest::create([
55 'type' => 'entity_test',
57 $entity_test->setOwnerId(0);
66 protected function getExpectedNormalizedEntity() {
67 $author = User::load(0);
71 'value' => $this->entity->uuid()
86 'value' => 'entity_test',
96 'value' => (int) $this->entity->get('created')->value,
101 'target_id' => (int) $author->id(),
102 'target_type' => 'user',
103 'target_uuid' => $author->uuid(),
104 'url' => $author->toUrl()->toString(),
107 'field_test_text' => [],
110 return $normalization;
116 protected function getNormalizedPostEntity() {
118 'type' => 'entity_test',
121 'value' => 'Dramallama',
130 protected function getExpectedUnauthorizedAccessMessage($method) {
131 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
132 return parent::getExpectedUnauthorizedAccessMessage($method);
137 return "The 'view test entity' permission is required.";
139 return "The following permissions are required: 'administer entity_test content' OR 'administer entity_test_with_bundle content' OR 'create entity_test entity_test_with_bundle entities'.";
141 return parent::getExpectedUnauthorizedAccessMessage($method);