3 namespace Drupal\Tests\entity_test\Functional\Rest;
5 use Drupal\entity_test\Entity\EntityTestMapField;
6 use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8 use Drupal\Tests\Traits\ExpectDeprecationTrait;
9 use Drupal\user\Entity\User;
11 abstract class EntityTestMapFieldResourceTestBase extends EntityResourceTestBase {
13 use BcTimestampNormalizerUnixTestTrait;
14 use ExpectDeprecationTrait;
19 public static $modules = ['entity_test'];
24 protected static $entityTypeId = 'entity_test_map_field';
29 protected static $patchProtectedFieldNames = [];
32 * @var \Drupal\entity_test\Entity\EntityTestMapField
37 * The complex nested value to assign to a @FieldType=map field.
41 protected static $mapValue = [
43 'key2' => 'no, val you',
55 protected function setUpAuthorization($method) {
56 $this->grantPermissionsToTestedRole(['administer entity_test content']);
62 protected function createEntity() {
63 $entity = EntityTestMapField::create([
65 'type' => 'entity_test_map_field',
70 $entity->setOwnerId(0);
78 protected function getExpectedNormalizedEntity() {
79 $author = User::load(0);
83 'value' => $this->entity->uuid(),
102 $this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value),
106 'target_id' => (int) $author->id(),
107 'target_type' => 'user',
108 'target_uuid' => $author->uuid(),
109 'url' => $author->toUrl()->toString(),
121 protected function getNormalizedPostEntity() {
125 'value' => 'Dramallama',
129 0 => static::$mapValue,
137 protected function getExpectedUnauthorizedAccessMessage($method) {
138 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
139 return parent::getExpectedUnauthorizedAccessMessage($method);
142 return "The 'administer entity_test content' permission is required.";
148 protected function getExpectedCacheContexts() {
149 return ['user.permissions'];