3 namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel;
5 use Drupal\entity_test\Entity\EntityTestLabel;
6 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
7 use Drupal\user\Entity\User;
9 abstract class EntityTestLabelResourceTestBase extends EntityResourceTestBase {
14 public static $modules = ['entity_test'];
19 protected static $entityTypeId = 'entity_test_label';
24 protected static $patchProtectedFieldNames = [];
27 * @var \Drupal\entity_test\Entity\EntityTestLabel
34 protected function setUpAuthorization($method) {
37 $this->grantPermissionsToTestedRole(['view test entity']);
40 $this->grantPermissionsToTestedRole([
41 'administer entity_test content',
42 'administer entity_test_with_bundle content',
43 'create entity_test entity_test_with_bundle entities',
48 $this->grantPermissionsToTestedRole(['administer entity_test content']);
56 protected function createEntity() {
57 $entity_test_label = EntityTestLabel::create([
58 'name' => 'label_llama',
60 $entity_test_label->setOwnerId(0);
61 $entity_test_label->save();
62 return $entity_test_label;
68 protected function getExpectedNormalizedEntity() {
69 $author = User::load(0);
73 'value' => $this->entity->uuid(),
78 'value' => (int) $this->entity->id(),
88 'value' => 'entity_test_label',
93 'value' => 'label_llama',
98 'value' => (int) $this->entity->get('created')->value,
103 'target_id' => (int) $author->id(),
104 'target_type' => 'user',
105 'target_uuid' => $author->uuid(),
106 'url' => $author->toUrl()->toString(),
111 return $normalization;
117 protected function getNormalizedPostEntity() {
119 'type' => 'entity_test_label',
122 'value' => 'label_llama',
131 protected function getExpectedCacheContexts() {
132 return ['user.permissions'];
138 protected function getExpectedUnauthorizedAccessMessage($method) {
139 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
140 return parent::getExpectedUnauthorizedAccessMessage($method);
145 return "The 'view test entity' permission is required.";
147 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'.";
150 return "The 'administer entity_test content' permission is required.";
152 return parent::getExpectedUnauthorizedAccessMessage($method);