View source
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\entity_test\Entity\EntityTestMapField;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\user\Entity\User;
abstract class EntityTestMapFieldResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
use ExpectDeprecationTrait;
public static $modules = [
'entity_test',
];
protected static $entityTypeId = 'entity_test_map_field';
protected static $patchProtectedFieldNames = [];
protected $entity;
protected static $mapValue = [
'key1' => 'value',
'key2' => 'no, val you',
'π' => 3.14159,
TRUE => 42,
'nested' => [
'bird' => 'robin',
'doll' => 'Russian',
],
];
protected function setUpAuthorization($method) {
$this
->grantPermissionsToTestedRole([
'administer entity_test content',
]);
}
protected function createEntity() {
$entity = EntityTestMapField::create([
'name' => 'Llama',
'type' => 'entity_test_map_field',
'data' => [
static::$mapValue,
],
]);
$entity
->setOwnerId(0);
$entity
->save();
return $entity;
}
protected function getExpectedNormalizedEntity() {
$author = User::load(0);
return [
'uuid' => [
[
'value' => $this->entity
->uuid(),
],
],
'id' => [
[
'value' => 1,
],
],
'name' => [
[
'value' => 'Llama',
],
],
'langcode' => [
[
'value' => 'en',
],
],
'created' => [
$this
->formatExpectedTimestampItemValues((int) $this->entity
->get('created')->value),
],
'user_id' => [
[
'target_id' => (int) $author
->id(),
'target_type' => 'user',
'target_uuid' => $author
->uuid(),
'url' => $author
->toUrl()
->toString(),
],
],
'data' => [
static::$mapValue,
],
];
}
protected function getNormalizedPostEntity() {
return [
'name' => [
[
'value' => 'Dramallama',
],
],
'data' => [
0 => static::$mapValue,
],
];
}
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this
->config('rest.settings')
->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
return "The 'administer entity_test content' permission is required.";
}
protected function getExpectedCacheContexts() {
return [
'user.permissions',
];
}
}