core/modules/rest/config/install/rest.settings.yml | 7 - core/modules/rest/config/schema/rest.schema.yml | 14 - core/modules/rest/rest.api.php | 57 -- core/modules/rest/rest.install | 96 ---- core/modules/rest/rest.module | 27 - core/modules/rest/rest.post_update.php | 63 --- core/modules/rest/rest.routing.yml | 9 - core/modules/rest/rest.services.yml | 15 - .../src/EventSubscriber/RestConfigSubscriber.php | 53 -- .../ConfigurableLinkManagerInterface.php | 13 - core/modules/rest/src/LinkManager/LinkManager.php | 13 - .../rest/src/LinkManager/LinkManagerBase.php | 13 - .../rest/src/LinkManager/LinkManagerInterface.php | 13 - .../rest/src/LinkManager/RelationLinkManager.php | 13 - .../LinkManager/RelationLinkManagerInterface.php | 13 - .../rest/src/LinkManager/TypeLinkManager.php | 13 - .../src/LinkManager/TypeLinkManagerInterface.php | 13 - .../PathProcessorEntityResourceBC.php | 55 -- core/modules/rest/src/Plugin/ResourceBase.php | 8 - .../src/Plugin/rest/resource/EntityResource.php | 10 +- .../rest/src/Plugin/views/display/RestExport.php | 18 - core/modules/rest/src/RequestHandler.php | 41 +- core/modules/rest/src/RestServiceProvider.php | 51 -- core/modules/rest/src/Tests/RESTTestBase.php | 626 --------------------- .../Update/RestExportAuthCorrectionUpdateTest.php | 36 -- ....rest-rest_post_update_resource_granularity.php | Bin 5199 -> 0 bytes .../update/drupal-8.rest-rest_update_8201.php | 59 -- .../update/drupal-8.rest-rest_update_8203.php | 58 -- .../rest-export-with-authentication-correction.php | 63 --- .../update/rest-export-with-authentication.php | 65 --- .../rest.resource.entity.comment_2721595.yml | 32 -- .../update/rest.resource.entity.node_2721595.yml | 29 - .../update/rest.resource.entity.user_2721595.yml | 32 -- .../BcTimestampNormalizerUnixTestTrait.php | 43 -- .../BaseFieldOverrideResourceTestBase.php | 4 - .../EntityResource/Block/BlockResourceTestBase.php | 4 - .../BlockContent/BlockContentResourceTestBase.php | 16 +- .../Comment/CommentResourceTestBase.php | 17 +- .../ContactForm/ContactFormResourceTestBase.php | 6 - .../Editor/EditorResourceTestBase.php | 4 - .../EntityFormDisplayResourceTestBase.php | 4 - .../EntityResource/EntityResourceTestBase.php | 154 ----- .../EntityTest/EntityTestResourceTestBase.php | 12 +- .../EntityTestBundleResourceTestBase.php | 2 - .../EntityTestLabelResourceTestBase.php | 12 +- .../EntityViewDisplayResourceTestBase.php | 4 - .../EntityResource/Feed/FeedResourceTestBase.php | 22 +- .../FieldConfig/FieldConfigResourceTestBase.php | 4 - .../FieldStorageConfigResourceTestBase.php | 4 - .../ImageStyle/ImageStyleResourceTestBase.php | 4 - .../EntityResource/Item/ItemResourceTestBase.php | 12 +- .../EntityResource/Media/MediaResourceTestBase.php | 21 +- .../MenuLinkContentResourceTestBase.php | 12 +- .../Message/MessageResourceTestBase.php | 4 - .../EntityResource/Node/NodeResourceTestBase.php | 22 +- .../NodeType/NodeTypeResourceTestBase.php | 4 - .../ResponsiveImageStyleResourceTestBase.php | 4 - .../SearchPage/SearchPageResourceTestBase.php | 4 - .../Shortcut/ShortcutResourceTestBase.php | 4 - .../EntityResource/Term/TermResourceTestBase.php | 12 +- .../EntityResource/Tour/TourResourceTestBase.php | 4 - .../EntityResource/User/UserResourceTestBase.php | 17 +- .../rest/tests/src/Functional/ResourceTestBase.php | 5 +- .../Update/EntityResourcePermissionsUpdateTest.php | 56 -- .../Update/ResourceGranularityUpdateTest.php | 71 --- .../Update/RestConfigurationEntitiesUpdateTest.php | 65 --- .../Functional/Update/RestExportAuthUpdateTest.php | 36 -- .../tests/src/Kernel/EntitySerializationTest.php | 7 +- 68 files changed, 89 insertions(+), 2215 deletions(-) diff --git a/core/modules/rest/config/install/rest.settings.yml b/core/modules/rest/config/install/rest.settings.yml deleted file mode 100644 index 8f70c69..0000000 --- a/core/modules/rest/config/install/rest.settings.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Before Drupal 8.2, EntityResource used permissions as well as the entity -# access system for access checking. This was confusing, and it only did this -# for historical reasons. New Drupal installations opt out from this by default -# (hence this is set to false), existing installations opt in to it. -# @see rest_update_8203() -# @see https://www.drupal.org/node/2664780 -bc_entity_resource_permissions: false diff --git a/core/modules/rest/config/schema/rest.schema.yml b/core/modules/rest/config/schema/rest.schema.yml index 98b35ae..467ae5b 100644 --- a/core/modules/rest/config/schema/rest.schema.yml +++ b/core/modules/rest/config/schema/rest.schema.yml @@ -1,17 +1,3 @@ -# Schema for the configuration files of the REST module. -rest.settings: - type: config_object - label: 'REST settings' - mapping: - # @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. - # @see https://www.drupal.org/node/2830467 - link_domain: - type: string - label: 'Domain of the relation' - bc_entity_resource_permissions: - type: boolean - label: 'Whether the pre Drupal 8.2.x behavior of having permissions for EntityResource is enabled or not.' - # Method-level granularity of REST resource configuration. rest_resource.method: type: mapping diff --git a/core/modules/rest/rest.api.php b/core/modules/rest/rest.api.php index 6c09bbf..2f3f6ee 100644 --- a/core/modules/rest/rest.api.php +++ b/core/modules/rest/rest.api.php @@ -29,62 +29,5 @@ function hook_rest_resource_alter(&$definitions) { } /** - * Alter the REST type URI. - * - * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use - * hook_serialization_type_uri_alter() instead. This exists solely for BC. - * - * @see https://www.drupal.org/node/2830467 - * - * Modules may wish to alter the type URI generated for a resource based on the - * context of the serializer/normalizer operation. - * - * @param string $uri - * The URI to alter. - * @param array $context - * The context from the serializer/normalizer operation. - * - * @see \Symfony\Component\Serializer\SerializerInterface::serialize() - * @see \Symfony\Component\Serializer\SerializerInterface::deserialize() - * @see \Symfony\Component\Serializer\NormalizerInterface::normalize() - * @see \Symfony\Component\Serializer\DenormalizerInterface::denormalize() - */ -function hook_rest_type_uri_alter(&$uri, $context = []) { - if ($context['mymodule'] == TRUE) { - $base = \Drupal::config('serialization.settings')->get('link_domain'); - $uri = str_replace($base, 'http://mymodule.domain', $uri); - } -} - - -/** - * Alter the REST relation URI. - * - * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Use - * hook_serialization_relation_uri_alter() instead. This exists solely for BC. - * - * @see https://www.drupal.org/node/2830467 - * - * Modules may wish to alter the relation URI generated for a resource based on - * the context of the serializer/normalizer operation. - * - * @param string $uri - * The URI to alter. - * @param array $context - * The context from the serializer/normalizer operation. - * - * @see \Symfony\Component\Serializer\SerializerInterface::serialize() - * @see \Symfony\Component\Serializer\SerializerInterface::deserialize() - * @see \Symfony\Component\Serializer\NormalizerInterface::normalize() - * @see \Symfony\Component\Serializer\DenormalizerInterface::denormalize() - */ -function hook_rest_relation_uri_alter(&$uri, $context = []) { - if ($context['mymodule'] == TRUE) { - $base = \Drupal::config('serialization.settings')->get('link_domain'); - $uri = str_replace($base, 'http://mymodule.domain', $uri); - } -} - -/** * @} End of "addtogroup hooks". */ diff --git a/core/modules/rest/rest.install b/core/modules/rest/rest.install index 2113b0b..c2d9412 100644 --- a/core/modules/rest/rest.install +++ b/core/modules/rest/rest.install @@ -24,99 +24,3 @@ function rest_requirements($phase) { } return $requirements; } - -/** - * Install the REST config entity type and fix old settings-based config. - * - * @see rest_post_update_create_rest_resource_config_entities() - */ -function rest_update_8201() { - \Drupal::entityDefinitionUpdateManager()->installEntityType(new ConfigEntityType([ - 'id' => 'rest_resource_config', - 'label' => new TranslatableMarkup('REST resource configuration'), - 'config_prefix' => 'resource', - 'admin_permission' => 'administer rest resources', - 'label_callback' => 'getLabelFromPlugin', - 'entity_keys' => ['id' => 'id'], - 'config_export' => [ - 'id', - 'plugin_id', - 'granularity', - 'configuration', - ], - ])); - \Drupal::state()->set('rest_update_8201_resources', \Drupal::config('rest.settings')->get('resources')); - \Drupal::configFactory()->getEditable('rest.settings') - ->clear('resources') - ->save(); -} - -/** - * Re-save all views with a REST display to add new auth defaults. - */ -function rest_update_8202() { - $config_factory = \Drupal::configFactory(); - foreach ($config_factory->listAll('views.view.') as $view_config_name) { - $save = FALSE; - $view = $config_factory->getEditable($view_config_name); - $displays = $view->get('display'); - foreach ($displays as $display_name => &$display) { - if ($display['display_plugin'] == 'rest_export') { - if (!isset($display['display_options']['auth'])) { - $display['display_options']['auth'] = []; - $save = TRUE; - } - } - } - if ($save) { - $view->set('display', $displays); - $view->save(TRUE); - } - } -} - -/** - * Enable BC for EntityResource: continue to use permissions. - */ -function rest_update_8203() { - $config_factory = \Drupal::configFactory(); - $rest_settings = $config_factory->getEditable('rest.settings'); - $rest_settings->set('bc_entity_resource_permissions', TRUE) - ->save(TRUE); -} - -/** - * Ensure the right REST authentication method is used. - * - * This fixes the bug in https://www.drupal.org/node/2825204. - */ -function rest_update_8401() { - $config_factory = \Drupal::configFactory(); - $auth_providers = \Drupal::service('authentication_collector')->getSortedProviders(); - $process_auth = function ($auth_option) use ($auth_providers) { - foreach ($auth_providers as $provider_id => $provider_data) { - // The provider belongs to the module that declares it as a service. - if (strtok($provider_data->_serviceId, '.') === $auth_option) { - return $provider_id; - } - } - - return $auth_option; - }; - - foreach ($config_factory->listAll('views.view.') as $view_config_name) { - $save = FALSE; - $view = $config_factory->getEditable($view_config_name); - $displays = $view->get('display'); - foreach ($displays as $display_name => $display) { - if ('rest_export' === $display['display_plugin'] && !empty($display['display_options']['auth'])) { - $displays[$display_name]['display_options']['auth'] = array_map($process_auth, $display['display_options']['auth']); - $save = TRUE; - } - } - if ($save) { - $view->set('display', $displays); - $view->save(TRUE); - } - } -} diff --git a/core/modules/rest/rest.module b/core/modules/rest/rest.module index ba61a17..3c061af 100644 --- a/core/modules/rest/rest.module +++ b/core/modules/rest/rest.module @@ -28,30 +28,3 @@ function rest_help($route_name, RouteMatchInterface $route_match) { return $output; } } - -/** - * Implements hook_view_presave(). - * - * @see rest_update_8401() - */ -function rest_view_presave(ViewEntityInterface $view) { - // Fix the auth options on import, much like what rest_update_8401() does. - $auth_providers = \Drupal::service('authentication_collector')->getSortedProviders(); - $process_auth = function ($auth_option) use ($auth_providers) { - foreach ($auth_providers as $provider_id => $provider_data) { - // The provider belongs to the module that declares it as a service. - if (strtok($provider_data->_serviceId, '.') === $auth_option) { - return $provider_id; - } - } - - return $auth_option; - }; - - foreach (array_keys($view->get('display')) as $display_id) { - $display = &$view->getDisplay($display_id); - if ($display['display_plugin'] === 'rest_export' && !empty($display['display_options']['auth'])) { - $display['display_options']['auth'] = array_map($process_auth, $display['display_options']['auth']); - } - } -} diff --git a/core/modules/rest/rest.post_update.php b/core/modules/rest/rest.post_update.php deleted file mode 100644 index 6d45178..0000000 --- a/core/modules/rest/rest.post_update.php +++ /dev/null @@ -1,63 +0,0 @@ -get('rest_update_8201_resources', []); - foreach ($resources as $key => $resource) { - $resource = RestResourceConfig::create([ - 'id' => str_replace(':', '.', $key), - 'granularity' => RestResourceConfigInterface::METHOD_GRANULARITY, - 'configuration' => $resource, - ]); - $resource->save(); - } -} - -/** - * Simplify method-granularity REST resource config to resource-granularity. - * - * @see https://www.drupal.org/node/2721595 - */ -function rest_post_update_resource_granularity() { - /** @var \Drupal\rest\RestResourceConfigInterface[] $resource_config_entities */ - $resource_config_entities = RestResourceConfig::loadMultiple(); - - foreach ($resource_config_entities as $resource_config_entity) { - if ($resource_config_entity->get('granularity') === RestResourceConfigInterface::METHOD_GRANULARITY) { - $configuration = $resource_config_entity->get('configuration'); - - $format_and_auth_configuration = []; - foreach (array_keys($configuration) as $method) { - $format_and_auth_configuration['format'][$method] = implode(',', $configuration[$method]['supported_formats']); - $format_and_auth_configuration['auth'][$method] = implode(',', $configuration[$method]['supported_auth']); - } - - // If each method has the same formats and the same authentication - // providers configured, convert it to 'granularity: resource', which has - // a simpler/less verbose configuration. - if (count(array_unique($format_and_auth_configuration['format'])) === 1 && count(array_unique($format_and_auth_configuration['auth'])) === 1) { - $first_method = array_keys($configuration)[0]; - $resource_config_entity->set('configuration', [ - 'methods' => array_keys($configuration), - 'formats' => $configuration[$first_method]['supported_formats'], - 'authentication' => $configuration[$first_method]['supported_auth'] - ]); - $resource_config_entity->set('granularity', RestResourceConfigInterface::RESOURCE_GRANULARITY); - $resource_config_entity->save(); - } - } - } -} diff --git a/core/modules/rest/rest.routing.yml b/core/modules/rest/rest.routing.yml deleted file mode 100644 index ba7dd03..0000000 --- a/core/modules/rest/rest.routing.yml +++ /dev/null @@ -1,9 +0,0 @@ -# @deprecated This route is deprecated, use the system.csrftoken route from the -# system module instead. -# @todo Remove this route in Drupal 9.0.0. -rest.csrftoken: - path: '/rest/session/token' - defaults: - _controller: '\Drupal\system\Controller\CsrfTokenController::csrfToken' - requirements: - _access: 'TRUE' diff --git a/core/modules/rest/rest.services.yml b/core/modules/rest/rest.services.yml index 080a681..5ffb8de 100644 --- a/core/modules/rest/rest.services.yml +++ b/core/modules/rest/rest.services.yml @@ -8,9 +8,6 @@ services: - { name: cache.bin } factory: cache_factory:get arguments: [rest] - # @todo Remove this service in Drupal 9.0.0. - access_check.rest.csrf: - alias: access_check.header.csrf rest.resource_routes: class: Drupal\rest\Routing\ResourceRoutes arguments: ['@plugin.manager.rest', '@entity_type.manager', '@logger.channel.rest'] @@ -26,20 +23,8 @@ services: tags: - { name: event_subscriber } arguments: ['@serializer', '@renderer', '@current_route_match'] - rest.config_subscriber: - class: Drupal\rest\EventSubscriber\RestConfigSubscriber - arguments: ['@router.builder'] - tags: - - { name: event_subscriber } rest.resource.entity.post_route.subscriber: class: \Drupal\rest\EventSubscriber\EntityResourcePostRouteSubscriber arguments: ['@entity_type.manager'] tags: - { name: event_subscriber } - - # @todo Remove in Drupal 9.0.0. - rest.path_processor_entity_resource_bc: - class: \Drupal\rest\PathProcessor\PathProcessorEntityResourceBC - arguments: ['@entity_type.manager'] - tags: - - { name: path_processor_inbound } diff --git a/core/modules/rest/src/EventSubscriber/RestConfigSubscriber.php b/core/modules/rest/src/EventSubscriber/RestConfigSubscriber.php deleted file mode 100644 index d199545..0000000 --- a/core/modules/rest/src/EventSubscriber/RestConfigSubscriber.php +++ /dev/null @@ -1,53 +0,0 @@ -routerBuilder = $router_builder; - } - - /** - * Informs the router builder a rebuild is needed when necessary. - * - * @param \Drupal\Core\Config\ConfigCrudEvent $event - * The Event to process. - */ - public function onSave(ConfigCrudEvent $event) { - $saved_config = $event->getConfig(); - if ($saved_config->getName() === 'rest.settings' && $event->isChanged('bc_entity_resource_permissions')) { - $this->routerBuilder->setRebuildNeeded(); - } - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - $events[ConfigEvents::SAVE][] = ['onSave']; - return $events; - } - -} diff --git a/core/modules/rest/src/LinkManager/ConfigurableLinkManagerInterface.php b/core/modules/rest/src/LinkManager/ConfigurableLinkManagerInterface.php deleted file mode 100644 index e521459..0000000 --- a/core/modules/rest/src/LinkManager/ConfigurableLinkManagerInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -entityTypeManager = $entity_type_manager; - } - - /** - * {@inheritdoc} - */ - public function processInbound($path, Request $request) { - if ($request->getMethod() === 'POST' && strpos($path, '/entity/') === 0) { - $parts = explode('/', $path); - $entity_type_id = array_pop($parts); - - // Until Drupal 8.3, no entity types specified a link template for the - // 'create' link relation type. As of Drupal 8.3, all core content entity - // types provide this link relation type. This inbound path processor - // provides automatic backwards compatibility: it allows both the old - // default from \Drupal\rest\Plugin\rest\resource\EntityResource, i.e. - // "/entity/{entity_type}" and the link template specified in a particular - // entity type. The former is rewritten to the latter - // specific one if it exists. - $entity_type = $this->entityTypeManager->getDefinition($entity_type_id); - if ($entity_type->hasLinkTemplate('create')) { - return $entity_type->getLinkTemplate('create'); - } - } - return $path; - } - -} diff --git a/core/modules/rest/src/Plugin/ResourceBase.php b/core/modules/rest/src/Plugin/ResourceBase.php index b40a031..2be0aac 100644 --- a/core/modules/rest/src/Plugin/ResourceBase.php +++ b/core/modules/rest/src/Plugin/ResourceBase.php @@ -101,14 +101,6 @@ public function routes() { $definition = $this->getPluginDefinition(); $canonical_path = isset($definition['uri_paths']['canonical']) ? $definition['uri_paths']['canonical'] : '/' . strtr($this->pluginId, ':', '/') . '/{id}'; $create_path = isset($definition['uri_paths']['create']) ? $definition['uri_paths']['create'] : '/' . strtr($this->pluginId, ':', '/'); - // BC: the REST module originally created the POST URL for a resource by - // reading the 'https://www.drupal.org/link-relations/create' URI path from - // the plugin annotation. For consistency with entity type definitions, that - // then changed to reading the 'create' URI path. For any REST Resource - // plugins that were using the old mechanism, we continue to support that. - if (!isset($definition['uri_paths']['create']) && isset($definition['uri_paths']['https://www.drupal.org/link-relations/create'])) { - $create_path = $definition['uri_paths']['https://www.drupal.org/link-relations/create']; - } $route_name = strtr($this->pluginId, ':', '.'); diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index 5d9849d..2eb663b 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -362,15 +362,7 @@ protected function generateFallbackAccessDeniedMessage(EntityInterface $entity, * {@inheritdoc} */ public function permissions() { - // @see https://www.drupal.org/node/2664780 - if ($this->configFactory->get('rest.settings')->get('bc_entity_resource_permissions')) { - // The default Drupal 8.0.x and 8.1.x behavior. - return parent::permissions(); - } - else { - // The default Drupal 8.2.x behavior. - return []; - } + return []; } /** diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index 52daee0..2b33cff 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -94,22 +94,6 @@ class RestExport extends PathPluginBase implements ResponseDisplayPluginInterfac protected $authenticationProviderIds; /** - * The authentication providers' modules, keyed by provider ID. - * - * Authentication providers like 'cookie' and 'basic_auth' are the array - * keys. The array values are the module names, e.g.: - * @code - * ['cookie' => 'user', 'basic_auth' => 'basic_auth'] - * @endcode - * - * @deprecated as of 8.4.x, will be removed in before Drupal 9.0.0, see - * https://www.drupal.org/node/2825204. - * - * @var string[] - */ - protected $authenticationProviders; - - /** * The serialization format providers, keyed by format. * * @var string[] @@ -146,8 +130,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition // basic_auth) as keys and modules providing those as values (user, // basic_auth). $this->authenticationProviderIds = array_keys($authentication_providers); - // For BC reasons we keep around authenticationProviders as before. - $this->authenticationProviders = $authentication_providers; $this->formatProviders = $serializer_format_providers; } diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php index 95deeaa..3ff2d61 100644 --- a/core/modules/rest/src/RequestHandler.php +++ b/core/modules/rest/src/RequestHandler.php @@ -121,13 +121,7 @@ public function handle(RouteMatchInterface $route_match, Request $request) { // Determine the request parameters that should be passed to the resource // plugin. $argument_resolver = $this->createArgumentResolver($route_match, $unserialized, $request); - try { - $arguments = $argument_resolver->getArguments([$resource, $method]); - } - catch (\RuntimeException $exception) { - @trigger_error('Passing in arguments the legacy way is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Provide the right parameter names in the method, similar to controllers. See https://www.drupal.org/node/2894819', E_USER_DEPRECATED); - $arguments = $this->getLegacyParameters($route_match, $unserialized, $request); - } + $arguments = $argument_resolver->getArguments([$resource, $method]); // Invoke the operation on the resource plugin. $response = call_user_func_array([$resource, $method], $arguments); @@ -203,37 +197,4 @@ protected function createArgumentResolver(RouteMatchInterface $route_match, $uns return new ArgumentsResolver($raw_route_arguments, $upcasted_route_arguments, $wildcard_arguments); } - /** - * Provides the parameter usable without an argument resolver. - * - * This creates an list of parameters in a statically defined order. - * - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route match - * @param mixed $unserialized - * The unserialized data. - * @param \Symfony\Component\HttpFoundation\Request $request - * The request. - * - * @deprecated in Drupal 8.4.0, will be removed before Drupal 9.0.0. Use the - * argument resolver method instead, see ::createArgumentResolver(). - * - * @see https://www.drupal.org/node/2894819 - * - * @return array - * An array of parameters. - */ - protected function getLegacyParameters(RouteMatchInterface $route_match, $unserialized, Request $request) { - $route_parameters = $route_match->getParameters(); - $parameters = []; - // Filter out all internal parameters starting with "_". - foreach ($route_parameters as $key => $parameter) { - if ($key{0} !== '_') { - $parameters[] = $parameter; - } - } - - return array_merge($parameters, [$unserialized, $request]); - } - } diff --git a/core/modules/rest/src/RestServiceProvider.php b/core/modules/rest/src/RestServiceProvider.php deleted file mode 100644 index e705de4..0000000 --- a/core/modules/rest/src/RestServiceProvider.php +++ /dev/null @@ -1,51 +0,0 @@ -getParameter(('container.modules')); - if (isset($modules['hal'])) { - // @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. - // Use hal.link_manager instead. - // @see https://www.drupal.org/node/2830467 - $service_definition = new DefinitionDecorator(new Reference('hal.link_manager')); - $service_definition->setClass(LinkManager::class); - $container->setDefinition('rest.link_manager', $service_definition); - - // @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. - // Use hal.link_manager.type instead. - // @see https://www.drupal.org/node/2830467 - $service_definition = new DefinitionDecorator(new Reference('hal.link_manager.type')); - $service_definition->setClass(TypeLinkManager::class); - $container->setDefinition('rest.link_manager.type', $service_definition); - - // @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. - // Use hal.link_manager.relation instead. - // @see https://www.drupal.org/node/2830467 - $service_definition = new DefinitionDecorator(new Reference('hal.link_manager.relation')); - $service_definition->setClass(RelationLinkManager::class); - $container->setDefinition('rest.link_manager.relation', $service_definition); - } - } - -} diff --git a/core/modules/rest/src/Tests/RESTTestBase.php b/core/modules/rest/src/Tests/RESTTestBase.php deleted file mode 100644 index 3f97e46..0000000 --- a/core/modules/rest/src/Tests/RESTTestBase.php +++ /dev/null @@ -1,626 +0,0 @@ -defaultFormat = 'hal_json'; - $this->defaultMimeType = 'application/hal+json'; - $this->defaultAuth = ['cookie']; - $this->resourceConfigStorage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config'); - // Create a test content type for node testing. - if (in_array('node', static::$modules)) { - $this->drupalCreateContentType(['name' => 'resttest', 'type' => 'resttest']); - } - - $this->cookieFile = $this->publicFilesDirectory . '/cookie.jar'; - } - - /** - * Calculates cookies used by guzzle later. - * - * @return \GuzzleHttp\Cookie\CookieJarInterface - * The used CURL options in guzzle. - */ - protected function cookies() { - $cookies = []; - - foreach ($this->cookies as $key => $cookie) { - $cookies[$key][] = $cookie['value']; - } - - $request = \Drupal::request(); - $cookies = NestedArray::mergeDeep($cookies, $this->extractCookiesFromRequest($request)); - - $cookie_jar = new FileCookieJar($this->cookieFile); - foreach ($cookies as $key => $cookie_values) { - foreach ($cookie_values as $cookie_value) { - // setcookie() sets the value of a cookie to be deleted, when its gonna - // be removed. - if ($cookie_value !== 'deleted') { - $cookie_jar->setCookie(new SetCookie(['Name' => $key, 'Value' => $cookie_value, 'Domain' => $request->getHost()])); - } - } - } - - return $cookie_jar; - } - - /** - * Helper function to issue a HTTP request with simpletest's cURL. - * - * @param string|\Drupal\Core\Url $url - * A Url object or system path. - * @param string $method - * HTTP method, one of GET, POST, PUT or DELETE. - * @param string $body - * The body for POST and PUT. - * @param string $mime_type - * The MIME type of the transmitted content. - * @param bool $csrf_token - * If NULL, a CSRF token will be retrieved and used. If FALSE, omit the - * X-CSRF-Token request header (to simulate developer error). Otherwise, the - * passed in value will be used as the value for the X-CSRF-Token request - * header (to simulate developer error, by sending an invalid CSRF token). - * - * @return string - * The content returned from the request. - */ - protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL, $csrf_token = NULL) { - if (!isset($mime_type)) { - $mime_type = $this->defaultMimeType; - } - if (!in_array($method, ['GET', 'HEAD', 'OPTIONS', 'TRACE'])) { - // GET the CSRF token first for writing requests. - $requested_token = $this->drupalGet('session/token'); - } - - $client = \Drupal::httpClient(); - $url = $this->buildUrl($url); - - $options = [ - 'http_errors' => FALSE, - 'cookies' => $this->cookies(), - 'curl' => [ - CURLOPT_HEADERFUNCTION => [&$this, 'curlHeaderCallback'], - ], - ]; - switch ($method) { - case 'GET': - $options += [ - 'headers' => [ - 'Accept' => $mime_type, - ], - ]; - $response = $client->get($url, $options); - break; - - case 'HEAD': - $response = $client->head($url, $options); - break; - - case 'POST': - $options += [ - 'headers' => $csrf_token !== FALSE ? [ - 'Content-Type' => $mime_type, - 'X-CSRF-Token' => ($csrf_token === NULL ? $requested_token : $csrf_token), - ] : [ - 'Content-Type' => $mime_type, - ], - 'body' => $body, - ]; - $response = $client->post($url, $options); - break; - - case 'PUT': - $options += [ - 'headers' => $csrf_token !== FALSE ? [ - 'Content-Type' => $mime_type, - 'X-CSRF-Token' => ($csrf_token === NULL ? $requested_token : $csrf_token), - ] : [ - 'Content-Type' => $mime_type, - ], - 'body' => $body, - ]; - $response = $client->put($url, $options); - break; - - case 'PATCH': - $options += [ - 'headers' => $csrf_token !== FALSE ? [ - 'Content-Type' => $mime_type, - 'X-CSRF-Token' => ($csrf_token === NULL ? $requested_token : $csrf_token), - ] : [ - 'Content-Type' => $mime_type, - ], - 'body' => $body, - ]; - $response = $client->patch($url, $options); - break; - - case 'DELETE': - $options += [ - 'headers' => $csrf_token !== FALSE ? [ - 'Content-Type' => $mime_type, - 'X-CSRF-Token' => ($csrf_token === NULL ? $requested_token : $csrf_token), - ] : [], - ]; - $response = $client->delete($url, $options); - break; - } - - $this->response = $response; - $this->responseBody = (string) $response->getBody(); - $this->setRawContent($this->responseBody); - - // Ensure that any changes to variables in the other thread are picked up. - $this->refreshVariables(); - - $this->verbose($method . ' request to: ' . $url . - '
Code: ' . $this->response->getStatusCode() . - (isset($options['headers']) ? '
Request headers: ' . nl2br(print_r($options['headers'], TRUE)) : '') . - (isset($options['body']) ? '
Request body: ' . nl2br(print_r($options['body'], TRUE)) : '') . - '
Response headers: ' . nl2br(print_r($response->getHeaders(), TRUE)) . - '
Response body: ' . $this->responseBody); - - return $this->responseBody; - } - - /** - * {@inheritdoc} - */ - protected function assertResponse($code, $message = '', $group = 'Browser') { - if (!isset($this->response)) { - return parent::assertResponse($code, $message, $group); - } - return $this->assertEqual($code, $this->response->getStatusCode(), $message ? $message : "HTTP response expected $code, actual {$this->response->getStatusCode()}", $group); - } - - /** - * {@inheritdoc} - */ - protected function drupalGetHeaders($all_requests = FALSE) { - if (!isset($this->response)) { - return parent::drupalGetHeaders($all_requests); - } - $lowercased_keys = array_map('strtolower', array_keys($this->response->getHeaders())); - return array_map(function (array $header) { - return implode(', ', $header); - }, array_combine($lowercased_keys, array_values($this->response->getHeaders()))); - } - - /** - * {@inheritdoc} - */ - protected function drupalGetHeader($name, $all_requests = FALSE) { - if (!isset($this->response)) { - return parent::drupalGetHeader($name, $all_requests); - } - if ($header = $this->response->getHeader($name)) { - return implode(', ', $header); - } - } - - /** - * Creates entity objects based on their types. - * - * @param string $entity_type - * The type of the entity that should be created. - * - * @return \Drupal\Core\Entity\EntityInterface - * The new entity object. - */ - protected function entityCreate($entity_type) { - return $this->container->get('entity_type.manager') - ->getStorage($entity_type) - ->create($this->entityValues($entity_type)); - } - - /** - * Provides an array of suitable property values for an entity type. - * - * Required properties differ from entity type to entity type, so we keep a - * minimum mapping here. - * - * @param string $entity_type_id - * The ID of the type of entity that should be created. - * - * @return array - * An array of values keyed by property name. - */ - protected function entityValues($entity_type_id) { - switch ($entity_type_id) { - case 'entity_test': - return [ - 'name' => $this->randomMachineName(), - 'user_id' => 1, - 'field_test_text' => [ - 0 => [ - 'value' => $this->randomString(), - 'format' => 'plain_text', - ], - ], - ]; - case 'config_test': - return [ - 'id' => $this->randomMachineName(), - 'label' => 'Test label', - ]; - case 'node': - return ['title' => $this->randomString(), 'type' => 'resttest']; - case 'node_type': - return [ - 'type' => 'article', - 'name' => $this->randomMachineName(), - ]; - case 'user': - return ['name' => $this->randomMachineName()]; - - case 'comment': - return [ - 'subject' => $this->randomMachineName(), - 'entity_type' => 'node', - 'comment_type' => 'comment', - 'comment_body' => $this->randomString(), - 'entity_id' => 'invalid', - 'field_name' => 'comment', - ]; - case 'taxonomy_vocabulary': - return [ - 'vid' => 'tags', - 'name' => $this->randomMachineName(), - ]; - case 'block': - // Block placements depend on themes, ensure Bartik is installed. - $this->container->get('theme_installer')->install(['bartik']); - return [ - 'id' => strtolower($this->randomMachineName(8)), - 'plugin' => 'system_powered_by_block', - 'theme' => 'bartik', - 'region' => 'header', - ]; - default: - if ($this->isConfigEntity($entity_type_id)) { - return $this->configEntityValues($entity_type_id); - } - return []; - } - } - - /** - * Enables the REST service interface for a specific entity type. - * - * @param string|false $resource_type - * The resource type that should get REST API enabled or FALSE to disable all - * resource types. - * @param string $method - * The HTTP method to enable, e.g. GET, POST etc. - * @param string|array $format - * (Optional) The serialization format, e.g. hal_json, or a list of formats. - * @param array $auth - * (Optional) The list of valid authentication methods. - */ - protected function enableService($resource_type, $method = 'GET', $format = NULL, array $auth = []) { - if ($resource_type) { - // Enable REST API for this entity type. - $resource_config_id = str_replace(':', '.', $resource_type); - // get entity by id - /** @var \Drupal\rest\RestResourceConfigInterface $resource_config */ - $resource_config = $this->resourceConfigStorage->load($resource_config_id); - if (!$resource_config) { - $resource_config = $this->resourceConfigStorage->create([ - 'id' => $resource_config_id, - 'granularity' => RestResourceConfigInterface::METHOD_GRANULARITY, - 'configuration' => [] - ]); - } - $configuration = $resource_config->get('configuration'); - - if (is_array($format)) { - for ($i = 0; $i < count($format); $i++) { - $configuration[$method]['supported_formats'][] = $format[$i]; - } - } - else { - if ($format == NULL) { - $format = $this->defaultFormat; - } - $configuration[$method]['supported_formats'][] = $format; - } - - if (!is_array($auth) || empty($auth)) { - $auth = $this->defaultAuth; - } - foreach ($auth as $auth_provider) { - $configuration[$method]['supported_auth'][] = $auth_provider; - } - - $resource_config->set('configuration', $configuration); - $resource_config->save(); - } - else { - foreach ($this->resourceConfigStorage->loadMultiple() as $resource_config) { - $resource_config->delete(); - } - } - $this->rebuildCache(); - } - - /** - * Rebuilds routing caches. - */ - protected function rebuildCache() { - $this->container->get('router.builder')->rebuildIfNeeded(); - } - - /** - * {@inheritdoc} - * - * This method is overridden to deal with a cURL quirk: the usage of - * CURLOPT_CUSTOMREQUEST cannot be unset on the cURL handle, so we need to - * override it every time it is omitted. - */ - protected function curlExec($curl_options, $redirect = FALSE) { - unset($this->response); - - if (!isset($curl_options[CURLOPT_CUSTOMREQUEST])) { - if (!empty($curl_options[CURLOPT_HTTPGET])) { - $curl_options[CURLOPT_CUSTOMREQUEST] = 'GET'; - } - if (!empty($curl_options[CURLOPT_POST])) { - $curl_options[CURLOPT_CUSTOMREQUEST] = 'POST'; - } - } - return parent::curlExec($curl_options, $redirect); - } - - /** - * Provides the necessary user permissions for entity operations. - * - * @param string $entity_type_id - * The entity type. - * @param string $operation - * The operation, one of 'view', 'create', 'update' or 'delete'. - * - * @return array - * The set of user permission strings. - */ - protected function entityPermissions($entity_type_id, $operation) { - switch ($entity_type_id) { - case 'entity_test': - switch ($operation) { - case 'view': - return ['view test entity']; - case 'create': - case 'update': - case 'delete': - return ['administer entity_test content']; - } - case 'node': - switch ($operation) { - case 'view': - return ['access content']; - case 'create': - return ['create resttest content']; - case 'update': - return ['edit any resttest content']; - case 'delete': - return ['delete any resttest content']; - } - - case 'comment': - switch ($operation) { - case 'view': - return ['access comments']; - - case 'create': - return ['post comments', 'skip comment approval']; - - case 'update': - return ['edit own comments']; - - case 'delete': - return ['administer comments']; - } - break; - - case 'user': - switch ($operation) { - case 'view': - return ['access user profiles']; - - default: - return ['administer users']; - } - - default: - if ($this->isConfigEntity($entity_type_id)) { - $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); - if ($admin_permission = $entity_type->getAdminPermission()) { - return [$admin_permission]; - } - } - } - return []; - } - - /** - * Loads an entity based on the location URL returned in the location header. - * - * @param string $location_url - * The URL returned in the Location header. - * - * @return \Drupal\Core\Entity\Entity|false - * The entity or FALSE if there is no matching entity. - */ - protected function loadEntityFromLocationHeader($location_url) { - $url_parts = explode('/', $location_url); - $id = end($url_parts); - return $this->container->get('entity_type.manager') - ->getStorage($this->testEntityType)->load($id); - } - - /** - * Remove node fields that can only be written by an admin user. - * - * @param \Drupal\node\NodeInterface $node - * The node to remove fields where non-administrative users cannot write. - * - * @return \Drupal\node\NodeInterface - * The node with removed fields. - */ - protected function removeNodeFieldsForNonAdminUsers(NodeInterface $node) { - $node->set('status', NULL); - $node->set('created', NULL); - $node->set('changed', NULL); - $node->set('promote', NULL); - $node->set('sticky', NULL); - $node->set('revision_timestamp', NULL); - $node->set('revision_log', NULL); - $node->set('uid', NULL); - - return $node; - } - - /** - * Check to see if the HTTP request response body is identical to the expected - * value. - * - * @param $expected - * The first value to check. - * @param $message - * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. - * @param $group - * (optional) The group this message is in, which is displayed in a column - * in test output. Use 'Debug' to indicate this is debugging output. Do not - * translate this string. Defaults to 'Other'; most tests do not override - * this default. - * - * @return bool - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertResponseBody($expected, $message = '', $group = 'REST Response') { - return $this->assertIdentical($expected, $this->responseBody, $message ? $message : strtr('Response body @expected (expected) is equal to @response (actual).', ['@expected' => var_export($expected, TRUE), '@response' => var_export($this->responseBody, TRUE)]), $group); - } - - /** - * Checks if an entity type id is for a Config Entity. - * - * @param string $entity_type_id - * The entity type ID to check. - * - * @return bool - * TRUE if the entity is a Config Entity, FALSE otherwise. - */ - protected function isConfigEntity($entity_type_id) { - return \Drupal::entityTypeManager()->getDefinition($entity_type_id) instanceof ConfigEntityType; - } - - /** - * Provides an array of suitable property values for a config entity type. - * - * Config entities have some common keys that need to be created. Required - * properties differ among config entity types, so we keep a minimum mapping - * here. - * - * @param string $entity_type_id - * The ID of the type of entity that should be created. - * - * @return array - * An array of values keyed by property name. - */ - protected function configEntityValues($entity_type_id) { - $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id); - $keys = $entity_type->getKeys(); - $values = []; - // Fill out known key values that are shared across entity types. - foreach ($keys as $key) { - if ($key === 'id' || $key === 'label') { - $values[$key] = $this->randomMachineName(); - } - } - // Add extra values for particular entity types. - switch ($entity_type_id) { - case 'block': - $values['plugin'] = 'system_powered_by_block'; - break; - } - return $values; - } - -} diff --git a/core/modules/rest/src/Tests/Update/RestExportAuthCorrectionUpdateTest.php b/core/modules/rest/src/Tests/Update/RestExportAuthCorrectionUpdateTest.php deleted file mode 100644 index aeca71f..0000000 --- a/core/modules/rest/src/Tests/Update/RestExportAuthCorrectionUpdateTest.php +++ /dev/null @@ -1,36 +0,0 @@ -databaseDumpFiles = [ - __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', - __DIR__ . '/../../../tests/fixtures/update/rest-export-with-authentication-correction.php', - ]; - } - - /** - * Ensures that update hook is run for "rest" module. - */ - public function testUpdate() { - $this->runUpdates(); - - // Get particular view. - $view = \Drupal::entityTypeManager()->getStorage('view')->load('rest_export_with_authorization_correction'); - $displays = $view->get('display'); - $this->assertIdentical($displays['rest_export_1']['display_options']['auth'], ['cookie'], 'Cookie is used for authentication'); - } - -} diff --git a/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_post_update_resource_granularity.php b/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_post_update_resource_granularity.php deleted file mode 100644 index aa94c63e555977ccc5ada2d04fd8632562e09a14..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5199 zcmcIoTTdJ}6z(&>!dgXIKw)8*OTuhJTS1~$YSSvD4^@aPGh-HuxykkrNRdD$9&F z6^48zGTYQD-+4K?R8~)%S7oMbHi4+g;tUX8_&|JEOkml;+1HnB*{X1I2>m-x3F?|SDb54)(e+j>q3cJZ5{Sa`a*V2 z0FkzSb9|%k<*mvaJ>J?7V&~+_=sa_qAMhf?IIZ%W)sDrh6ESx8&g){rlE=?^QK<^e z(*#aC%0j~~lf0bmP3K|eBdgJOI&HjeP5wJzDN}1TPu0l9iGhtEE z-`A_@-{bI~$-yic^>g_&$hdeN%t3mSM1FY>d81_iIQim|=}|KJVfzPGC~FI=??!W% zyi7)|HS{_?49nn#H>pe&Qg<}JO!jE%AWY>|b<@-m`RYb z-_@1%wD_Q13>RprNv05doQ&$cS(sAt*o>4-lTojb(b9by-cLsCLSqB(g1Q+N!?zH? zECSH!+)KWYMeLW=Wv1@=YY8)3{U^3fcj zO%T}X)&L(Gf*4v&kFbrHlPiaayJY`G$3I%p67Ll zLhhWmn}{z=3Y8V0C8$vt*9LV4o5DD;#fF2JeuCoxAX>nLio5zpasUNzM?O)?(-32v zoAM?g5lIVAAShRtItMB9{8FViK>(KH$o-ur-q@=6E2Iz2#8hCq$$^ppIw%W?ak{!1 z&BG`g97lt?IDvGdrbt)H7bGS5!v~vf!`?wdDK5NLo3Kx|$5F{{uf9At7mjzDL&* zJOP%RCF>NWRb?%Erh*P9Wf0a&pBk%bj4R1MIUXkM=UjjGpnMM968M8 zUPkTxNJr{Dtnq3Q=DS00A8s;f5~_s{O*juqlFuh1M*+j&AMOPMMsZHG_XDB@lZuNr z$i|#)i5(7?xAU)Uhdbfi zDBf^fTsgcM^jae{Bgk{^Mvj0tUlJZ&l2ArdBqlCQ9HPkCwp3=irWT=0jYg!oKRHAK zGu?V-w;LV^7Edziv?r@+H+3=x;N$Xcr*2_EgLA5o@vuTuR^g=a_ieLt2p=x;1Xp}u>2tEzBT%j8%RiVjT>Suv!>2XN>K0`D$1n$aP7`` z)eLQ+x->cZUs-6c+MP$V6Kr1g7Z*U2!`KWtD4qGN`!KzrZO9~3;LIMF$|KI-!{NuF zc^P*tJNRF_j@LTJM&s&TD361EN#B&3-~$}p%L=>8%ZgppV(xEZF=oJK zJr|V1qO81d_<%v*en3Dc@P!2(U)P(s?}!4OjUdbu0ueQQD;BE3_apS?C{j4|o)Qv# SAhS=12Z>(`#?DFaT>Tf|^skfv diff --git a/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php b/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php deleted file mode 100644 index 17a69d5..0000000 --- a/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8201.php +++ /dev/null @@ -1,59 +0,0 @@ -insert('key_value') - ->fields([ - 'collection' => 'system.schema', - 'name' => 'rest', - 'value' => 'i:8000;', - ]) - ->execute(); - -// Update core.extension. -$extensions = $connection->select('config') - ->fields('config', ['data']) - ->condition('collection', '') - ->condition('name', 'core.extension') - ->execute() - ->fetchField(); -$extensions = unserialize($extensions); -$extensions['module']['basic_auth'] = 0; -$extensions['module']['rest'] = 0; -$extensions['module']['serialization'] = 0; -$connection->update('config') - ->fields([ - 'data' => serialize($extensions), - ]) - ->condition('collection', '') - ->condition('name', 'core.extension') - ->execute(); - -// Install the rest configuration. -$config = [ - 'resources' => [ - 'entity:node' => [ - 'GET' => [ - 'supported_formats' => ['json'], - 'supported_auth' => ['basic_auth'], - ], - ], - ], - 'link_domain' => NULL, -]; -$data = $connection->insert('config') - ->fields([ - 'name' => 'rest.settings', - 'data' => serialize($config), - 'collection' => '' - ]) - ->execute(); diff --git a/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8203.php b/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8203.php deleted file mode 100644 index 15acff9..0000000 --- a/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_update_8203.php +++ /dev/null @@ -1,58 +0,0 @@ -insert('key_value') - ->fields([ - 'collection' => 'system.schema', - 'name' => 'rest', - 'value' => 'i:8000;', - ]) - ->execute(); - -// Update core.extension. -$extensions = $connection->select('config') - ->fields('config', ['data']) - ->condition('collection', '') - ->condition('name', 'core.extension') - ->execute() - ->fetchField(); -$extensions = unserialize($extensions); -$extensions['module']['rest'] = 0; -$extensions['module']['serialization'] = 0; -$connection->update('config') - ->fields([ - 'data' => serialize($extensions), - ]) - ->condition('collection', '') - ->condition('name', 'core.extension') - ->execute(); - -// Install the rest configuration. -$config = [ - 'resources' => [ - 'entity:node' => [ - 'GET' => [ - 'supported_formats' => ['json'], - 'supported_auth' => ['basic_auth'], - ], - ], - ], - 'link_domain' => NULL, -]; -$data = $connection->insert('config') - ->fields([ - 'name' => 'rest.settings', - 'data' => serialize($config), - 'collection' => '' - ]) - ->execute(); diff --git a/core/modules/rest/tests/fixtures/update/rest-export-with-authentication-correction.php b/core/modules/rest/tests/fixtures/update/rest-export-with-authentication-correction.php deleted file mode 100644 index 6cbd04e..0000000 --- a/core/modules/rest/tests/fixtures/update/rest-export-with-authentication-correction.php +++ /dev/null @@ -1,63 +0,0 @@ -insert('key_value') - ->fields([ - 'collection' => 'system.schema', - 'name' => 'rest', - 'value' => 'i:8000;', - ]) - ->execute(); - -// Update core.extension. -$extensions = $connection->select('config') - ->fields('config', ['data']) - ->condition('collection', '') - ->condition('name', 'core.extension') - ->execute() - ->fetchField(); -$extensions = unserialize($extensions); -$extensions['module']['rest'] = 0; -$extensions['module']['serialization'] = 0; -$extensions['module']['basic_auth'] = 0; -$connection->update('config') - ->fields([ - 'data' => serialize($extensions), - ]) - ->condition('collection', '') - ->condition('name', 'core.extension') - ->execute(); - -$connection->insert('config') - ->fields([ - 'name' => 'rest.settings', - 'data' => serialize([ - 'link_domain' => '~', - ]), - 'collection' => '', - ]) - ->execute(); - -$connection->insert('config') - ->fields([ - 'name' => 'views.view.rest_export_with_authorization_correction', - ]) - ->execute(); - -$connection->merge('config') - ->condition('name', 'views.view.rest_export_with_authorization_correction') - ->condition('collection', '') - ->fields([ - 'data' => serialize(Yaml::decode(file_get_contents('core/modules/views/tests/modules/views_test_config/test_views/views.view.rest_export_with_authorization_correction.yml'))), - ]) - ->execute(); diff --git a/core/modules/rest/tests/fixtures/update/rest-export-with-authentication.php b/core/modules/rest/tests/fixtures/update/rest-export-with-authentication.php deleted file mode 100644 index 7d72d49..0000000 --- a/core/modules/rest/tests/fixtures/update/rest-export-with-authentication.php +++ /dev/null @@ -1,65 +0,0 @@ -insert('key_value') - ->fields([ - 'collection' => 'system.schema', - 'name' => 'rest', - 'value' => 'i:8000;', - ]) - ->execute(); - -// Update core.extension. -$extensions = $connection->select('config') - ->fields('config', ['data']) - ->condition('collection', '') - ->condition('name', 'core.extension') - ->execute() - ->fetchField(); -$extensions = unserialize($extensions); -$extensions['module']['rest'] = 0; -$extensions['module']['serialization'] = 0; -$extensions['module']['basic_auth'] = 0; -$connection->update('config') - ->fields([ - 'data' => serialize($extensions), - ]) - ->condition('collection', '') - ->condition('name', 'core.extension') - ->execute(); - -$config = [ - 'link_domain' => '~', -]; -$data = $connection->insert('config') - ->fields([ - 'name' => 'rest.settings', - 'data' => serialize($config), - 'collection' => '', - ]) - ->execute(); - -$connection->insert('config') - ->fields([ - 'name' => 'views.view.rest_export_with_authorization', - ]) - ->execute(); - -$connection->merge('config') - ->condition('name', 'views.view.rest_export_with_authorization') - ->condition('collection', '') - ->fields([ - 'data' => serialize(Yaml::decode(file_get_contents('core/modules/views/tests/modules/views_test_config/test_views/views.view.rest_export_with_authorization.yml'))), - ]) - ->execute(); diff --git a/core/modules/rest/tests/fixtures/update/rest.resource.entity.comment_2721595.yml b/core/modules/rest/tests/fixtures/update/rest.resource.entity.comment_2721595.yml deleted file mode 100644 index 7e86bab..0000000 --- a/core/modules/rest/tests/fixtures/update/rest.resource.entity.comment_2721595.yml +++ /dev/null @@ -1,32 +0,0 @@ -id: entity.comment -plugin_id: 'entity:comment' -granularity: method -configuration: - GET: - supported_formats: - - hal_json - # This resource has a method-specific format. - # @see \Drupal\rest\Tests\Update\ResourceGranularityUpdateTest - - xml - supported_auth: - - basic_auth - POST: - supported_formats: - - hal_json - supported_auth: - - basic_auth - PATCH: - supported_formats: - - hal_json - supported_auth: - - basic_auth - DELETE: - supported_formats: - - hal_json - supported_auth: - - basic_auth -dependencies: - module: - - node - - basic_auth - - hal diff --git a/core/modules/rest/tests/fixtures/update/rest.resource.entity.node_2721595.yml b/core/modules/rest/tests/fixtures/update/rest.resource.entity.node_2721595.yml deleted file mode 100644 index 0cf4d78..0000000 --- a/core/modules/rest/tests/fixtures/update/rest.resource.entity.node_2721595.yml +++ /dev/null @@ -1,29 +0,0 @@ -id: entity.node -plugin_id: 'entity:node' -granularity: method -configuration: - GET: - supported_formats: - - hal_json - supported_auth: - - basic_auth - POST: - supported_formats: - - hal_json - supported_auth: - - basic_auth - PATCH: - supported_formats: - - hal_json - supported_auth: - - basic_auth - DELETE: - supported_formats: - - hal_json - supported_auth: - - basic_auth -dependencies: - module: - - node - - basic_auth - - hal diff --git a/core/modules/rest/tests/fixtures/update/rest.resource.entity.user_2721595.yml b/core/modules/rest/tests/fixtures/update/rest.resource.entity.user_2721595.yml deleted file mode 100644 index 593a260..0000000 --- a/core/modules/rest/tests/fixtures/update/rest.resource.entity.user_2721595.yml +++ /dev/null @@ -1,32 +0,0 @@ -id: entity.user -plugin_id: 'entity:user' -granularity: method -configuration: - GET: - supported_formats: - - hal_json - supported_auth: - - basic_auth - # This resource has a method-specific authentication. - # @see \Drupal\rest\Tests\Update\ResourceGranularityUpdateTest - - oauth - POST: - supported_formats: - - hal_json - supported_auth: - - basic_auth - PATCH: - supported_formats: - - hal_json - supported_auth: - - basic_auth - DELETE: - supported_formats: - - hal_json - supported_auth: - - basic_auth -dependencies: - module: - - node - - basic_auth - - hal diff --git a/core/modules/rest/tests/src/Functional/BcTimestampNormalizerUnixTestTrait.php b/core/modules/rest/tests/src/Functional/BcTimestampNormalizerUnixTestTrait.php deleted file mode 100644 index a275f64..0000000 --- a/core/modules/rest/tests/src/Functional/BcTimestampNormalizerUnixTestTrait.php +++ /dev/null @@ -1,43 +0,0 @@ -config('serialization.settings')->get('bc_timestamp_normalizer_unix')) { - return ['value' => $timestamp]; - } - - // Otherwise, format the date string to the same that - // \Drupal\serialization\Normalizer\TimestampItemNormalizer will produce. - $date = new \DateTime(); - $date->setTimestamp($timestamp); - $date->setTimezone(new \DateTimeZone('UTC')); - - // Format is also added to the expected return values. - return [ - 'value' => $date->format(\DateTime::RFC3339), - 'format' => \DateTime::RFC3339, - ]; - } - -} 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..9725e34 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/BaseFieldOverride/BaseFieldOverrideResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/BaseFieldOverride/BaseFieldOverrideResourceTestBase.php @@ -101,10 +101,6 @@ protected function getExpectedCacheContexts() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return "The 'administer node fields' permission is required."; } 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..ee2cc64 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Block/BlockResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Block/BlockResourceTestBase.php @@ -129,10 +129,6 @@ protected function getExpectedCacheTags() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': return "You are not authorized to view this block entity."; diff --git a/core/modules/rest/tests/src/Functional/EntityResource/BlockContent/BlockContentResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/BlockContent/BlockContentResourceTestBase.php index 8b67cc6..f5b8e10 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/BlockContent/BlockContentResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/BlockContent/BlockContentResourceTestBase.php @@ -12,8 +12,6 @@ */ abstract class BlockContentResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -105,7 +103,10 @@ protected function getExpectedNormalizedEntity() { ], 'revision_log' => [], 'changed' => [ - $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), + [ + 'value' => (new \DateTime())->setTimestamp((int) $this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'revision_id' => [ [ @@ -113,7 +114,10 @@ protected function getExpectedNormalizedEntity() { ], ], 'revision_created' => [ - $this->formatExpectedTimestampItemValues((int) $this->entity->getRevisionCreationTime()), + [ + 'value' => (new \DateTime())->setTimestamp((int) $this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'revision_user' => [], 'revision_translation_affected' => [ @@ -164,10 +168,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return parent::getExpectedUnauthorizedAccessMessage($method); } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php index bade2a7..69d46f7 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php @@ -6,14 +6,13 @@ use Drupal\comment\Entity\CommentType; use Drupal\comment\Tests\CommentTestTrait; use Drupal\entity_test\Entity\EntityTest; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use Drupal\user\Entity\User; use GuzzleHttp\RequestOptions; abstract class CommentResourceTestBase extends EntityResourceTestBase { - use CommentTestTrait, BcTimestampNormalizerUnixTestTrait; + use CommentTestTrait; /** * {@inheritdoc} @@ -149,10 +148,16 @@ protected function getExpectedNormalizedEntity() { ], ], 'created' => [ - $this->formatExpectedTimestampItemValues(123456789), + [ + 'value' => (new \DateTime())->setTimestamp(123456789)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'changed' => [ - $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), + [ + 'value' => (new \DateTime())->setTimestamp((int) $this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'default_langcode' => [ [ @@ -310,10 +315,6 @@ public function testPostDxWithoutCriticalBaseFields() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET'; return "The 'access comments' permission is required and the comment must be published."; 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..214e06c 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ContactForm/ContactFormResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ContactForm/ContactFormResourceTestBase.php @@ -8,8 +8,6 @@ abstract class ContactFormResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -94,10 +92,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ 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."; } 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..4f20778 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Editor/EditorResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Editor/EditorResourceTestBase.php @@ -174,10 +174,6 @@ protected function getExpectedCacheContexts() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return "The 'administer filters' permission is required."; } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityFormDisplay/EntityFormDisplayResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityFormDisplay/EntityFormDisplayResourceTestBase.php index cc4cf58..54798c4 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityFormDisplay/EntityFormDisplayResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityFormDisplay/EntityFormDisplayResourceTestBase.php @@ -151,10 +151,6 @@ protected function getExpectedCacheContexts() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return "The 'administer node form display' permission is required."; } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 7196940..714c8a9 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -233,11 +233,6 @@ protected function getNormalizedPatchEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - $permission = $this->entity->getEntityType()->getAdminPermission(); if ($permission !== FALSE) { return "The '{$permission}' permission is required."; @@ -485,83 +480,6 @@ public function testGet() { $head_headers = $header_cleaner($head_headers); $this->assertSame($get_headers, $head_headers); - // BC: serialization_update_8302(). - // Only run this for fieldable entities. It doesn't make sense for config - // entities as config values are already casted. They also run through the - // ConfigEntityNormalizer, which doesn't deal with fields individually. - if ($this->entity instanceof FieldableEntityInterface) { - // Test primitive data casting BC (strings). - $this->config('serialization.settings')->set('bc_primitives_as_strings', TRUE)->save(TRUE); - // Rebuild the container so new config is reflected in the addition of the - // PrimitiveDataNormalizer. - $this->rebuildAll(); - - $response = $this->request('GET', $url, $request_options); - $this->assertResourceResponse(200, FALSE, $response); - - // Again do an identical comparison, but this time transform the expected - // normalized entity's values to strings. This ensures the BC layer for - // bc_primitives_as_strings works as expected. - $expected = $this->getExpectedNormalizedEntity(); - // Config entities are not affected. - // @see \Drupal\serialization\Normalizer\ConfigEntityNormalizer::normalize() - $expected = static::castToString($expected); - static::recursiveKSort($expected); - $actual = $this->serializer->decode((string) $response->getBody(), static::$format); - static::recursiveKSort($actual); - $this->assertSame($expected, $actual); - - // Reset the config value and rebuild. - $this->config('serialization.settings')->set('bc_primitives_as_strings', FALSE)->save(TRUE); - $this->rebuildAll(); - } - - // BC: serialization_update_8401(). - // Only run this for fieldable entities. It doesn't make sense for config - // entities as config values always use the raw values (as per the config - // schema), returned directly from the ConfigEntityNormalizer, which - // doesn't deal with fields individually. - if ($this->entity instanceof FieldableEntityInterface) { - // Test the BC settings for timestamp values. - $this->config('serialization.settings')->set('bc_timestamp_normalizer_unix', TRUE)->save(TRUE); - // Rebuild the container so new config is reflected in the addition of the - // TimestampItemNormalizer. - $this->rebuildAll(); - - $response = $this->request('GET', $url, $request_options); - $this->assertResourceResponse(200, FALSE, $response); - - // This ensures the BC layer for bc_timestamp_normalizer_unix works as - // expected. This method should be using - // ::formatExpectedTimestampValue() to generate the timestamp value. This - // will take into account the above config setting. - $expected = $this->getExpectedNormalizedEntity(); - // Config entities are not affected. - // @see \Drupal\serialization\Normalizer\ConfigEntityNormalizer::normalize() - static::recursiveKSort($expected); - $actual = $this->serializer->decode((string) $response->getBody(), static::$format); - static::recursiveKSort($actual); - $this->assertSame($expected, $actual); - - // Reset the config value and rebuild. - $this->config('serialization.settings')->set('bc_timestamp_normalizer_unix', FALSE)->save(TRUE); - $this->rebuildAll(); - } - - // BC: rest_update_8203(). - $this->config('rest.settings')->set('bc_entity_resource_permissions', TRUE)->save(TRUE); - $this->refreshTestStateAfterRestConfigChange(); - - // DX: 403 when unauthorized. - $response = $this->request('GET', $url, $request_options); - $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('GET'), $response); - - $this->grantPermissionsToTestedRole(['restful get entity:' . static::$entityTypeId]); - - // 200 for well-formed request. - $response = $this->request('GET', $url, $request_options); - $this->assertResourceResponse(200, FALSE, $response); - $this->resourceConfigStorage->load(static::$resourceConfigId)->disable()->save(); $this->refreshTestStateAfterRestConfigChange(); @@ -810,44 +728,6 @@ public function testPost() { } } } - - $this->config('rest.settings')->set('bc_entity_resource_permissions', TRUE)->save(TRUE); - $this->refreshTestStateAfterRestConfigChange(); - $request_options[RequestOptions::BODY] = $parseable_valid_request_body_2; - - // DX: 403 when unauthorized. - $response = $this->request('POST', $url, $request_options); - $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('POST'), $response); - - $this->grantPermissionsToTestedRole(['restful post entity:' . static::$entityTypeId]); - - // 201 for well-formed request. - // If the entity is stored, delete the first created entity (in case there - // is a uniqueness constraint). - if (get_class($this->entityStorage) !== ContentEntityNullStorage::class) { - $this->entityStorage->load(static::$firstCreatedEntityId)->delete(); - } - $response = $this->request('POST', $url, $request_options); - $this->assertResourceResponse(201, FALSE, $response); - if ($has_canonical_url) { - $location = $this->entityStorage->load(static::$secondCreatedEntityId)->toUrl('canonical')->setAbsolute(TRUE)->toString(); - $this->assertSame([$location], $response->getHeader('Location')); - } - else { - $this->assertSame([], $response->getHeader('Location')); - } - $this->assertFalse($response->hasHeader('X-Drupal-Cache')); - - // BC: old default POST URLs have their path updated by the inbound path - // processor \Drupal\rest\PathProcessor\PathProcessorEntityResourceBC to the - // new URL, which is derived from the 'create' link template if an entity - // type specifies it. - if ($this->entity->getEntityType()->hasLinkTemplate('create')) { - $this->entityStorage->load(static::$secondCreatedEntityId)->delete(); - $old_url = Url::fromUri('base:entity/' . static::$entityTypeId); - $response = $this->request('POST', $old_url, $request_options); - $this->assertResourceResponse(201, FALSE, $response); - } } /** @@ -1017,21 +897,6 @@ public function testPatch() { // request. Test this using the configurable field that we added, but which // is not sent in the PATCH request. $this->assertSame('All the faith he had had had had no effect on the outcome of his life.', $updated_entity->get('field_rest_test')->value); - - $this->config('rest.settings')->set('bc_entity_resource_permissions', TRUE)->save(TRUE); - $this->refreshTestStateAfterRestConfigChange(); - $request_options[RequestOptions::BODY] = $parseable_valid_request_body_2; - - // DX: 403 when unauthorized. - $response = $this->request('PATCH', $url, $request_options); - $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('PATCH'), $response); - - $this->grantPermissionsToTestedRole(['restful patch entity:' . static::$entityTypeId]); - - // 200 for well-formed request. - $response = $this->request('PATCH', $url, $request_options); - $this->assertResourceResponse(200, FALSE, $response); - $this->assertFalse($response->hasHeader('X-Drupal-Cache')); } /** @@ -1112,25 +977,6 @@ public function testDelete() { // $this->assertSame(FALSE, $response->hasHeader('Content-Type')); $this->assertSame('', (string) $response->getBody()); $this->assertFalse($response->hasHeader('X-Drupal-Cache')); - - $this->config('rest.settings')->set('bc_entity_resource_permissions', TRUE)->save(TRUE); - $this->refreshTestStateAfterRestConfigChange(); - $this->entity = $this->createEntity(); - $url = $this->getEntityResourceUrl()->setOption('query', $url->getOption('query')); - - // DX: 403 when unauthorized. - $response = $this->request('DELETE', $url, $request_options); - $this->assertResourceErrorResponse(403, $this->getExpectedUnauthorizedAccessMessage('DELETE'), $response); - - $this->grantPermissionsToTestedRole(['restful delete entity:' . static::$entityTypeId]); - - // 204 for well-formed request. - $response = $this->request('DELETE', $url, $request_options); - $this->assertSame(204, $response->getStatusCode()); - // @todo Uncomment the following line when https://www.drupal.org/node/2821711 is fixed. - // $this->assertSame(FALSE, $response->hasHeader('Content-Type')); - $this->assertSame('', (string) $response->getBody()); - $this->assertFalse($response->hasHeader('X-Drupal-Cache')); } /** diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTest/EntityTestResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTest/EntityTestResourceTestBase.php index d14ec38..315f5be 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityTest/EntityTestResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTest/EntityTestResourceTestBase.php @@ -3,14 +3,11 @@ namespace Drupal\Tests\rest\Functional\EntityResource\EntityTest; use Drupal\entity_test\Entity\EntityTest; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use Drupal\user\Entity\User; abstract class EntityTestResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -106,7 +103,10 @@ protected function getExpectedNormalizedEntity() { ] ], 'created' => [ - $this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value) + [ + 'value' => (new \DateTime())->setTimestamp((int) $this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'user_id' => [ [ @@ -144,10 +144,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': return "The 'view test entity' permission is required."; 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..bb42717 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php @@ -8,8 +8,6 @@ abstract class EntityTestBundleResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelResourceTestBase.php index 2257d6c..9ae5cc5 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelResourceTestBase.php @@ -3,14 +3,11 @@ namespace Drupal\Tests\rest\Functional\EntityResource\EntityTestLabel; use Drupal\entity_test\Entity\EntityTestLabel; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use Drupal\user\Entity\User; abstract class EntityTestLabelResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -97,7 +94,10 @@ protected function getExpectedNormalizedEntity() { ], ], 'created' => [ - $this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value), + [ + 'value' => (new \DateTime())->setTimestamp((int) $this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'user_id' => [ [ @@ -141,10 +141,6 @@ protected function getExpectedCacheContexts() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': return "The 'view test entity' permission is required."; diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityViewDisplay/EntityViewDisplayResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityViewDisplay/EntityViewDisplayResourceTestBase.php index ccc3aad..871b4c1 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityViewDisplay/EntityViewDisplayResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityViewDisplay/EntityViewDisplayResourceTestBase.php @@ -108,10 +108,6 @@ protected function getExpectedCacheContexts() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return "The 'administer node display' permission is required."; } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedResourceTestBase.php index 1e79395..eda368d 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Feed/FeedResourceTestBase.php @@ -2,14 +2,11 @@ namespace Drupal\Tests\rest\Functional\EntityResource\Feed; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityTest\EntityTestResourceTestBase; use Drupal\aggregator\Entity\Feed; abstract class FeedResourceTestBase extends EntityTestResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -95,10 +92,16 @@ protected function getExpectedNormalizedEntity() { ] ], 'checked' => [ - $this->formatExpectedTimestampItemValues(123456789), + [ + 'value' => (new \DateTime())->setTimestamp(123456789)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'queued' => [ - $this->formatExpectedTimestampItemValues(123456789), + [ + 'value' => (new \DateTime())->setTimestamp(123456789)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'link' => [ [ @@ -126,7 +129,10 @@ protected function getExpectedNormalizedEntity() { ] ], 'modified' => [ - $this->formatExpectedTimestampItemValues(123456789), + [ + 'value' => (new \DateTime())->setTimestamp(123456789)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], ]; } @@ -163,10 +169,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': return "The 'access news feeds' permission is required."; 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..fd82c7a 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/FieldConfig/FieldConfigResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/FieldConfig/FieldConfigResourceTestBase.php @@ -109,10 +109,6 @@ protected function getExpectedCacheContexts() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return "The 'administer node fields' permission is required."; } 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..817c8e8 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/FieldStorageConfig/FieldStorageConfigResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/FieldStorageConfig/FieldStorageConfigResourceTestBase.php @@ -79,10 +79,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': return "The 'administer node fields' permission is required."; 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..3dbc1ab 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ImageStyle/ImageStyleResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ImageStyle/ImageStyleResourceTestBase.php @@ -103,10 +103,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return "The 'administer image styles' permission is required."; } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Item/ItemResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Item/ItemResourceTestBase.php index f217b97..8ca3005 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Item/ItemResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Item/ItemResourceTestBase.php @@ -4,7 +4,6 @@ use Drupal\aggregator\Entity\Feed; use Drupal\aggregator\Entity\Item; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; /** @@ -12,8 +11,6 @@ */ abstract class ItemResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -116,7 +113,10 @@ protected function getExpectedNormalizedEntity() { 'author' => [], 'description' => [], 'timestamp' => [ - $this->formatExpectedTimestampItemValues(123456789), + [ + 'value' => (new \DateTime())->setTimestamp(123456789)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'guid' => [], ]; @@ -157,10 +157,6 @@ protected function getExpectedCacheContexts() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': return "The 'access news feeds' permission is required."; diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php index 475a1ca..5504ff4 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Media/MediaResourceTestBase.php @@ -11,8 +11,6 @@ abstract class MediaResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -175,13 +173,22 @@ protected function getExpectedNormalizedEntity() { ], ], 'created' => [ - $this->formatExpectedTimestampItemValues(123456789), + [ + 'value' => (new \DateTime())->setTimestamp(123456789)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'changed' => [ - $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), + [ + 'value' => (new \DateTime())->setTimestamp((int) $this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'revision_created' => [ - $this->formatExpectedTimestampItemValues((int) $this->entity->getRevisionCreationTime()), + [ + 'value' => (new \DateTime())->setTimestamp((int) $this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'default_langcode' => [ [ @@ -235,10 +242,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET'; return "The 'view media' permission is required and the media item must be published."; diff --git a/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentResourceTestBase.php index 0b1f967..c01c985 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentResourceTestBase.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\rest\Functional\EntityResource\MenuLinkContent; use Drupal\menu_link_content\Entity\MenuLinkContent; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; /** @@ -11,8 +10,6 @@ */ abstract class MenuLinkContentResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -164,7 +161,10 @@ protected function getExpectedNormalizedEntity() { ], ], 'changed' => [ - $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), + [ + 'value' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'default_langcode' => [ [ @@ -179,10 +179,6 @@ protected function getExpectedNormalizedEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'DELETE': return "You are not authorized to delete this menu_link_content entity."; diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Message/MessageResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Message/MessageResourceTestBase.php index 3f1cab9..75ebdd2 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Message/MessageResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Message/MessageResourceTestBase.php @@ -101,10 +101,6 @@ protected function getExpectedNormalizedEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - if ($method === 'POST') { return "The 'access site-wide contact form' permission is required."; } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php index 492ff64..2bb1b9e 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php @@ -4,15 +4,12 @@ use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use Drupal\user\Entity\User; use GuzzleHttp\RequestOptions; abstract class NodeResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -129,10 +126,16 @@ protected function getExpectedNormalizedEntity() { ], ], 'created' => [ - $this->formatExpectedTimestampItemValues(123456789), + [ + 'value' => (new \DateTime())->setTimestamp(123456789)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'changed' => [ - $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), + [ + 'value' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'promote' => [ [ @@ -145,7 +148,10 @@ protected function getExpectedNormalizedEntity() { ], ], 'revision_timestamp' => [ - $this->formatExpectedTimestampItemValues(123456789), + [ + 'value' => (new \DateTime())->setTimestamp(123456789)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'revision_translation_affected' => [ [ @@ -206,10 +212,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - if ($method === 'GET' || $method == 'PATCH' || $method == 'DELETE') { return "The 'access content' permission is required."; } 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..2bf5523 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/NodeType/NodeTypeResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/NodeType/NodeTypeResourceTestBase.php @@ -80,10 +80,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return "The 'access content' permission is required."; } 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..91d7c38 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ResponsiveImageStyle/ResponsiveImageStyleResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ResponsiveImageStyle/ResponsiveImageStyleResourceTestBase.php @@ -123,10 +123,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return "The 'administer responsive images' permission is required."; } 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..58cf9e2 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/SearchPage/SearchPageResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/SearchPage/SearchPageResourceTestBase.php @@ -86,10 +86,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': return "The 'access content' permission is required."; diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Shortcut/ShortcutResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Shortcut/ShortcutResourceTestBase.php index 36be5b5..c4cfd4b 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Shortcut/ShortcutResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Shortcut/ShortcutResourceTestBase.php @@ -144,10 +144,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': case 'POST': diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php index e0a1581..a9ca768 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php @@ -4,14 +4,11 @@ use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Vocabulary; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use GuzzleHttp\RequestOptions; abstract class TermResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -123,7 +120,10 @@ protected function getExpectedNormalizedEntity() { ], ], 'changed' => [ - $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), + [ + 'value' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'default_langcode' => [ [ @@ -168,10 +168,6 @@ protected function getNormalizedPostEntity() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': return "The 'access content' permission is required."; 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..7f0b99a 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Tour/TourResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Tour/TourResourceTestBase.php @@ -113,10 +113,6 @@ protected function getExpectedCacheContexts() { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - return "The following permissions are required: 'access tour' OR 'administer site configuration'."; } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/User/UserResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/User/UserResourceTestBase.php index d758cf6..8ebe7f8 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/User/UserResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/User/UserResourceTestBase.php @@ -3,15 +3,12 @@ namespace Drupal\Tests\rest\Functional\EntityResource\User; use Drupal\Core\Url; -use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; use Drupal\user\Entity\User; use GuzzleHttp\RequestOptions; abstract class UserResourceTestBase extends EntityResourceTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * {@inheritdoc} */ @@ -101,10 +98,16 @@ protected function getExpectedNormalizedEntity() { ], ], 'created' => [ - $this->formatExpectedTimestampItemValues(123456789), + [ + 'value' => (new \DateTime())->setTimestamp(123456789)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'changed' => [ - $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), + [ + 'value' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'default_langcode' => [ [ @@ -247,10 +250,6 @@ protected function assertRpcLogin($username, $password) { * {@inheritdoc} */ protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - switch ($method) { case 'GET': return "The 'access user profiles' permission is required and the user must be active."; diff --git a/core/modules/rest/tests/src/Functional/ResourceTestBase.php b/core/modules/rest/tests/src/Functional/ResourceTestBase.php index 0a0e34c..b30c5d4 100644 --- a/core/modules/rest/tests/src/Functional/ResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/ResourceTestBase.php @@ -163,7 +163,6 @@ protected function provisionResource($formats = [], $authentication = []) { * * Should be called after every change made to: * - RestResourceConfig entities - * - the 'rest.settings' simple configuration */ protected function refreshTestStateAfterRestConfigChange() { // Ensure that the cache tags invalidator has its internal values reset. @@ -171,8 +170,8 @@ protected function refreshTestStateAfterRestConfigChange() { $this->refreshVariables(); // Tests using this base class may trigger route rebuilds due to changes to - // RestResourceConfig entities or 'rest.settings'. Ensure the test generates - // routes using an up-to-date router. + // RestResourceConfig entities. Ensure the test generates routes using an + // up-to-date router. \Drupal::service('router.builder')->rebuildIfNeeded(); } diff --git a/core/modules/rest/tests/src/Functional/Update/EntityResourcePermissionsUpdateTest.php b/core/modules/rest/tests/src/Functional/Update/EntityResourcePermissionsUpdateTest.php deleted file mode 100644 index 9add9c5..0000000 --- a/core/modules/rest/tests/src/Functional/Update/EntityResourcePermissionsUpdateTest.php +++ /dev/null @@ -1,56 +0,0 @@ -databaseDumpFiles = [ - __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', - __DIR__ . '/../../../fixtures/update/drupal-8.rest-rest_update_8203.php', - ]; - } - - /** - * Tests rest_update_8203(). - */ - public function testBcEntityResourcePermissionSettingAdded() { - $permission_handler = $this->container->get('user.permissions'); - - $is_rest_resource_permission = function ($permission) { - return $permission['provider'] === 'rest' && (string) $permission['title'] !== 'Administer REST resource configuration'; - }; - - // Make sure we have the expected values before the update. - $rest_settings = $this->config('rest.settings'); - $this->assertFalse(array_key_exists('bc_entity_resource_permissions', $rest_settings->getRawData())); - $this->assertEqual([], array_filter($permission_handler->getPermissions(), $is_rest_resource_permission)); - - $this->runUpdates(); - - // Make sure we have the expected values after the update. - $rest_settings = $this->config('rest.settings'); - $this->assertTrue(array_key_exists('bc_entity_resource_permissions', $rest_settings->getRawData())); - $this->assertTrue($rest_settings->get('bc_entity_resource_permissions')); - $rest_permissions = array_keys(array_filter($permission_handler->getPermissions(), $is_rest_resource_permission)); - $this->assertEqual(['restful delete entity:node', 'restful get entity:node', 'restful patch entity:node', 'restful post entity:node'], $rest_permissions); - } - -} diff --git a/core/modules/rest/tests/src/Functional/Update/ResourceGranularityUpdateTest.php b/core/modules/rest/tests/src/Functional/Update/ResourceGranularityUpdateTest.php deleted file mode 100644 index 19ef545..0000000 --- a/core/modules/rest/tests/src/Functional/Update/ResourceGranularityUpdateTest.php +++ /dev/null @@ -1,71 +0,0 @@ -databaseDumpFiles = [ - __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', - __DIR__ . '/../../../fixtures/update/drupal-8.rest-rest_post_update_resource_granularity.php', - ]; - } - - /** - * Tests rest_post_update_simplify_resource_granularity(). - */ - public function testMethodGranularityConvertedToResourceGranularity() { - /** @var \Drupal\Core\Entity\EntityStorageInterface $resource_config_storage */ - $resource_config_storage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config'); - - // Make sure we have the expected values before the update. - $resource_config_entities = $resource_config_storage->loadMultiple(); - $this->assertIdentical(['entity.comment', 'entity.node', 'entity.user'], array_keys($resource_config_entities)); - $this->assertIdentical('method', $resource_config_entities['entity.node']->get('granularity')); - $this->assertIdentical('method', $resource_config_entities['entity.comment']->get('granularity')); - $this->assertIdentical('method', $resource_config_entities['entity.user']->get('granularity')); - - // Read the existing 'entity:comment' and 'entity:user' resource - // configuration so we can verify it after the update. - $comment_resource_configuration = $resource_config_entities['entity.comment']->get('configuration'); - $user_resource_configuration = $resource_config_entities['entity.user']->get('configuration'); - - $this->runUpdates(); - - // Make sure we have the expected values after the update. - $resource_config_entities = $resource_config_storage->loadMultiple(); - $this->assertIdentical(['entity.comment', 'entity.node', 'entity.user'], array_keys($resource_config_entities)); - // 'entity:node' should be updated. - $this->assertIdentical('resource', $resource_config_entities['entity.node']->get('granularity')); - $this->assertidentical($resource_config_entities['entity.node']->get('configuration'), [ - 'methods' => ['GET', 'POST', 'PATCH', 'DELETE'], - 'formats' => ['hal_json'], - 'authentication' => ['basic_auth'], - ]); - // 'entity:comment' should be unchanged. - $this->assertIdentical('method', $resource_config_entities['entity.comment']->get('granularity')); - $this->assertIdentical($comment_resource_configuration, $resource_config_entities['entity.comment']->get('configuration')); - // 'entity:user' should be unchanged. - $this->assertIdentical('method', $resource_config_entities['entity.user']->get('granularity')); - $this->assertIdentical($user_resource_configuration, $resource_config_entities['entity.user']->get('configuration')); - } - -} diff --git a/core/modules/rest/tests/src/Functional/Update/RestConfigurationEntitiesUpdateTest.php b/core/modules/rest/tests/src/Functional/Update/RestConfigurationEntitiesUpdateTest.php deleted file mode 100644 index f4d8199..0000000 --- a/core/modules/rest/tests/src/Functional/Update/RestConfigurationEntitiesUpdateTest.php +++ /dev/null @@ -1,65 +0,0 @@ -databaseDumpFiles = [ - __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', - __DIR__ . '/../../../fixtures/update/drupal-8.rest-rest_update_8201.php', - ]; - } - - /** - * Tests rest_update_8201(). - */ - public function testResourcesConvertedToConfigEntities() { - /** @var \Drupal\Core\Entity\EntityStorageInterface $resource_config_storage */ - $resource_config_storage = $this->container->get('entity_type.manager')->getStorage('rest_resource_config'); - - // Make sure we have the expected values before the update. - $rest_settings = $this->config('rest.settings'); - $this->assertTrue(array_key_exists('resources', $rest_settings->getRawData())); - $this->assertTrue(array_key_exists('entity:node', $rest_settings->getRawData()['resources'])); - $resource_config_entities = $resource_config_storage->loadMultiple(); - $this->assertIdentical([], array_keys($resource_config_entities)); - - $this->runUpdates(); - - // Make sure we have the expected values after the update. - $rest_settings = $this->config('rest.settings'); - $this->assertFalse(array_key_exists('resources', $rest_settings->getRawData())); - $resource_config_entities = $resource_config_storage->loadMultiple(); - $this->assertIdentical(['entity.node'], array_keys($resource_config_entities)); - $node_resource_config_entity = $resource_config_entities['entity.node']; - $this->assertIdentical(RestResourceConfigInterface::RESOURCE_GRANULARITY, $node_resource_config_entity->get('granularity')); - $this->assertIdentical([ - 'methods' => ['GET'], - 'formats' => ['json'], - 'authentication' => ['basic_auth'], - ], $node_resource_config_entity->get('configuration')); - $this->assertIdentical(['module' => ['basic_auth', 'node', 'serialization']], $node_resource_config_entity->getDependencies()); - } - -} diff --git a/core/modules/rest/tests/src/Functional/Update/RestExportAuthUpdateTest.php b/core/modules/rest/tests/src/Functional/Update/RestExportAuthUpdateTest.php deleted file mode 100644 index 87cd5db..0000000 --- a/core/modules/rest/tests/src/Functional/Update/RestExportAuthUpdateTest.php +++ /dev/null @@ -1,36 +0,0 @@ -databaseDumpFiles = [ - __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', - __DIR__ . '/../../../../tests/fixtures/update/rest-export-with-authentication.php', - ]; - } - - /** - * Ensures that update hook is run for rest module. - */ - public function testUpdate() { - $this->runUpdates(); - - // Get particular view. - $view = \Drupal::entityTypeManager()->getStorage('view')->load('rest_export_with_authorization'); - $displays = $view->get('display'); - $this->assertIdentical($displays['rest_export_1']['display_options']['auth']['basic_auth'], 'basic_auth', 'Basic authentication is set as authentication method.'); - } - -} diff --git a/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php b/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php index 5b71b93..5bde06b 100644 --- a/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php +++ b/core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php @@ -13,8 +13,6 @@ */ class EntitySerializationTest extends NormalizerTestBase { - use BcTimestampNormalizerUnixTestTrait; - /** * Modules to install. * @@ -109,7 +107,10 @@ public function testNormalize() { ['value' => 'entity_test_mulrev'], ], 'created' => [ - $this->formatExpectedTimestampItemValues($this->entity->created->value), + [ + 'value' => (new \DateTime())->setTimestamp((int) $this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), + 'format' => \DateTime::RFC3339, + ], ], 'user_id' => [ [