class ShortcutResourceTestBase
Same name and namespace in other branches
- 11.x core/modules/shortcut/tests/src/Functional/Rest/ShortcutResourceTestBase.php \Drupal\Tests\shortcut\Functional\Rest\ShortcutResourceTestBase
- 10 core/modules/shortcut/tests/src/Functional/Rest/ShortcutResourceTestBase.php \Drupal\Tests\shortcut\Functional\Rest\ShortcutResourceTestBase
- 8.9.x core/modules/shortcut/tests/src/Functional/Rest/ShortcutResourceTestBase.php \Drupal\Tests\shortcut\Functional\Rest\ShortcutResourceTestBase
- 8.9.x core/modules/rest/tests/src/Functional/EntityResource/Shortcut/ShortcutResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\Shortcut\ShortcutResourceTestBase
ResourceTestBase for Shortcut entity.
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 extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\rest\Functional\ResourceTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase extends \Drupal\Tests\rest\Functional\ResourceTestBase
- class \Drupal\Tests\shortcut\Functional\Rest\ShortcutResourceTestBase extends \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase
- class \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase extends \Drupal\Tests\rest\Functional\ResourceTestBase
- class \Drupal\Tests\rest\Functional\ResourceTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ShortcutResourceTestBase
1 file declares its use of ShortcutResourceTestBase
- ShortcutHalJsonAnonTest.php in core/
modules/ hal/ tests/ src/ Functional/ shortcut/ ShortcutHalJsonAnonTest.php
File
-
core/
modules/ shortcut/ tests/ src/ Functional/ Rest/ ShortcutResourceTestBase.php, line 12
Namespace
Drupal\Tests\shortcut\Functional\RestView source
abstract class ShortcutResourceTestBase extends EntityResourceTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'comment',
'shortcut',
];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'shortcut';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* The Shortcut entity.
*
* @var \Drupal\shortcut\ShortcutInterface
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
case 'POST':
case 'PATCH':
case 'DELETE':
$this->grantPermissionsToTestedRole([
'access shortcuts',
'customize shortcut links',
]);
break;
}
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Create shortcut.
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Comments'),
'weight' => -20,
'link' => [
'uri' => 'internal:/admin/content/comment',
'options' => [
'fragment' => 'new',
],
],
]);
$shortcut->save();
return $shortcut;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'uuid' => [
[
'value' => $this->entity
->uuid(),
],
],
'id' => [
[
'value' => (int) $this->entity
->id(),
],
],
'title' => [
[
'value' => 'Comments',
],
],
'shortcut_set' => [
[
'target_id' => 'default',
'target_type' => 'shortcut_set',
'target_uuid' => ShortcutSet::load('default')->uuid(),
],
],
'link' => [
[
'uri' => 'internal:/admin/content/comment',
'title' => NULL,
'options' => [
'fragment' => 'new',
],
],
],
'weight' => [
[
'value' => -20,
],
],
'langcode' => [
[
'value' => 'en',
],
],
'default_langcode' => [
[
'value' => TRUE,
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return [
'title' => [
[
'value' => 'Comments',
],
],
'link' => [
[
'uri' => 'internal:/',
],
],
'shortcut_set' => [
[
'target_id' => 'default',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
switch ($method) {
case 'GET':
case 'POST':
case 'PATCH':
case 'DELETE':
return "The shortcut set must be the currently displayed set for the user and the user must have 'access shortcuts' AND 'customize shortcut links' permissions.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.