3 namespace Drupal\Tests\rest\Functional\EntityResource\EntityTest;
5 use Drupal\entity_test\Entity\EntityTest;
6 use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8 use Drupal\user\Entity\User;
10 abstract class EntityTestResourceTestBase extends EntityResourceTestBase {
12 use BcTimestampNormalizerUnixTestTrait;
17 public static $modules = ['entity_test'];
22 protected static $entityTypeId = 'entity_test';
27 protected static $patchProtectedFieldNames = [];
30 * @var \Drupal\entity_test\Entity\EntityTest
37 protected function setUpAuthorization($method) {
40 $this->grantPermissionsToTestedRole(['view test entity']);
43 $this->grantPermissionsToTestedRole(['create entity_test entity_test_with_bundle entities']);
47 $this->grantPermissionsToTestedRole(['administer entity_test content']);
55 protected function createEntity() {
56 $entity_test = EntityTest::create([
58 'type' => 'entity_test',
60 $entity_test->setOwnerId(0);
69 protected function getExpectedNormalizedEntity() {
70 $author = User::load(0);
74 'value' => $this->entity->uuid()
89 'value' => 'entity_test',
98 $this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value)
102 'target_id' => (int) $author->id(),
103 'target_type' => 'user',
104 'target_uuid' => $author->uuid(),
105 'url' => $author->toUrl()->toString(),
108 'field_test_text' => [],
111 return $normalization;
117 protected function getNormalizedPostEntity() {
121 'value' => 'entity_test',
126 'value' => 'Dramallama',
135 protected function getExpectedUnauthorizedAccessMessage($method) {
136 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
137 return parent::getExpectedUnauthorizedAccessMessage($method);
142 return "The 'view test entity' permission is required.";
144 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'.";
146 return parent::getExpectedUnauthorizedAccessMessage($method);