class WorkspaceResourceTestBase
Same name and namespace in other branches
- 11.x core/modules/workspaces/tests/src/Functional/Rest/WorkspaceResourceTestBase.php \Drupal\Tests\workspaces\Functional\Rest\WorkspaceResourceTestBase
Base class for workspace EntityResource tests.
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\rest\Functional\ResourceTestBase implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase implements \Drupal\Tests\rest\Functional\ResourceTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase implements \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase
- class \Drupal\Tests\workspaces\Functional\EntityResource\WorkspaceResourceTestBase implements \Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase implements \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase implements \Drupal\Tests\rest\Functional\ResourceTestBase
- class \Drupal\Tests\rest\Functional\ResourceTestBase implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of WorkspaceResourceTestBase
File
-
core/
modules/ workspaces/ tests/ src/ Functional/ EntityResource/ WorkspaceResourceTestBase.php, line 12
Namespace
Drupal\Tests\workspaces\Functional\EntityResourceView source
abstract class WorkspaceResourceTestBase extends ConfigEntityResourceTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'workspaces',
];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'workspace';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [
'changed' => NULL,
];
/**
* {@inheritdoc}
*/
protected static $uniqueFieldNames = [
'id',
];
/**
* {@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' => [
[
'value' => (new \DateTime())->setTimestamp((int) $this->entity
->getCreatedTime())
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339),
'format' => \DateTime::RFC3339,
],
],
'changed' => [
[
'value' => (new \DateTime())->setTimestamp($this->entity
->getChangedTime())
->setTimezone(new \DateTimeZone('UTC'))
->format(\DateTime::RFC3339),
'format' => \DateTime::RFC3339,
],
],
'id' => [
[
'value' => 'layla',
],
],
'label' => [
[
'value' => 'Layla',
],
],
'revision_id' => [
[
'value' => 2,
],
],
'parent' => [],
'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 getNormalizedPatchEntity() {
return [
'label' => [
[
'value' => 'Running on faith',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
switch ($method) {
case 'GET':
return "The 'view any workspace' permission is required.";
case 'POST':
return "The following permissions are required: 'administer workspaces' OR 'create workspace'.";
case 'PATCH':
return "The 'edit any workspace' permission is required.";
case 'DELETE':
return "The 'delete any workspace' permission is required.";
}
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.