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 | 60 --
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 +-
core/modules/rest/src/RestServiceProvider.php | 51 --
core/modules/rest/src/Tests/RESTTestBase.php | 624 ---------------------
....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 --
.../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 -
.../Comment/CommentResourceTestBase.php | 17 +-
.../Editor/EditorResourceTestBase.php | 4 -
.../EntityResource/EntityResourceTestBase.php | 171 ------
.../EntityTest/EntityTestResourceTestBase.php | 12 +-
.../EntityTestLabelResourceTestBase.php | 12 +-
.../EntityResource/Feed/FeedResourceTestBase.php | 22 +-
.../FieldConfig/FieldConfigResourceTestBase.php | 4 -
.../FieldStorageConfigResourceTestBase.php | 4 -
.../ImageStyle/ImageStyleResourceTestBase.php | 4 -
.../EntityResource/Item/ItemResourceTestBase.php | 12 +-
.../MenuLinkContentResourceTestBase.php | 12 +-
.../EntityResource/Node/NodeResourceTestBase.php | 22 +-
.../NodeType/NodeTypeResourceTestBase.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 +-
.../Update/EntityResourcePermissionsUpdateTest.php | 56 --
.../Update/ResourceGranularityUpdateTest.php | 71 ---
.../Update/RestConfigurationEntitiesUpdateTest.php | 65 ---
.../Functional/Update/RestExportAuthUpdateTest.php | 36 --
53 files changed, 62 insertions(+), 1963 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 32c5b1d..c2d9412 100644
--- a/core/modules/rest/rest.install
+++ b/core/modules/rest/rest.install
@@ -24,63 +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);
-}
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/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 40a9fe2..0000000
--- a/core/modules/rest/src/Tests/RESTTestBase.php
+++ /dev/null
@@ -1,624 +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/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 aa94c63..0000000
Binary files a/core/modules/rest/tests/fixtures/update/drupal-8.rest-rest_post_update_resource_granularity.php and /dev/null differ
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.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/Comment/CommentResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php
index 5b51014..cbd6075 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/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/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
index f39b7d8..2485d0c 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
@@ -228,11 +228,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.";
@@ -497,91 +492,6 @@ public function testGet() {
}
$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();
@@ -865,45 +775,6 @@ public function testPost() {
$this->assertArraySubset(static::castToString($field_normalization), $created_entity->get($field_name)->getValue(), TRUE);
}
}
-
-
- $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.
- // Delete the first created entity in case there is a uniqueness constraint.
- $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);
- }
}
/**
@@ -1099,25 +970,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'));
}
/**
@@ -1207,29 +1059,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 e2c0ccd..09d9649 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}
*/
@@ -95,7 +92,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' => [
[
@@ -133,10 +133,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/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/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/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/Node/NodeResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php
index b4fc553..7c53063 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/Node/NodeResourceTestBase.php
@@ -4,14 +4,11 @@
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;
abstract class NodeResourceTestBase extends EntityResourceTestBase {
- use BcTimestampNormalizerUnixTestTrait;
-
/**
* {@inheritdoc}
*/
@@ -128,10 +125,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' => [
[
@@ -144,7 +147,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' => [
[
@@ -205,10 +211,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/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 44a4e83..2bec08a 100644
--- a/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php
+++ b/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php
@@ -4,13 +4,10 @@
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
-use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class TermResourceTestBase extends EntityResourceTestBase {
- use BcTimestampNormalizerUnixTestTrait;
-
/**
* {@inheritdoc}
*/
@@ -115,7 +112,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' => [
[
@@ -160,10 +160,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 caf2909..625d1f7 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' => [
[
@@ -263,10 +266,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/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.');
- }
-
-}