3 namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel;
5 use Drupal\entity_test\Entity\EntityTestLabel;
6 use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8 use Drupal\user\Entity\User;
10 abstract class EntityTestLabelResourceTestBase extends EntityResourceTestBase {
12 use BcTimestampNormalizerUnixTestTrait;
17 public static $modules = ['entity_test'];
22 protected static $entityTypeId = 'entity_test_label';
27 protected static $patchProtectedFieldNames = [];
30 * @var \Drupal\entity_test\Entity\EntityTestLabel
37 protected function setUpAuthorization($method) {
40 $this->grantPermissionsToTestedRole(['view test entity']);
43 $this->grantPermissionsToTestedRole([
44 'administer entity_test content',
45 'administer entity_test_with_bundle content',
46 'create entity_test entity_test_with_bundle entities',
51 $this->grantPermissionsToTestedRole(['administer entity_test content']);
59 protected function createEntity() {
60 $entity_test_label = EntityTestLabel::create([
61 'name' => 'label_llama',
63 $entity_test_label->setOwnerId(0);
64 $entity_test_label->save();
65 return $entity_test_label;
71 protected function getExpectedNormalizedEntity() {
72 $author = User::load(0);
76 'value' => $this->entity->uuid(),
81 'value' => (int) $this->entity->id(),
91 'value' => 'entity_test_label',
96 'value' => 'label_llama',
100 $this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value),
104 'target_id' => (int) $author->id(),
105 'target_type' => 'user',
106 'target_uuid' => $author->uuid(),
107 'url' => $author->toUrl()->toString(),
112 return $normalization;
118 protected function getNormalizedPostEntity() {
122 'value' => 'entity_test_label',
127 'value' => 'label_llama',
136 protected function getExpectedCacheContexts() {
137 return ['user.permissions'];
143 protected function getExpectedUnauthorizedAccessMessage($method) {
144 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
145 return parent::getExpectedUnauthorizedAccessMessage($method);
150 return "The 'view test entity' permission is required.";
152 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'.";
155 return "The 'administer entity_test content' permission is required.";
157 return parent::getExpectedUnauthorizedAccessMessage($method);