diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 90bb702..2d7ed0a 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -5,11 +5,13 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Schema\SchemaIncompleteException; +use Drupal\Core\Entity\ConfigValidatableTrait; use Drupal\Core\Entity\Entity; use Drupal\Core\Config\ConfigDuplicateUUIDException; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; +use Drupal\Core\Entity\ValidatableInterface; use Drupal\Core\Plugin\PluginDependencyTrait; /** @@ -17,12 +19,14 @@ * * @ingroup entity_api */ -abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface { +abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface, ValidatableInterface { use PluginDependencyTrait { addDependency as addDependencyTrait; } + use ConfigValidatableTrait; + /** * The original ID of the configuration entity. * diff --git a/core/modules/rest/tests/modules/rest_test_access_helper/rest_test_access_helper.info.yml b/core/modules/rest/tests/modules/rest_test_access_helper/rest_test_access_helper.info.yml new file mode 100644 index 0000000..e8a4c07 --- /dev/null +++ b/core/modules/rest/tests/modules/rest_test_access_helper/rest_test_access_helper.info.yml @@ -0,0 +1,8 @@ +name: 'REST test access helper' +type: module +description: 'Provides needs access rules for REST tests.' +package: Testing +version: VERSION +core: 8.x +dependencies: + - editor \ No newline at end of file diff --git a/core/modules/rest/tests/modules/rest_test_access_helper/rest_test_access_helper.module b/core/modules/rest/tests/modules/rest_test_access_helper/rest_test_access_helper.module new file mode 100644 index 0000000..ef75f2c --- /dev/null +++ b/core/modules/rest/tests/modules/rest_test_access_helper/rest_test_access_helper.module @@ -0,0 +1,18 @@ +setHandlerClass("access", BaseFieldOverrideAccessControlHandlerHelper::class); + $entity_info['editor']->setHandlerClass("access", EditorAccessControlHandlerHelper::class); + $entity_info['field_config']->setHandlerClass("access", FieldConfigAccessControlHandlerHelper::class); + $entity_info['field_storage_config']->setHandlerClass("access", FieldStorageConfigAccessControlHandlerHelper::class); + $entity_info['filter_format']->setHandlerClass("access", FilterFormatAccessControlHandlerHelper::class); +} diff --git a/core/modules/rest/tests/modules/rest_test_access_helper/src/BaseFieldOverrideAccessControlHandlerHelper.php b/core/modules/rest/tests/modules/rest_test_access_helper/src/BaseFieldOverrideAccessControlHandlerHelper.php new file mode 100644 index 0000000..8dbd0f5 --- /dev/null +++ b/core/modules/rest/tests/modules/rest_test_access_helper/src/BaseFieldOverrideAccessControlHandlerHelper.php @@ -0,0 +1,20 @@ +isAllowed()) { + return AccessResult::allowed(); + } + return parent::checkAccess($filter_format, $operation, $account); + } + +} diff --git a/core/modules/rest/tests/modules/rest_test_base_field_override_helper/rest_test_base_field_override_helper.info.yml b/core/modules/rest/tests/modules/rest_test_base_field_override_helper/rest_test_base_field_override_helper.info.yml new file mode 100644 index 0000000..4ce0875 --- /dev/null +++ b/core/modules/rest/tests/modules/rest_test_base_field_override_helper/rest_test_base_field_override_helper.info.yml @@ -0,0 +1,8 @@ +name: 'REST base field override helper' +type: module +description: 'Provides test base fields for REST tests of base_field_override entity.' +package: Testing +version: VERSION +core: 8.x +dependencies: + - rest diff --git a/core/modules/rest/tests/modules/rest_test_base_field_override_helper/rest_test_base_field_override_helper.module b/core/modules/rest/tests/modules/rest_test_base_field_override_helper/rest_test_base_field_override_helper.module new file mode 100644 index 0000000..91b3d0f --- /dev/null +++ b/core/modules/rest/tests/modules/rest_test_base_field_override_helper/rest_test_base_field_override_helper.module @@ -0,0 +1,22 @@ +id() === 'node') { + $fields = []; + for ($i=0; $i < 10; $i++) { + $new_field = "promote$i"; + $fields[$new_field] = BaseFieldDefinition::create('boolean') + ->setTargetEntityTypeId('node') + ->setProvider('node') + ->setTargetBundle(NULL) + ->setName($new_field) + ->setLabel($new_field); + } + return $fields; + } +} \ No newline at end of file diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Action/ActionResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Action/ActionResourceTestBase.php index 76aff4b..d20ca9d 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Action/ActionResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Action/ActionResourceTestBase.php @@ -4,6 +4,8 @@ use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use Drupal\system\Entity\Action; +use Drupal\user\Entity\Role; +use Drupal\user\Plugin\Action\AddRoleUser; use Drupal\user\RoleInterface; abstract class ActionResourceTestBase extends EntityResourceTestBase { @@ -24,6 +26,18 @@ protected $entity; /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'dllama1'; + + /** * {@inheritdoc} */ protected function setUpAuthorization($method) { @@ -34,17 +48,36 @@ protected function setUpAuthorization($method) { * {@inheritdoc} */ protected function createEntity() { + + $role = 'anonymous' . $this->counter; + if (Role::load($role)) { + Role::create([ + 'id' => 'anonymous' . $this->counter, + 'label' => 'anonymous', + ])->save(); + } + $action = Action::create([ - 'id' => 'user_add_role_action.' . RoleInterface::ANONYMOUS_ID, + 'id' => "user_add_role_action.$role", 'type' => 'user', 'label' => t('Add the anonymous role to the selected users'), 'configuration' => [ - 'rid' => RoleInterface::ANONYMOUS_ID, + 'rid' => $role, ], 'plugin' => 'user_add_role_action', ]); $action->save(); + // Or use more simple Action example? + /* + public static $modules = ['user', 'action']; + ... + $action = Action::create([ + 'id' => 'llama' . $this->counter, + 'plugin' => 'action_message_action', + ]); + $action->save(); + */ return $action; } @@ -54,13 +87,13 @@ protected function createEntity() { protected function getExpectedNormalizedEntity() { return [ 'configuration' => [ - 'rid' => 'anonymous', + 'rid' => 'anonymous' . $this->counter, ], 'dependencies' => [ - 'config' => ['user.role.anonymous'], + 'config' => ['user.role.anonymous' . $this->counter], 'module' => ['user'], ], - 'id' => 'user_add_role_action.anonymous', + 'id' => 'user_add_role_action.anonymous' . $this->counter, 'label' => 'Add the anonymous role to the selected users', 'langcode' => 'en', 'plugin' => 'user_add_role_action', @@ -82,8 +115,33 @@ protected function getExpectedCacheContexts() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + Role::create([ + 'id' => 'anonymous' . $this->counter, + 'label' => 'anonymous', + ])->save(); + } + + return [ + 'id' => 'dllama' . $this->counter, + 'label' => 'dllama', + 'type' => 'user', + 'plugin' => 'user_add_role_action', + 'configuration' => [ + 'rid' => 'anonymous' . $this->counter, + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + $result = $this->getNormalizedPostEntity(FALSE); + $result['id'] = 'user_add_role_action.anonymous' . $this->counter; + return $result; } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/BaseFieldOverride/BaseFieldOverrideResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/BaseFieldOverride/BaseFieldOverrideResourceTestBase.php index 1f4b03a..2ca78d4 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/BaseFieldOverride/BaseFieldOverrideResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/BaseFieldOverride/BaseFieldOverrideResourceTestBase.php @@ -11,7 +11,7 @@ /** * {@inheritdoc} */ - public static $modules = ['field', 'node']; + public static $modules = ['field', 'node', 'rest_test_access_helper', 'rest_test_base_field_override_helper']; /** * {@inheritdoc} @@ -19,6 +19,18 @@ protected static $entityTypeId = 'base_field_override'; /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'node.camelids.promote1'; + + /** * @var \Drupal\Core\Field\Entity\BaseFieldOverride */ protected $entity; @@ -34,14 +46,17 @@ protected function setUpAuthorization($method) { * {@inheritdoc} */ protected function createEntity() { - $camelids = NodeType::create([ - 'name' => 'Camelids', - 'type' => 'camelids', - ]); - $camelids->save(); + if (!NodeType::load('camelids')) { + $camelids = NodeType::create([ + 'name' => 'Camelids', + 'type' => 'camelids', + ]); + $camelids->save(); + } $entity = BaseFieldOverride::create([ - 'field_name' => 'promote', + 'field_name' => 'promote' . $this->counter, + 'label' => 'promote', 'entity_type' => 'node', 'bundle' => 'camelids', ]); @@ -65,10 +80,10 @@ protected function getExpectedNormalizedEntity() { ], 'description' => '', 'entity_type' => 'node', - 'field_name' => 'promote', + 'field_name' => 'promote' . $this->counter, 'field_type' => 'boolean', - 'id' => 'node.camelids.promote', - 'label' => NULL, + 'id' => 'node.camelids.promote' . $this->counter, + 'label' => 'promote', 'langcode' => 'en', 'required' => FALSE, 'settings' => [ @@ -84,8 +99,23 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'field_name' => 'promote'. $this->counter, + 'label' => 'promote', + 'entity_type' => 'node', + 'bundle' => 'camelids', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Block/BlockResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Block/BlockResourceTestBase.php index d86f9b1..23987d6 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Block/BlockResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Block/BlockResourceTestBase.php @@ -18,6 +18,23 @@ protected static $entityTypeId = 'block'; /** + * {@inheritdoc} + */ + protected static $labelFieldName = 'region'; + + /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'llama1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\block\BlockInterface */ protected $entity; @@ -30,10 +47,10 @@ protected function setUpAuthorization($method) { case 'GET': $this->entity->setVisibilityConfig('user_role', [])->save(); break; + case 'POST': - $this->grantPermissionsToTestedRole(['administer blocks']); - break; case 'PATCH': + case 'DELETE': $this->grantPermissionsToTestedRole(['administer blocks']); break; } @@ -44,9 +61,9 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $block = Block::create([ - 'plugin' => 'llama_block', + 'plugin' => 'llama_block' . $this->counter, 'region' => 'header', - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'theme' => 'classy', ]); // All blocks can be viewed by the anonymous user by default. An interesting @@ -76,7 +93,7 @@ protected function createEntity() { protected function getExpectedNormalizedEntity() { $normalization = [ 'uuid' => $this->entity->uuid(), - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'weight' => NULL, 'langcode' => 'en', 'status' => TRUE, @@ -88,7 +105,7 @@ protected function getExpectedNormalizedEntity() { 'theme' => 'classy', 'region' => 'header', 'provider' => NULL, - 'plugin' => 'llama_block', + 'plugin' => 'llama_block' . $this->counter, 'settings' => [ 'id' => 'broken', 'label' => '', @@ -104,8 +121,23 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'plugin' => 'llama_block' . $this->counter, + 'region' => 'header', + 'id' => 'llama' . $this->counter, + 'theme' => 'classy', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/BlockContentType/BlockContentTypeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/BlockContentType/BlockContentTypeResourceTestBase.php index f96f40e..6b57518 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/BlockContentType/BlockContentTypeResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/BlockContentType/BlockContentTypeResourceTestBase.php @@ -18,6 +18,18 @@ protected static $entityTypeId = 'block_content_type'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'pascal1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\block_content\Entity\BlockContentTypeInterface */ protected $entity; @@ -34,7 +46,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $block_content_type = BlockContentType::create([ - 'id' => 'pascal', + 'id' => 'pascal' . $this->counter, 'label' => 'Pascal', 'revision' => FALSE, 'description' => 'Provides a competitive alternative to the "basic" type', @@ -52,7 +64,7 @@ protected function getExpectedNormalizedEntity() { return [ 'dependencies' => [], 'description' => 'Provides a competitive alternative to the "basic" type', - 'id' => 'pascal', + 'id' => 'pascal' . $this->counter, 'label' => 'Pascal', 'langcode' => 'en', 'revision' => 0, @@ -64,8 +76,22 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'pascal' . $this->counter, + 'label' => 'Pascal', + 'description' => 'Provides a competitive alternative to the "basic" type', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/CommentType/CommentTypeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/CommentType/CommentTypeResourceTestBase.php index 9d88211..193cde2 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/CommentType/CommentTypeResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/CommentType/CommentTypeResourceTestBase.php @@ -21,6 +21,18 @@ protected static $entityTypeId = 'comment_type'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'camelids1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * The CommentType entity. * * @var \Drupal\comment\CommentTypeInterface @@ -40,7 +52,7 @@ protected function setUpAuthorization($method) { protected function createEntity() { // Create a "Camelids" comment type. $camelids = CommentType::create([ - 'id' => 'camelids', + 'id' => 'camelids' . $this->counter, 'label' => 'Camelids', 'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.', 'target_entity_type_id' => 'node', @@ -58,7 +70,7 @@ protected function getExpectedNormalizedEntity() { return [ 'dependencies' => [], 'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.', - 'id' => 'camelids', + 'id' => 'camelids' . $this->counter, 'label' => 'Camelids', 'langcode' => 'en', 'status' => TRUE, @@ -70,8 +82,21 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'camelids' . $this->counter, + 'label' => 'Camelids', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php index f49fbc9..cc94e2f 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php @@ -57,7 +57,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $config_test = ConfigTest::create([ - 'id' => 'llama' . (string) $this->counter, + 'id' => 'llama' . $this->counter, 'label' => 'Llama', ]); $config_test->save(); @@ -71,7 +71,7 @@ protected function createEntity() { protected function getExpectedNormalizedEntity() { $normalization = [ 'uuid' => $this->entity->uuid(), - 'id' => 'llama' . (string) $this->counter, + 'id' => 'llama' . $this->counter, 'weight' => 0, 'langcode' => 'en', 'status' => TRUE, @@ -108,7 +108,7 @@ protected function getNormalizedPostEntity($count_up = TRUE) { } return [ - 'id' => 'llama' . (string) $this->counter, + 'id' => 'llama' . $this->counter, 'label' => 'Llamam', ]; } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ConfigurableLanguage/ConfigurableLanguageResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ConfigurableLanguage/ConfigurableLanguageResourceTestBase.php index 301beb2..8bdd3bf 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ConfigurableLanguage/ConfigurableLanguageResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ConfigurableLanguage/ConfigurableLanguageResourceTestBase.php @@ -19,6 +19,18 @@ protected static $entityTypeId = 'configurable_language'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'll1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\language\ConfigurableLanguageInterface */ protected $entity; @@ -35,7 +47,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $configurable_language = ConfigurableLanguage::create([ - 'id' => 'll', + 'id' => 'll' . $this->counter, 'label' => 'Llama Language', ]); $configurable_language->save(); @@ -50,7 +62,7 @@ protected function getExpectedNormalizedEntity() { return [ 'dependencies' => [], 'direction' => 'ltr', - 'id' => 'll', + 'id' => 'll' . $this->counter, 'label' => 'Llama Language', 'langcode' => 'en', 'locked' => FALSE, @@ -70,8 +82,21 @@ protected function getExpectedCacheContexts() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'll' . $this->counter, + 'label' => 'Llama Language', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ContactForm/ContactFormResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ContactForm/ContactFormResourceTestBase.php index 51e297a..b32f6ff 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ContactForm/ContactFormResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ContactForm/ContactFormResourceTestBase.php @@ -26,6 +26,23 @@ protected static $patchProtectedFieldNames = []; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'llama1'; + + /** + * {@inheritdoc} + */ + protected static $secondCreatedEntityId = 'llama2'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\contact\Entity\ContactForm */ protected $entity; @@ -47,7 +64,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $contact_form = ContactForm::create([ - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'label' => 'Llama', 'message' => 'Let us know what you think about llamas', 'reply' => 'Llamas are indeed awesome!', @@ -67,7 +84,7 @@ protected function createEntity() { protected function getExpectedNormalizedEntity() { return [ 'dependencies' => [], - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'label' => 'Llama', 'langcode' => 'en', 'message' => 'Let us know what you think about llamas', @@ -86,8 +103,27 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'llama' . $this->counter, + 'label' => 'llama', + 'message' => 'Let us know what you think about llamas', + 'reply' => 'Llamas are indeed awesome!', + 'recipients' => [ + 'llama@example.com', + 'contact@example.com', + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** @@ -97,8 +133,10 @@ protected function getExpectedUnauthorizedAccessMessage($method) { if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { return parent::getExpectedUnauthorizedAccessMessage($method); } - - return "The 'access site-wide contact form' permission is required."; + if ($method === 'GET') { + return "The 'access site-wide contact form' permission is required."; + } + return "The 'administer contact forms' permission is required."; } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ContentLanguageSettings/ContentLanguageSettingsResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ContentLanguageSettings/ContentLanguageSettingsResourceTestBase.php index a8b3f8c..6b9ec5e 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ContentLanguageSettings/ContentLanguageSettingsResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ContentLanguageSettings/ContentLanguageSettingsResourceTestBase.php @@ -19,6 +19,23 @@ protected static $entityTypeId = 'language_content_settings'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'node.camelids1'; + + /** + * {@inheritdoc} + */ + protected static $labelFieldName = 'langcode'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\language\ContentLanguageSettingsInterface */ protected $entity; @@ -34,16 +51,19 @@ protected function setUpAuthorization($method) { * {@inheritdoc} */ protected function createEntity() { - // Create a "Camelids" node type. - $camelids = NodeType::create([ - 'name' => 'Camelids', - 'type' => 'camelids', - ]); - $camelids->save(); + if (!NodeType::load('camelids' . $this->counter)) { + // Create a "Camelids" node type. + $camelids = NodeType::create([ + 'name' => 'Camelids', + 'type' => 'camelids' . $this->counter, + ]); + $camelids->save(); + } + $entity = ContentLanguageSettings::create([ 'target_entity_type_id' => 'node', - 'target_bundle' => 'camelids', + 'target_bundle' => 'camelids' . $this->counter, ]); $entity->setDefaultLangcode('site_default') ->save(); @@ -59,14 +79,14 @@ protected function getExpectedNormalizedEntity() { 'default_langcode' => 'site_default', 'dependencies' => [ 'config' => [ - 'node.type.camelids', + 'node.type.camelids' . $this->counter, ], ], - 'id' => 'node.camelids', + 'id' => 'node.camelids' . $this->counter, 'langcode' => 'en', 'language_alterable' => FALSE, 'status' => TRUE, - 'target_bundle' => 'camelids', + 'target_bundle' => 'camelids' . $this->counter, 'target_entity_type_id' => 'node', 'uuid' => $this->entity->uuid(), ]; @@ -75,8 +95,28 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + + $camelids = NodeType::create([ + 'name' => 'Camelids', + 'type' => 'camelids' . $this->counter, + ]); + $camelids->save(); + } + return [ + 'target_entity_type_id' => 'node', + 'target_bundle' => 'camelids' . $this->counter, + 'langcode' => 'll', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/DateFormat/DateFormatResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/DateFormat/DateFormatResourceTestBase.php index 8fce0fe..d64caa3 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/DateFormat/DateFormatResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/DateFormat/DateFormatResourceTestBase.php @@ -21,6 +21,18 @@ protected static $entityTypeId = 'date_format'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'llama1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * The DateFormat entity. * * @var \Drupal\Core\Datetime\DateFormatInterface @@ -40,7 +52,7 @@ protected function setUpAuthorization($method) { protected function createEntity() { // Create a date format. $date_format = DateFormat::create([ - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'label' => 'Llama', 'pattern' => 'F d, Y', ]); @@ -56,7 +68,7 @@ protected function createEntity() { protected function getExpectedNormalizedEntity() { return [ 'dependencies' => [], - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'label' => 'Llama', 'langcode' => 'en', 'locked' => FALSE, @@ -69,8 +81,22 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'llama' . $this->counter, + 'label' => 'Llama', + 'pattern' => 'F d, Y', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Editor/EditorResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Editor/EditorResourceTestBase.php index 4eb4a6e..8426536 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Editor/EditorResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Editor/EditorResourceTestBase.php @@ -14,7 +14,7 @@ /** * {@inheritdoc} */ - public static $modules = ['ckeditor', 'editor']; + public static $modules = ['ckeditor', 'editor', 'rest_test_access_helper']; /** * {@inheritdoc} @@ -22,6 +22,23 @@ protected static $entityTypeId = 'editor'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'llama1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** + * {@inheritdoc} + */ + protected static $labelFieldName = 'langcode'; + + /** * The Editor entity. * * @var \Drupal\editor\EditorInterface @@ -39,26 +56,28 @@ protected function setUpAuthorization($method) { * {@inheritdoc} */ protected function createEntity() { - // Create a "Llama" filter format. - $llama_format = FilterFormat::create([ - 'name' => 'Llama', - 'format' => 'llama', - 'langcode' => 'es', - 'filters' => [ - 'filter_html' => [ - 'status' => TRUE, - 'settings' => [ - 'allowed_html' => '

', + if (!FilterFormat::load('llama' . $this->counter)) { + // Create a "Llama" filter format. + $llama_format = FilterFormat::create([ + 'name' => 'Llama', + 'format' => 'llama' . $this->counter, + 'langcode' => 'es', + 'filters' => [ + 'filter_html' => [ + 'status' => TRUE, + 'settings' => [ + 'allowed_html' => '

', + ], ], ], - ], - ]); + ]); - $llama_format->save(); + $llama_format->save(); + } // Create a "Camelids" editor. $camelids = Editor::create([ - 'format' => 'llama', + 'format' => 'llama' . $this->counter, 'editor' => 'ckeditor', ]); $camelids @@ -84,14 +103,14 @@ protected function getExpectedNormalizedEntity() { return [ 'dependencies' => [ 'config' => [ - 'filter.format.llama', + 'filter.format.llama' . $this->counter, ], 'module' => [ 'ckeditor', ], ], 'editor' => 'ckeditor', - 'format' => 'llama', + 'format' => 'llama' . $this->counter, 'image_upload' => [ 'status' => FALSE, 'scheme' => 'public', @@ -158,8 +177,38 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + + $llama_format = FilterFormat::create([ + 'name' => 'Llama', + 'format' => 'llama' . $this->counter, + 'langcode' => 'es', + 'filters' => [ + 'filter_html' => [ + 'status' => TRUE, + 'settings' => [ + 'allowed_html' => '

', + ], + ], + ], + ]); + + $llama_format->save(); + } + return [ + 'format' => 'llama' . $this->counter, + 'editor' => 'ckeditor', + 'langcode' => 'll', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** @@ -178,7 +227,11 @@ protected function getExpectedUnauthorizedAccessMessage($method) { return parent::getExpectedUnauthorizedAccessMessage($method); } - return "The 'administer filters' permission is required."; + if ($method !== 'DELETE') { + return "The 'administer filters' permission is required."; + } + + return parent::getExpectedUnauthorizedAccessMessage($method); } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index d552e36..1c55419 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -798,12 +798,13 @@ public function testPost() { // DX: 422 when invalid entity: multiple values sent for single-value field. $response = $this->request('POST', $url, $request_options); if ($this->entity instanceof FieldableEntityInterface) { - $label_field = $this->entity->getEntityType()->hasKey('label') ? $this->entity->getEntityType()->getKey('label') : static::$labelFieldName; + $label_field = static::$labelFieldName ?: $this->entity->getEntityType()->getKey('label'); $label_field_capitalized = $this->entity->getFieldDefinition($label_field)->getLabel(); $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\n$label_field: $label_field_capitalized: this field cannot hold more than 1 values.\n", $response); } else { - $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nlabel: This value should be of the correct primitive type.\n", $response); + $label = static::$labelFieldName ?: $this->entity->getEntityType()->getKey('label'); + $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\n$label: This value should be of the correct primitive type.\n", $response); } @@ -1042,7 +1043,7 @@ public function testPatch() { // DX: 422 when invalid entity: multiple values sent for single-value field. $response = $this->request('PATCH', $url, $request_options); - $label_field = $this->entity->getEntityType()->hasKey('label') ? $this->entity->getEntityType()->getKey('label') : static::$labelFieldName; + $label_field = static::$labelFieldName ?: $this->entity->getEntityType()->getKey('label'); if ($this->entity instanceof FieldableEntityInterface) { $label_field_capitalized = $this->entity->getFieldDefinition($label_field)->getLabel(); $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\n$label_field: $label_field_capitalized: this field cannot hold more than 1 values.\n", $response); @@ -1327,7 +1328,7 @@ protected function getEntityResourcePostUrl() { */ protected function makeNormalizationInvalid(array $normalization) { // Add a second label to this entity to make it invalid. - $label_field = $this->entity->getEntityType()->hasKey('label') ? $this->entity->getEntityType()->getKey('label') : static::$labelFieldName; + $label_field = static::$labelFieldName ?: $this->entity->getEntityType()->getKey('label'); if ($this->entity instanceof FieldableEntityInterface) { $normalization[$label_field][1]['value'] = 'Second Title'; } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php index f43d877..fbd4dbb 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php @@ -26,6 +26,18 @@ protected static $patchProtectedFieldNames = []; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'camelids1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\entity_test\Entity\EntityTestBundle */ protected $entity; @@ -42,7 +54,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $entity_test_bundle = EntityTestBundle::create([ - 'id' => 'camelids', + 'id' => 'camelids' . $this->counter, 'label' => 'Camelids', 'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.', ]); @@ -58,7 +70,7 @@ protected function getExpectedNormalizedEntity() { return [ 'dependencies' => [], 'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.', - 'id' => 'camelids', + 'id' => 'camelids' . $this->counter, 'label' => 'Camelids', 'langcode' => 'en', 'status' => TRUE, @@ -69,8 +81,21 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'camelids' . $this->counter, + 'label' => 'Camelids', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/FieldConfig/FieldConfigResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/FieldConfig/FieldConfigResourceTestBase.php index 05c05f4..c761259 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/FieldConfig/FieldConfigResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/FieldConfig/FieldConfigResourceTestBase.php @@ -12,7 +12,7 @@ /** * {@inheritdoc} */ - public static $modules = ['field', 'node']; + public static $modules = ['field', 'node', 'rest_test_access_helper']; /** * {@inheritdoc} @@ -20,6 +20,18 @@ protected static $entityTypeId = 'field_config'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'node.camelids.field_llama1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\field\FieldConfigInterface */ protected $entity; @@ -35,14 +47,16 @@ protected function setUpAuthorization($method) { * {@inheritdoc} */ protected function createEntity() { - $camelids = NodeType::create([ - 'name' => 'Camelids', - 'type' => 'camelids', - ]); - $camelids->save(); + if (!NodeType::load('camelids')) { + $camelids = NodeType::create([ + 'name' => 'Camelids', + 'type' => 'camelids', + ]); + $camelids->save(); + } $field_storage = FieldStorageConfig::create([ - 'field_name' => 'field_llama', + 'field_name' => 'field_llama' . $this->counter, 'entity_type' => 'node', 'type' => 'text', ]); @@ -51,6 +65,7 @@ protected function createEntity() { $entity = FieldConfig::create([ 'field_storage' => $field_storage, 'bundle' => 'camelids', + 'label' => 'llama', ]); $entity->save(); @@ -67,7 +82,7 @@ protected function getExpectedNormalizedEntity() { 'default_value_callback' => '', 'dependencies' => [ 'config' => [ - 'field.storage.node.field_llama', + 'field.storage.node.field_llama' . $this->counter, 'node.type.camelids', ], 'module' => [ @@ -76,10 +91,10 @@ protected function getExpectedNormalizedEntity() { ], 'description' => '', 'entity_type' => 'node', - 'field_name' => 'field_llama', + 'field_name' => 'field_llama' . $this->counter, 'field_type' => 'text', - 'id' => 'node.camelids.field_llama', - 'label' => 'field_llama', + 'id' => 'node.camelids.field_llama' . $this->counter, + 'label' => 'llama', 'langcode' => 'en', 'required' => FALSE, 'settings' => [], @@ -92,8 +107,29 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + + FieldStorageConfig::create([ + 'field_name' => 'field_llama' . $this->counter, + 'entity_type' => 'node', + 'type' => 'text', + ])->save(); + } + return [ + 'entity_type' => 'node', + 'field_name' => 'field_llama' . $this->counter, + 'bundle' => 'camelids', + 'label' => 'llama', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/FieldStorageConfig/FieldStorageConfigResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/FieldStorageConfig/FieldStorageConfigResourceTestBase.php index aafc253..baf7eb6 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/FieldStorageConfig/FieldStorageConfigResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/FieldStorageConfig/FieldStorageConfigResourceTestBase.php @@ -10,7 +10,7 @@ /** * {@inheritdoc} */ - public static $modules = ['node']; + public static $modules = ['node', 'rest_test_access_helper']; /** * {@inheritdoc} @@ -18,6 +18,23 @@ protected static $entityTypeId = 'field_storage_config'; /** + * {@inheritdoc} + */ + protected static $labelFieldName = 'langcode'; + + /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'node.true_llama1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\field\FieldConfigStorage */ protected $entity; @@ -34,7 +51,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $field_storage = FieldStorageConfig::create([ - 'field_name' => 'true_llama', + 'field_name' => 'true_llama' . $this->counter, 'entity_type' => 'node', 'type' => 'boolean', ]); @@ -53,8 +70,8 @@ protected function getExpectedNormalizedEntity() { 'module' => ['node'], ], 'entity_type' => 'node', - 'field_name' => 'true_llama', - 'id' => 'node.true_llama', + 'field_name' => 'true_llama' . $this->counter, + 'id' => 'node.true_llama' . $this->counter, 'indexes' => [], 'langcode' => 'en', 'locked' => FALSE, @@ -71,8 +88,23 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'field_name' => 'true_llama' . $this->counter, + 'entity_type' => 'node', + 'type' => 'boolean', + 'langcode' => 'true_llama' . $this->counter, + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** @@ -83,13 +115,7 @@ protected function getExpectedUnauthorizedAccessMessage($method) { return parent::getExpectedUnauthorizedAccessMessage($method); } - switch ($method) { - case 'GET': - return "The 'administer node fields' permission is required."; - - default: - return parent::getExpectedUnauthorizedAccessMessage($method); - } + return "The 'administer node fields' permission is required."; } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatResourceTestBase.php index 4d65e00..763d811 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/FilterFormat/FilterFormatResourceTestBase.php @@ -10,7 +10,7 @@ /** * {@inheritdoc} */ - public static $modules = []; + public static $modules = ['rest_test_access_helper']; /** * {@inheritdoc} @@ -18,6 +18,23 @@ protected static $entityTypeId = 'filter_format'; /** + * {@inheritdoc} + */ + protected static $labelFieldName = 'name'; + + /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'pablo1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\filter\FilterFormatInterface */ protected $entity; @@ -34,8 +51,8 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $pablo_format = FilterFormat::create([ - 'name' => 'Pablo Piccasso', - 'format' => 'pablo', + 'name' => 'Pablo Picasso', + 'format' => 'pablo' . $this->counter, 'langcode' => 'es', 'filters' => [ 'filter_html' => [ @@ -69,9 +86,9 @@ protected function getExpectedNormalizedEntity() { ], ], ], - 'format' => 'pablo', + 'format' => 'pablo' . $this->counter, 'langcode' => 'es', - 'name' => 'Pablo Piccasso', + 'name' => 'Pablo Picasso', 'status' => TRUE, 'uuid' => $this->entity->uuid(), 'weight' => 0, @@ -81,8 +98,35 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'name' => 'Pablo Picasso', + 'format' => 'pablo' . $this->counter, + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { + return parent::getExpectedUnauthorizedAccessMessage($method); + } + + if ($method === 'DELETE') { + return "You are not authorized to delete this filter_format entity."; + } + + return parent::getExpectedUnauthorizedAccessMessage($method); + } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ImageStyle/ImageStyleResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ImageStyle/ImageStyleResourceTestBase.php index ccd68d9..787a37a 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ImageStyle/ImageStyleResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ImageStyle/ImageStyleResourceTestBase.php @@ -21,6 +21,18 @@ protected static $entityTypeId = 'image_style'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'camelids1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * The ImageStyle entity. * * @var \Drupal\image\ImageStyleInterface @@ -47,7 +59,7 @@ protected function setUpAuthorization($method) { protected function createEntity() { // Create a "Camelids" image style. $camelids = ImageStyle::create([ - 'name' => 'camelids', + 'name' => 'camelids' . $this->counter, 'label' => 'Camelids', ]); @@ -86,7 +98,7 @@ protected function getExpectedNormalizedEntity() { ], 'label' => 'Camelids', 'langcode' => 'en', - 'name' => 'camelids', + 'name' => 'camelids' . $this->counter, 'status' => TRUE, 'uuid' => $this->entity->uuid(), ]; @@ -95,8 +107,21 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'name' => 'camelids' . $this->counter, + 'label' => 'Camelids', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/MediaType/MediaTypeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/MediaType/MediaTypeResourceTestBase.php index ac72737..1278c8f 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/MediaType/MediaTypeResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/MediaType/MediaTypeResourceTestBase.php @@ -18,6 +18,18 @@ protected static $entityTypeId = 'media_type'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'camelids1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\media\MediaTypeInterface */ protected $entity; @@ -36,7 +48,7 @@ protected function createEntity() { // Create a "Camelids" media type. $camelids = MediaType::create([ 'name' => 'Camelids', - 'id' => 'camelids', + 'id' => 'camelids' . $this->counter, 'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.', 'source' => 'file', ]); @@ -54,7 +66,7 @@ protected function getExpectedNormalizedEntity() { 'dependencies' => [], 'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.', 'field_map' => [], - 'id' => 'camelids', + 'id' => 'camelids' . $this->counter, 'label' => NULL, 'langcode' => 'en', 'new_revision' => FALSE, @@ -71,8 +83,23 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'name' => 'Camelids', + 'id' => 'camelids' . $this->counter, + 'label' => 'camelids', + 'source' => 'file', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Menu/MenuResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Menu/MenuResourceTestBase.php index dd7f552..9dfffd0 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Menu/MenuResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Menu/MenuResourceTestBase.php @@ -18,6 +18,18 @@ protected static $entityTypeId = 'menu'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'menu1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\system\MenuInterface */ protected $entity; @@ -34,7 +46,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $menu = Menu::create([ - 'id' => 'menu', + 'id' => 'menu' . $this->counter, 'label' => 'Menu', 'description' => 'Menu', ]); @@ -50,7 +62,7 @@ protected function getExpectedNormalizedEntity() { return [ 'dependencies' => [], 'description' => 'Menu', - 'id' => 'menu', + 'id' => 'menu' . $this->counter, 'label' => 'Menu', 'langcode' => 'en', 'locked' => FALSE, @@ -62,8 +74,21 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'menu' . $this->counter, + 'label' => 'Menu', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/NodeType/NodeTypeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/NodeType/NodeTypeResourceTestBase.php index c374bfb..52a1e0e 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/NodeType/NodeTypeResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/NodeType/NodeTypeResourceTestBase.php @@ -21,6 +21,18 @@ protected static $entityTypeId = 'node_type'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'camelids1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * The NodeType entity. * * @var \Drupal\node\NodeTypeInterface @@ -41,7 +53,7 @@ protected function createEntity() { // Create a "Camelids" node type. $camelids = NodeType::create([ 'name' => 'Camelids', - 'type' => 'camelids', + 'type' => 'camelids' . $this->counter, 'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.', ]); @@ -64,7 +76,7 @@ protected function getExpectedNormalizedEntity() { 'new_revision' => TRUE, 'preview_mode' => 1, 'status' => TRUE, - 'type' => 'camelids', + 'type' => 'camelids' . $this->counter, 'uuid' => $this->entity->uuid(), ]; } @@ -72,8 +84,21 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'name' => 'Camelids', + 'type' => 'camelids' . $this->counter, + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** @@ -84,7 +109,11 @@ protected function getExpectedUnauthorizedAccessMessage($method) { return parent::getExpectedUnauthorizedAccessMessage($method); } - return "The 'access content' permission is required."; + if ($method === 'GET') { + return "The 'access content' permission is required."; + } + + return "The 'administer content types' permission is required."; } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/RdfMapping/RdfMappingResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/RdfMapping/RdfMappingResourceTestBase.php index c826be0..2e2aa8b 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/RdfMapping/RdfMappingResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/RdfMapping/RdfMappingResourceTestBase.php @@ -19,6 +19,23 @@ protected static $entityTypeId = 'rdf_mapping'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'node.camelids1'; + + /** + * {@inheritdoc} + */ + protected static $labelFieldName = 'langcode'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\rdf\RdfMappingInterface */ protected $entity; @@ -34,18 +51,20 @@ protected function setUpAuthorization($method) { * {@inheritdoc} */ protected function createEntity() { - // Create a "Camelids" node type. - $camelids = NodeType::create([ - 'name' => 'Camelids', - 'type' => 'camelids', - ]); + if (!NodeType::load('camelids' . $this->counter)) { + // Create a "Camelids" node type. + $camelids = NodeType::create([ + 'name' => 'Camelids', + 'type' => 'camelids' . $this->counter, + ]); - $camelids->save(); + $camelids->save(); + } // Create the RDF mapping. $llama = RdfMapping::create([ 'targetEntityType' => 'node', - 'bundle' => 'camelids', + 'bundle' => 'camelids' . $this->counter, ]); $llama->setBundleMapping([ 'types' => ['sioc:Item', 'foaf:Document'], @@ -68,10 +87,10 @@ protected function createEntity() { */ protected function getExpectedNormalizedEntity() { return [ - 'bundle' => 'camelids', + 'bundle' => 'camelids' . $this->counter, 'dependencies' => [ 'config' => [ - 'node.type.camelids', + 'node.type.camelids' . $this->counter, ], 'module' => [ 'node', @@ -94,7 +113,7 @@ protected function getExpectedNormalizedEntity() { ], ], ], - 'id' => 'node.camelids', + 'id' => 'node.camelids' . $this->counter, 'langcode' => 'en', 'status' => TRUE, 'targetEntityType' => 'node', @@ -109,8 +128,29 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + + $camelids = NodeType::create([ + 'name' => 'Camelids', + 'type' => 'camelids' . $this->counter, + ]); + + $camelids->save(); + } + return [ + 'targetEntityType' => 'node', + 'bundle' => 'camelids' . $this->counter, + 'langcode' => 'll', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ResponsiveImageStyle/ResponsiveImageStyleResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ResponsiveImageStyle/ResponsiveImageStyleResourceTestBase.php index 4221314..174b7e0 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ResponsiveImageStyle/ResponsiveImageStyleResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ResponsiveImageStyle/ResponsiveImageStyleResourceTestBase.php @@ -28,6 +28,18 @@ protected $entity; /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'camelids1'; + + /** * The effect UUID. * * @var string @@ -47,7 +59,7 @@ protected function setUpAuthorization($method) { protected function createEntity() { // Create a "Camelids" responsive image style. $camelids = ResponsiveImageStyle::create([ - 'id' => 'camelids', + 'id' => 'camelids' . $this->counter, 'label' => 'Camelids', ]); $camelids->setBreakpointGroup('test_group'); @@ -84,7 +96,7 @@ protected function getExpectedNormalizedEntity() { ], ], 'fallback_image_style' => 'fallback', - 'id' => 'camelids', + 'id' => 'camelids' . $this->counter, 'image_style_mappings' => [ 0 => [ 'breakpoint_id' => 'test_breakpoint', @@ -115,8 +127,21 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'camelids' . $this->counter, + 'label' => 'Dramallama', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/RestResourceConfig/RestResourceConfigResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/RestResourceConfig/RestResourceConfigResourceTestBase.php index a19e2ef..4b6c79d 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/RestResourceConfig/RestResourceConfigResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/RestResourceConfig/RestResourceConfigResourceTestBase.php @@ -18,6 +18,23 @@ protected static $entityTypeId = 'rest_resource_config'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'llama1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** + * {@inheritdoc} + */ + protected static $labelFieldName = 'langcode'; + + /** * @var \Drupal\rest\RestResourceConfigInterface */ protected $entity; @@ -34,7 +51,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $rest_resource_config = RestResourceConfig::create([ - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'plugin_id' => 'dblog', 'granularity' => 'method', 'configuration' => [ @@ -68,7 +85,7 @@ protected function getExpectedNormalizedEntity() { 'user', ], ], - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'plugin_id' => 'dblog', 'granularity' => 'method', 'configuration' => [ @@ -87,8 +104,33 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'llama' . $this->counter, + 'plugin_id' => 'dblog', + 'langcode' => 'en', + 'granularity' => 'method', + 'configuration' => [ + 'GET' => [ + 'supported_formats' => [ + 'json', + ], + 'supported_auth' => [ + 'cookie', + ], + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Role/RoleResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Role/RoleResourceTestBase.php index ee719c4..fbd1aa6 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Role/RoleResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Role/RoleResourceTestBase.php @@ -18,6 +18,18 @@ protected static $entityTypeId = 'user_role'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'llama1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\user\RoleInterface */ protected $entity; @@ -34,7 +46,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $role = Role::create([ - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'name' => $this->randomString(), ]); $role->save(); @@ -52,7 +64,7 @@ protected function getExpectedNormalizedEntity() { 'langcode' => 'en', 'status' => TRUE, 'dependencies' => [], - 'id' => 'llama', + 'id' => 'llama' . $this->counter, 'label' => NULL, 'is_admin' => NULL, 'permissions' => [], @@ -62,8 +74,22 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'llama' . $this->counter, + 'name' => $this->randomString(), + 'label' => 'llama', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/SearchPage/SearchPageResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/SearchPage/SearchPageResourceTestBase.php index e81993f..c78f652 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/SearchPage/SearchPageResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/SearchPage/SearchPageResourceTestBase.php @@ -18,6 +18,18 @@ protected static $entityTypeId = 'search_page'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'hinode_search1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\search\SearchPageInterface */ protected $entity; @@ -44,10 +56,10 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $search_page = SearchPage::create([ - 'id' => 'hinode_search', + 'id' => 'hinode_search' . $this->counter, 'plugin' => 'node_search', 'label' => 'Search of magnetic activity of the Sun', - 'path' => 'sun', + 'path' => 'sun' . $this->counter, ]); $search_page->save(); return $search_page; @@ -64,10 +76,10 @@ protected function getExpectedNormalizedEntity() { 'dependencies' => [ 'module' => ['node'], ], - 'id' => 'hinode_search', + 'id' => 'hinode_search' . $this->counter, 'label' => 'Search of magnetic activity of the Sun', 'langcode' => 'en', - 'path' => 'sun', + 'path' => 'sun' . $this->counter, 'plugin' => 'node_search', 'status' => TRUE, 'uuid' => $this->entity->uuid(), @@ -78,8 +90,23 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'hinode_search' . $this->counter, + 'plugin' => 'node_search', + 'label' => 'Search of magnetic activity of the Sun', + 'path' => 'sun' . $this->counter, + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetResourceTestBase.php index 97ae1a6..dae19fc 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetResourceTestBase.php @@ -33,6 +33,18 @@ protected $entity; /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'llama_set1'; + + /** * {@inheritdoc} */ protected function setUpAuthorization($method) { @@ -42,10 +54,10 @@ protected function setUpAuthorization($method) { break; case 'POST': - case 'PATCH': $this->grantPermissionsToTestedRole(['access shortcuts', 'customize shortcut links']); break; + case 'PATCH': case 'DELETE': $this->grantPermissionsToTestedRole(['administer shortcuts']); break; @@ -57,7 +69,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $set = ShortcutSet::create([ - 'id' => 'llama_set', + 'id' => 'llama_set' . $this->counter, 'label' => 'Llama Set', ]); $set->save(); @@ -69,7 +81,7 @@ protected function createEntity() { */ protected function getExpectedNormalizedEntity() { return [ - 'id' => 'llama_set', + 'id' => 'llama_set' . $this->counter, 'uuid' => $this->entity->uuid(), 'label' => 'Llama Set', 'status' => TRUE, @@ -81,8 +93,37 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'llama_set' . $this->counter, + 'label' => 'Dramallama', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { + return parent::getExpectedUnauthorizedAccessMessage($method); + } + + switch ($method) { + case 'POST': + return "The following permissions are required: 'access shortcuts' AND 'customize shortcut links'."; + + default: + return parent::getExpectedUnauthorizedAccessMessage($method); + } + } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Tour/TourResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Tour/TourResourceTestBase.php index 294e3ee..e828755 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Tour/TourResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Tour/TourResourceTestBase.php @@ -18,6 +18,18 @@ protected static $entityTypeId = 'tour'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'tour-llama1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\tour\TourInterface */ protected $entity; @@ -26,7 +38,13 @@ * {@inheritdoc} */ protected function setUpAuthorization($method) { - $this->grantPermissionsToTestedRole(['access tour']); + + if ($method === 'GET') { + $this->grantPermissionsToTestedRole(['access tour']); + } + else { + $this->grantPermissionsToTestedRole(['administer site configuration']); + } } /** @@ -34,7 +52,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $tour = Tour::create([ - 'id' => 'tour-llama', + 'id' => 'tour-llama' . $this->counter, 'label' => 'Llama tour', 'langcode' => 'en', 'module' => 'tour', @@ -67,7 +85,7 @@ protected function createEntity() { protected function getExpectedNormalizedEntity() { return [ 'dependencies' => [], - 'id' => 'tour-llama', + 'id' => 'tour-llama' . $this->counter, 'label' => 'Llama tour', 'langcode' => 'en', 'module' => 'tour', @@ -96,8 +114,21 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'tour-llama' . $this->counter, + 'label' => 'Llama tour', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** @@ -117,7 +148,11 @@ protected function getExpectedUnauthorizedAccessMessage($method) { return parent::getExpectedUnauthorizedAccessMessage($method); } - return "The following permissions are required: 'access tour' OR 'administer site configuration'."; + if ($method === 'GET') { + return "The following permissions are required: 'access tour' OR 'administer site configuration'."; + } + + return "The 'administer site configuration' permission is required."; } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/View/ViewResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/View/ViewResourceTestBase.php index 26ec7bb..d160e71 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/View/ViewResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/View/ViewResourceTestBase.php @@ -18,6 +18,18 @@ protected static $entityTypeId = 'view'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'test_rest1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\views\ViewEntityInterface */ protected $entity; @@ -34,7 +46,7 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $view = View::create([ - 'id' => 'test_rest', + 'id' => 'test_rest' . $this->counter, 'label' => 'Test REST', ]); $view->save(); @@ -70,7 +82,7 @@ protected function getExpectedNormalizedEntity() { ], ], ], - 'id' => 'test_rest', + 'id' => 'test_rest' . $this->counter, 'label' => 'Test REST', 'langcode' => 'en', 'module' => 'views', @@ -83,8 +95,21 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'test_rest' . $this->counter, + 'label' => 'Test REST', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Vocabulary/VocabularyJsonAnonTest.php b/core/modules/rest/tests/src/Functional/EntityResource/Vocabulary/VocabularyJsonAnonTest.php index 40f26ab..9f222ac 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Vocabulary/VocabularyJsonAnonTest.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Vocabulary/VocabularyJsonAnonTest.php @@ -21,12 +21,4 @@ class VocabularyJsonAnonTest extends VocabularyResourceTestBase { */ protected static $mimeType = 'application/json'; - /** - * Disable the GET test coverage due to bug in taxonomy module. - * @todo Fix in https://www.drupal.org/node/2805281: remove this override. - */ - public function testGet() { - $this->markTestSkipped(); - } - } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Vocabulary/VocabularyResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Vocabulary/VocabularyResourceTestBase.php index abada74..f07ef36 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Vocabulary/VocabularyResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Vocabulary/VocabularyResourceTestBase.php @@ -18,6 +18,18 @@ protected static $entityTypeId = 'taxonomy_vocabulary'; /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'llama1'; + + /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** * @var \Drupal\taxonomy\VocabularyInterface */ protected $entity; @@ -35,7 +47,7 @@ protected function setUpAuthorization($method) { protected function createEntity() { $vocabulary = Vocabulary::create([ 'name' => 'Llama', - 'vid' => 'llama', + 'vid' => 'llama' . $this->counter, ]); $vocabulary->save(); @@ -48,7 +60,7 @@ protected function createEntity() { protected function getExpectedNormalizedEntity() { return [ 'uuid' => $this->entity->uuid(), - 'vid' => 'llama', + 'vid' => 'llama' . $this->counter, 'langcode' => 'en', 'status' => TRUE, 'dependencies' => [], @@ -62,8 +74,21 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'name' => 'Llama', + 'vid' => 'llama' . $this->counter, + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } } diff --git a/core/modules/workflows/tests/src/Functional/Rest/WorkflowResourceTestBase.php b/core/modules/workflows/tests/src/Functional/Rest/WorkflowResourceTestBase.php index ce796a4..10ab23f 100644 --- a/core/modules/workflows/tests/src/Functional/Rest/WorkflowResourceTestBase.php +++ b/core/modules/workflows/tests/src/Functional/Rest/WorkflowResourceTestBase.php @@ -24,6 +24,18 @@ protected static $entityTypeId = 'workflow'; /** + * Counter used internally to have deterministic IDs. + * + * @var int + */ + protected $counter = 0; + + /** + * {@inheritdoc} + */ + protected static $firstCreatedEntityId = 'rest_workflow1'; + + /** * {@inheritdoc} */ protected static $patchProtectedFieldNames = []; @@ -47,8 +59,8 @@ protected function setUpAuthorization($method) { */ protected function createEntity() { $workflow = Workflow::create([ - 'id' => 'rest_workflow', - 'label' => 'REST Worklow', + 'id' => 'rest_workflow' . $this->counter, + 'label' => 'REST Workflow', 'type' => 'workflow_type_complex_test', ]); $workflow @@ -73,8 +85,8 @@ protected function getExpectedNormalizedEntity() { 'workflow_type_test', ], ], - 'id' => 'rest_workflow', - 'label' => 'REST Worklow', + 'id' => 'rest_workflow' . $this->counter, + 'label' => 'REST Workflow', 'langcode' => 'en', 'status' => TRUE, 'type' => 'workflow_type_complex_test', @@ -100,8 +112,22 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { - // @todo Update in https://www.drupal.org/node/2300677. + protected function getNormalizedPostEntity($count_up = TRUE) { + if ($count_up) { + $this->counter++; + } + return [ + 'id' => 'rest_workflow' . $this->counter, + 'label' => 'Dramallama', + 'type' => 'workflow_type_complex_test', + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPatchEntity() { + return $this->getNormalizedPostEntity(FALSE); } }