X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fworkspaces%2Ftests%2Fsrc%2FFunctional%2FEntityResource%2FWorkspaceResourceTestBase.php;fp=web%2Fcore%2Fmodules%2Fworkspaces%2Ftests%2Fsrc%2FFunctional%2FEntityResource%2FWorkspaceResourceTestBase.php;h=79f24da5a8eae4f4d0c9b0353baf7ebae979fb21;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/workspaces/tests/src/Functional/EntityResource/WorkspaceResourceTestBase.php b/web/core/modules/workspaces/tests/src/Functional/EntityResource/WorkspaceResourceTestBase.php new file mode 100644 index 000000000..79f24da5a --- /dev/null +++ b/web/core/modules/workspaces/tests/src/Functional/EntityResource/WorkspaceResourceTestBase.php @@ -0,0 +1,196 @@ + NULL, + ]; + + /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'running_on_faith'; + + /** + * {@inheritdoc} + */ + protected static $secondCreatedEntityId = 'running_on_faith_2'; + + /** + * {@inheritdoc} + */ + protected function setUpAuthorization($method) { + switch ($method) { + case 'GET': + $this->grantPermissionsToTestedRole(['view any workspace']); + break; + case 'POST': + $this->grantPermissionsToTestedRole(['create workspace']); + break; + case 'PATCH': + $this->grantPermissionsToTestedRole(['edit any workspace']); + break; + case 'DELETE': + $this->grantPermissionsToTestedRole(['delete any workspace']); + break; + } + } + + /** + * {@inheritdoc} + */ + protected function createEntity() { + $workspace = Workspace::create([ + 'id' => 'layla', + 'label' => 'Layla', + ]); + $workspace->save(); + return $workspace; + } + + /** + * {@inheritdoc} + */ + protected function createAnotherEntity() { + $workspace = $this->entity->createDuplicate(); + $workspace->id = 'layla_dupe'; + $workspace->label = 'Layla_dupe'; + $workspace->save(); + return $workspace; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedEntity() { + $author = User::load($this->entity->getOwnerId()); + return [ + 'created' => [ + $this->formatExpectedTimestampItemValues((int) $this->entity->getCreatedTime()), + ], + 'changed' => [ + $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), + ], + 'id' => [ + [ + 'value' => 'layla', + ], + ], + 'label' => [ + [ + 'value' => 'Layla', + ], + ], + 'revision_id' => [ + [ + 'value' => 3, + ], + ], + 'uid' => [ + [ + 'target_id' => (int) $author->id(), + 'target_type' => 'user', + 'target_uuid' => $author->uuid(), + 'url' => base_path() . 'user/' . $author->id(), + ], + ], + 'uuid' => [ + [ + 'value' => $this->entity->uuid(), + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + return [ + 'id' => [ + [ + 'value' => static::$firstCreatedEntityId, + ], + ], + 'label' => [ + [ + 'value' => 'Running on faith', + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getSecondNormalizedPostEntity() { + $normalized_post_entity = $this->getNormalizedPostEntity(); + $normalized_post_entity['id'][0]['value'] = static::$secondCreatedEntityId; + + return $normalized_post_entity; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return [ + 'label' => [ + [ + 'value' => 'Running on faith', + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { + return parent::getExpectedUnauthorizedAccessMessage($method); + } + + switch ($method) { + case 'GET': + return "The 'view any workspace' permission is required."; + break; + case 'POST': + return "The 'create workspace' permission is required."; + break; + case 'PATCH': + return "The 'edit any workspace' permission is required."; + break; + case 'DELETE': + return "The 'delete any workspace' permission is required."; + break; + } + return parent::getExpectedUnauthorizedAccessMessage($method); + } + +}