3 namespace Drupal\Tests\workspaces\Functional\EntityResource;
5 use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
6 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
7 use Drupal\user\Entity\User;
8 use Drupal\workspaces\Entity\Workspace;
11 * Base class for workspace EntityResource tests.
13 abstract class WorkspaceResourceTestBase extends EntityResourceTestBase {
15 use BcTimestampNormalizerUnixTestTrait;
20 public static $modules = ['workspaces'];
25 protected static $entityTypeId = 'workspace';
30 protected static $patchProtectedFieldNames = [
37 protected static $firstCreatedEntityId = 'running_on_faith';
42 protected static $secondCreatedEntityId = 'running_on_faith_2';
47 protected function setUpAuthorization($method) {
50 $this->grantPermissionsToTestedRole(['view any workspace']);
53 $this->grantPermissionsToTestedRole(['create workspace']);
56 $this->grantPermissionsToTestedRole(['edit any workspace']);
59 $this->grantPermissionsToTestedRole(['delete any workspace']);
67 protected function createEntity() {
68 $workspace = Workspace::create([
79 protected function createAnotherEntity() {
80 $workspace = $this->entity->createDuplicate();
81 $workspace->id = 'layla_dupe';
82 $workspace->label = 'Layla_dupe';
90 protected function getExpectedNormalizedEntity() {
91 $author = User::load($this->entity->getOwnerId());
94 $this->formatExpectedTimestampItemValues((int) $this->entity->getCreatedTime()),
97 $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()),
116 'target_id' => (int) $author->id(),
117 'target_type' => 'user',
118 'target_uuid' => $author->uuid(),
119 'url' => base_path() . 'user/' . $author->id(),
124 'value' => $this->entity->uuid(),
133 protected function getNormalizedPostEntity() {
137 'value' => static::$firstCreatedEntityId,
142 'value' => 'Running on faith',
151 protected function getSecondNormalizedPostEntity() {
152 $normalized_post_entity = $this->getNormalizedPostEntity();
153 $normalized_post_entity['id'][0]['value'] = static::$secondCreatedEntityId;
155 return $normalized_post_entity;
161 protected function getNormalizedPatchEntity() {
165 'value' => 'Running on faith',
174 protected function getExpectedUnauthorizedAccessMessage($method) {
175 if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
176 return parent::getExpectedUnauthorizedAccessMessage($method);
181 return "The 'view any workspace' permission is required.";
184 return "The 'create workspace' permission is required.";
187 return "The 'edit any workspace' permission is required.";
190 return "The 'delete any workspace' permission is required.";
193 return parent::getExpectedUnauthorizedAccessMessage($method);