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' => '