composer.json | 3 +- jsonapi.info.yml | 3 - jsonapi.module | 16 ---- jsonapi.services.yml | 1 - src/Access/TemporaryQueryGuard.php | 13 ---- .../tests/Traits/ContentModerationTestTrait.php | 91 ---------------------- .../tests/Traits/EntityReferenceTestTrait.php | 67 ---------------- src/EventSubscriber/ResourceResponseValidator.php | 72 +---------------- src/JsonapiServiceProvider.php | 22 ------ src/Routing/Routes.php | 5 -- tests/src/Functional/BlockContentTest.php | 7 +- tests/src/Functional/BlockTest.php | 2 +- tests/src/Functional/CommentTest.php | 50 ++---------- tests/src/Functional/ConfigTestTest.php | 2 +- tests/src/Functional/EntityTestMapFieldTest.php | 3 - tests/src/Functional/EntityViewDisplayTest.php | 9 +-- tests/src/Functional/ExternalNormalizersTest.php | 5 +- tests/src/Functional/FileTest.php | 3 +- tests/src/Functional/FileUploadTest.php | 3 - tests/src/Functional/ImageStyleTest.php | 6 +- tests/src/Functional/InternalEntitiesTest.php | 2 +- tests/src/Functional/JsonApiFunctionalTestBase.php | 2 +- tests/src/Functional/MediaTest.php | 23 +----- tests/src/Functional/MenuLinkContentTest.php | 2 +- tests/src/Functional/ResourceTestBase.php | 23 ++---- tests/src/Functional/ShortcutSetTest.php | 2 +- tests/src/Functional/TermTest.php | 42 ++-------- tests/src/Functional/UserTest.php | 9 +-- tests/src/Functional/VocabularyTest.php | 6 +- .../JsonApiDocumentTopLevelNormalizerTest.php | 4 +- ...mmonCollectionFilterAccessTestPatternsTrait.php | 2 +- .../ResourceResponseValidatorTest.php | 72 ----------------- 32 files changed, 42 insertions(+), 530 deletions(-) diff --git a/composer.json b/composer.json index 970aa03..270bbc8 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,6 @@ "type": "drupal-module", "license": "GPL-2.0+", "require-dev": { - "justinrainbow/json-schema": "^5.2", - "drupal/schemata": "1.x-dev#8325d172e1d6880aa24073f8f751ef089282cf9a" + "justinrainbow/json-schema": "^5.2" } } diff --git a/jsonapi.info.yml b/jsonapi.info.yml index f2135bc..a333090 100644 --- a/jsonapi.info.yml +++ b/jsonapi.info.yml @@ -4,7 +4,4 @@ description: Provides a JSON:API standards-compliant API for accessing and manip core: 8.x package: Web services dependencies: - - drupal:system (>=8.5.4) - drupal:serialization -test_dependencies: - - schemata:schemata_json_schema diff --git a/jsonapi.module b/jsonapi.module index a092541..f1256bf 100644 --- a/jsonapi.module +++ b/jsonapi.module @@ -98,22 +98,6 @@ function jsonapi_help($route_name, RouteMatchInterface $route_match) { return NULL; } -/** - * Implements hook_entity_bundle_field_info(). - */ -function jsonapi_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) { - $fields = []; - - if (floatval(\Drupal::VERSION) < 8.6 && $entity_type->id() == 'taxonomy_term') { - // Only terms in the same bundle can be a parent. - $fields['parent'] = clone $base_field_definitions['parent']; - $fields['parent']->setSetting('handler_settings', ['target_bundles' => [$bundle]]); - return $fields; - } - - return $fields; -} - /** * Implements hook_entity_bundle_create(). */ diff --git a/jsonapi.services.yml b/jsonapi.services.yml index 44309dc..ca8ef22 100644 --- a/jsonapi.services.yml +++ b/jsonapi.services.yml @@ -210,7 +210,6 @@ services: arguments: ['@jsonapi.serializer_do_not_use_removal_imminent', '@logger.channel.jsonapi', '@module_handler', '@app.root'] calls: - [setValidator, []] - - [setSchemaFactory, ['@?schemata.schema_factory']] # This is only injected when the service is available. tags: - { name: event_subscriber, priority: 1000 } diff --git a/src/Access/TemporaryQueryGuard.php b/src/Access/TemporaryQueryGuard.php index 618e48e..8150350 100644 --- a/src/Access/TemporaryQueryGuard.php +++ b/src/Access/TemporaryQueryGuard.php @@ -374,15 +374,6 @@ class TemporaryQueryGuard { $cacheability->addCacheTags($entity_type->getListCacheTags()); } } - // @todo Remove when Drupal 8.5 support is dropped (terms are publishable in >=8.6). - if (floatval(\Drupal::VERSION) < 8.6 && $entity_type->id() === 'taxonomy_term') { - $access_result = $access_results[JSONAPI_FILTER_AMONG_PUBLISHED]; - $cacheability->addCacheableDependency($access_result); - if ($access_result->isAllowed()) { - $conditions[] = new EntityCondition('tid', 0, '>'); - $cacheability->addCacheTags($entity_type->getListCacheTags()); - } - } // The "enabled" subset. // @todo Remove ternary when the 'status' key is added to the User entity type. @@ -399,10 +390,6 @@ class TemporaryQueryGuard { // The "owner" subset. // @todo Remove ternary when the 'uid' key is added to the User entity type. $owner_field_name = $entity_type->id() === 'user' ? 'uid' : $entity_type->getKey('owner'); - // @todo Remove when Drupal 8.5 and 8.6 support is dropped. - if (floatval(\Drupal::VERSION) < 8.7) { - $owner_field_name = $entity_type->id() === 'user' ? $owner_field_name : $entity_type->getKey('uid'); - } if ($owner_field_name) { $access_result = $access_results[JSONAPI_FILTER_AMONG_OWN]; $cacheability->addCacheableDependency($access_result); diff --git a/src/BackwardCompatibility/tests/Traits/ContentModerationTestTrait.php b/src/BackwardCompatibility/tests/Traits/ContentModerationTestTrait.php deleted file mode 100644 index 310bcfb..0000000 --- a/src/BackwardCompatibility/tests/Traits/ContentModerationTestTrait.php +++ /dev/null @@ -1,91 +0,0 @@ -=8.6 - */ -trait ContentModerationTestTrait { - - /** - * Creates the editorial workflow. - * - * @return \Drupal\workflows\Entity\Workflow - * The editorial workflow entity. - */ - protected function createEditorialWorkflow() { - $workflow = Workflow::create([ - 'type' => 'content_moderation', - 'id' => 'editorial', - 'label' => 'Editorial', - 'type_settings' => [ - 'states' => [ - 'archived' => [ - 'label' => 'Archived', - 'weight' => 5, - 'published' => FALSE, - 'default_revision' => TRUE, - ], - 'draft' => [ - 'label' => 'Draft', - 'published' => FALSE, - 'default_revision' => FALSE, - 'weight' => -5, - ], - 'published' => [ - 'label' => 'Published', - 'published' => TRUE, - 'default_revision' => TRUE, - 'weight' => 0, - ], - ], - 'transitions' => [ - 'archive' => [ - 'label' => 'Archive', - 'from' => ['published'], - 'to' => 'archived', - 'weight' => 2, - ], - 'archived_draft' => [ - 'label' => 'Restore to Draft', - 'from' => ['archived'], - 'to' => 'draft', - 'weight' => 3, - ], - 'archived_published' => [ - 'label' => 'Restore', - 'from' => ['archived'], - 'to' => 'published', - 'weight' => 4, - ], - 'create_new_draft' => [ - 'label' => 'Create New Draft', - 'to' => 'draft', - 'weight' => 0, - 'from' => [ - 'draft', - 'published', - ], - ], - 'publish' => [ - 'label' => 'Publish', - 'to' => 'published', - 'weight' => 1, - 'from' => [ - 'draft', - 'published', - ], - ], - ], - ], - ]); - $workflow->save(); - return $workflow; - } - -} diff --git a/src/BackwardCompatibility/tests/Traits/EntityReferenceTestTrait.php b/src/BackwardCompatibility/tests/Traits/EntityReferenceTestTrait.php deleted file mode 100644 index 2c8a5e3..0000000 --- a/src/BackwardCompatibility/tests/Traits/EntityReferenceTestTrait.php +++ /dev/null @@ -1,67 +0,0 @@ -=8.6 - */ -trait EntityReferenceTestTrait { - - /** - * Creates an entity reference field storage on the specified bundle. - * - * @param string $entity_type - * The type of entity the field will be attached to. - * @param string $bundle - * The bundle name of the entity the field will be attached to. - * @param string $field_name - * The name of the field; if it already exists, a new instance of the - * existing field will be created. - * @param string $field_label - * The label of the field. - * @param string $target_entity_type - * The type of the referenced entity. - * @param string $selection_handler - * The selection handler used by this field. - * @param array $selection_handler_settings - * An array of settings supported by the selection handler specified above. - * (e.g. 'target_bundles', 'sort', 'auto_create', etc). - * @param int $cardinality - * The cardinality of the field. - * - * @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm() - */ - protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', array $selection_handler_settings = [], $cardinality = 1) { - // Look for or add the specified field to the requested entity bundle. - if (!FieldStorageConfig::loadByName($entity_type, $field_name)) { - FieldStorageConfig::create([ - 'field_name' => $field_name, - 'type' => 'entity_reference', - 'entity_type' => $entity_type, - 'cardinality' => $cardinality, - 'settings' => [ - 'target_type' => $target_entity_type, - ], - ])->save(); - } - if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) { - FieldConfig::create([ - 'field_name' => $field_name, - 'entity_type' => $entity_type, - 'bundle' => $bundle, - 'label' => $field_label, - 'settings' => [ - 'handler' => $selection_handler, - 'handler_settings' => $selection_handler_settings, - ], - ])->save(); - } - } - -} diff --git a/src/EventSubscriber/ResourceResponseValidator.php b/src/EventSubscriber/ResourceResponseValidator.php index 6823498..d19154e 100644 --- a/src/EventSubscriber/ResourceResponseValidator.php +++ b/src/EventSubscriber/ResourceResponseValidator.php @@ -5,11 +5,8 @@ namespace Drupal\jsonapi\EventSubscriber; use Drupal\Component\Serialization\Json; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\jsonapi\ResourceResponse; -use Drupal\jsonapi\Routing\Routes; -use Drupal\schemata\SchemaFactory; use JsonSchema\Validator; use Psr\Log\LoggerInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -50,15 +47,6 @@ class ResourceResponseValidator implements EventSubscriberInterface { */ protected $validator; - /** - * The schemata schema factory. - * - * This property will only be set if the schemata module is installed. - * - * @var \Drupal\schemata\SchemaFactory|null - */ - protected $schemaFactory; - /** * The module handler. * @@ -112,16 +100,6 @@ class ResourceResponseValidator implements EventSubscriberInterface { } } - /** - * Injects the schema factory. - * - * @param \Drupal\schemata\SchemaFactory $schema_factory - * The schema factory service. - */ - public function setSchemaFactory(SchemaFactory $schema_factory) { - $this->schemaFactory = $schema_factory; - } - /** * Validates JSON:API responses. * @@ -180,56 +158,8 @@ class ResourceResponseValidator implements EventSubscriberInterface { ]) ); $generic_jsonapi_schema = (object) ['$ref' => $schema_ref]; - $is_valid = $this->validateSchema($generic_jsonapi_schema, $response_data); - if (!$is_valid) { - return FALSE; - } - // This will be set if the schemata module is present. - if (!$this->schemaFactory) { - // Fall back the valid generic result since schemata is absent. - return TRUE; - } - - // Get the schema for the current resource. For that we will need to - // introspect the request to find the entity type and bundle matched by the - // router. - $resource_type = $request->get(Routes::RESOURCE_TYPE_KEY); - $route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME); - - // We shouldn't validate related/relationships. - $is_related = strpos($route_name, '.related') !== FALSE; - $is_relationship = strpos($route_name, '.relationship') !== FALSE; - if ($is_related || $is_relationship) { - // Fall back the valid generic result since schemata is absent. - return TRUE; - } - - $entity_type_id = $resource_type->getEntityTypeId(); - $bundle = $resource_type->getBundle(); - $output_format = 'schema_json'; - $described_format = 'api_json'; - - $schema_object = $this->schemaFactory->create($entity_type_id, $bundle); - $format = $output_format . ':' . $described_format; - $output = $this->serializer->serialize($schema_object, $format); - $specific_schema = Json::decode($output); - if (!$specific_schema) { - return $is_valid; - } - - // We need to individually validate each collection resource object. - $is_collection = strpos($route_name, '.collection') !== FALSE; - - // Iterate over each resource object and check the schema. - return array_reduce( - $is_collection ? $response_data->data : [$response_data->data], - function ($valid, $resource_object) use ($specific_schema) { - // Validating the schema first ensures that every object is processed. - return $this->validateSchema($specific_schema, $resource_object) && $valid; - }, - TRUE - ); + return $this->validateSchema($generic_jsonapi_schema, $response_data); } /** diff --git a/src/JsonapiServiceProvider.php b/src/JsonapiServiceProvider.php index 3d3a788..9721af1 100644 --- a/src/JsonapiServiceProvider.php +++ b/src/JsonapiServiceProvider.php @@ -9,7 +9,6 @@ use Drupal\Core\StackMiddleware\NegotiationMiddleware; use Drupal\jsonapi\DependencyInjection\Compiler\RegisterSerializationClassesCompilerPass; use Drupal\jsonapi\DependencyInjection\Compiler\RemoveJsonapiFormatCompilerPass; use Symfony\Component\DependencyInjection\Compiler\PassConfig; -use Symfony\Component\DependencyInjection\Reference; /** * Adds 'api_json' as known format and prevents its use in the REST module. @@ -22,35 +21,14 @@ class JsonapiServiceProvider implements ServiceModifierInterface, ServiceProvide * {@inheritdoc} */ public function alter(ContainerBuilder $container) { - // @todo Remove when we stop supporting Drupal 8.5. - if (floatval(\Drupal::VERSION) < 8.6) { - // Swap the cache service back. - $definition = $container->getDefinition('jsonapi.resource_type.repository'); - $definition->setArgument(3, new Reference('cache.static')); - $container->setDefinition('jsonapi.resource_type.repository', $definition); - - // Drop the new service definition. - $container->removeDefinition('cache.jsonapi_resource_types'); - } - if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')->getClass(), NegotiationMiddleware::class, TRUE)) { // @see http://www.iana.org/assignments/media-types/application/vnd.api+json $container->getDefinition('http_middleware.negotiation') ->addMethodCall('registerFormat', [ 'api_json', ['application/vnd.api+json'], - ]) - ->addMethodCall('registerFormat', [ - 'bin', - ['application/octet-stream'], ]); } - - // @todo Remove this when JSON:API requires Drupal >=8.6, see https://www.drupal.org/node/1927648. - if (floatval(\Drupal::VERSION) < 8.6) { - $container->removeDefinition('jsonapi.file_upload'); - $container->removeDefinition('file.uploader'); - } } /** diff --git a/src/Routing/Routes.php b/src/Routing/Routes.php index 3ccfd29..230d6de 100644 --- a/src/Routing/Routes.php +++ b/src/Routing/Routes.php @@ -205,11 +205,6 @@ class Routes implements ContainerInjectionInterface { * The route collection. */ protected static function getFileUploadRoutesForResourceType(ResourceType $resource_type, $path_prefix) { - // @todo Remove this when JSON:API requires Drupal >=8.6, see https://www.drupal.org/node/1927648. - if (\Drupal::VERSION < 8.6) { - return new RouteCollection(); - } - $routes = new RouteCollection(); // Internal resources have no routes; individual routes require locations. diff --git a/tests/src/Functional/BlockContentTest.php b/tests/src/Functional/BlockContentTest.php index 9cd9ff0..3168383 100644 --- a/tests/src/Functional/BlockContentTest.php +++ b/tests/src/Functional/BlockContentTest.php @@ -86,7 +86,7 @@ class BlockContentTest extends ResourceTestBase { */ protected function getExpectedDocument() { $self_url = Url::fromUri('base:/jsonapi/block_content/basic/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); - $expected_document = [ + return [ 'jsonapi' => [ 'meta' => [ 'links' => [ @@ -121,6 +121,7 @@ class BlockContentTest extends ResourceTestBase { 'default_langcode' => TRUE, 'drupal_internal__id' => 1, 'drupal_internal__revision_id' => 1, + 'reusable' => TRUE, ], 'relationships' => [ 'block_content_type' => [ @@ -143,10 +144,6 @@ class BlockContentTest extends ResourceTestBase { ], ], ]; - if (floatval(\Drupal::VERSION) >= 8.6) { - $expected_document['data']['attributes']['reusable'] = TRUE; - } - return $expected_document; } /** diff --git a/tests/src/Functional/BlockTest.php b/tests/src/Functional/BlockTest.php index b88ef23..da080af 100644 --- a/tests/src/Functional/BlockTest.php +++ b/tests/src/Functional/BlockTest.php @@ -156,7 +156,7 @@ class BlockTest extends ResourceTestBase { protected function getExpectedUnauthorizedAccessMessage($method) { switch ($method) { case 'GET': - return floatval(\Drupal::VERSION >= 8.7) ? "The block visibility condition 'user_role' denied access." : ''; + return "The block visibility condition 'user_role' denied access."; default: return parent::getExpectedUnauthorizedAccessMessage($method); diff --git a/tests/src/Functional/CommentTest.php b/tests/src/Functional/CommentTest.php index effce39..c197b02 100644 --- a/tests/src/Functional/CommentTest.php +++ b/tests/src/Functional/CommentTest.php @@ -66,20 +66,6 @@ class CommentTest extends ResourceTestBase { */ protected $entity; - /** - * {@inheritdoc} - */ - public function setUp() { - parent::setUp(); - - // @todo Remove this when only Drupal >= 8.7 is supported; validation order changed in 8.7. - if (floatval(\Drupal::VERSION) < 8.7) { - $tmp = static::$patchProtectedFieldNames['uid']; - unset(static::$patchProtectedFieldNames['uid']); - static::$patchProtectedFieldNames['uid'] = $tmp; - } - } - /** * {@inheritdoc} */ @@ -289,10 +275,7 @@ class CommentTest extends ResourceTestBase { return "The 'post comments' permission is required."; case 'PATCH': - // @todo Make this unconditional when JSON:API requires Drupal 8.6 or newer. - if (floatval(\Drupal::VERSION) >= 8.6) { - return "The 'edit own comments' permission is required, the user must be the comment author, and the comment must be published."; - } + return "The 'edit own comments' permission is required, the user must be the comment author, and the comment must be published."; default: return parent::getExpectedUnauthorizedAccessMessage($method); @@ -329,40 +312,17 @@ class CommentTest extends ResourceTestBase { // DX: 422 when missing 'entity_type' field. $request_options[RequestOptions::BODY] = Json::encode($remove_field($this->getPostDocument(), 'attributes', 'entity_type')); $response = $this->request('POST', $url, $request_options); - if (floatval(\Drupal::VERSION) >= 8.7) { - $this->assertResourceErrorResponse(422, 'entity_type: This value should not be null.', NULL, $response, '/data/attributes/entity_type'); - } - else { - $this->assertResourceErrorResponse(500, 'The "" entity type does not exist.', $url, $response, FALSE); - } + $this->assertResourceErrorResponse(422, 'entity_type: This value should not be null.', NULL, $response, '/data/attributes/entity_type'); // DX: 422 when missing 'entity_id' field. $request_options[RequestOptions::BODY] = Json::encode($remove_field($this->getPostDocument(), 'relationships', 'entity_id')); - // @todo Remove the try/catch in https://www.drupal.org/node/2820364. - try { - $response = $this->request('POST', $url, $request_options); - if (floatval(\Drupal::VERSION) >= 8.7) { - $this->assertResourceErrorResponse(422, 'entity_id: This value should not be null.', NULL, $response, '/data/attributes/entity_id'); - } - } - catch (\Exception $e) { - if (version_compare(phpversion(), '7.0') >= 0) { - $this->assertSame("Error: Call to a member function get() on null\nDrupal\\comment\\Plugin\\Validation\\Constraint\\CommentNameConstraintValidator->getAnonymousContactDetailsSetting()() (Line: 96)\n", $e->getMessage()); - } - else { - $this->assertSame(500, $response->getStatusCode()); - } - } + $response = $this->request('POST', $url, $request_options); + $this->assertResourceErrorResponse(422, 'entity_id: This value should not be null.', NULL, $response, '/data/attributes/entity_id'); // DX: 422 when missing 'field_name' field. $request_options[RequestOptions::BODY] = Json::encode($remove_field($this->getPostDocument(), 'attributes', 'field_name')); $response = $this->request('POST', $url, $request_options); - if (floatval(\Drupal::VERSION) >= 8.7) { - $this->assertResourceErrorResponse(422, 'field_name: This value should not be null.', NULL, $response, '/data/attributes/field_name'); - } - else { - $this->assertSame(500, $response->getStatusCode()); - } + $this->assertResourceErrorResponse(422, 'field_name: This value should not be null.', NULL, $response, '/data/attributes/field_name'); } /** diff --git a/tests/src/Functional/ConfigTestTest.php b/tests/src/Functional/ConfigTestTest.php index df8da49..e6d873d 100644 --- a/tests/src/Functional/ConfigTestTest.php +++ b/tests/src/Functional/ConfigTestTest.php @@ -47,7 +47,7 @@ class ConfigTestTest extends ResourceTestBase { protected function getExpectedUnauthorizedAccessMessage($method) { switch ($method) { case 'GET': - return floatval(\Drupal::VERSION >= 8.7) ? "The 'view config_test' permission is required." : ''; + return "The 'view config_test' permission is required."; default: return parent::getExpectedUnauthorizedAccessMessage($method); diff --git a/tests/src/Functional/EntityTestMapFieldTest.php b/tests/src/Functional/EntityTestMapFieldTest.php index 38326eb..b78f96c 100644 --- a/tests/src/Functional/EntityTestMapFieldTest.php +++ b/tests/src/Functional/EntityTestMapFieldTest.php @@ -10,9 +10,6 @@ use Drupal\user\Entity\User; * JSON:API integration test for the "EntityTestMapField" content entity type. * * @group jsonapi - * @requires function Drupal\entity_test\Entity\EntityTestMapField::baseFieldDefinitions - * - * @todo Remove the "@requires" annotation when JSON:API requires Drupal >=8.6 */ class EntityTestMapFieldTest extends ResourceTestBase { diff --git a/tests/src/Functional/EntityViewDisplayTest.php b/tests/src/Functional/EntityViewDisplayTest.php index cd5fa95..1b154cc 100644 --- a/tests/src/Functional/EntityViewDisplayTest.php +++ b/tests/src/Functional/EntityViewDisplayTest.php @@ -70,7 +70,7 @@ class EntityViewDisplayTest extends ResourceTestBase { */ protected function getExpectedDocument() { $self_url = Url::fromUri('base:/jsonapi/entity_view_display/entity_view_display/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); - $document = [ + return [ 'jsonapi' => [ 'meta' => [ 'links' => [ @@ -94,6 +94,8 @@ class EntityViewDisplayTest extends ResourceTestBase { 'links' => [ 'region' => 'content', 'weight' => 100, + 'settings' => [], + 'third_party_settings' => [], ], ], 'dependencies' => [ @@ -113,11 +115,6 @@ class EntityViewDisplayTest extends ResourceTestBase { ], ], ]; - if (floatval(\Drupal::VERSION) >= 8.6) { - $document['data']['attributes']['content']['links']['settings'] = []; - $document['data']['attributes']['content']['links']['third_party_settings'] = []; - } - return $document; } /** diff --git a/tests/src/Functional/ExternalNormalizersTest.php b/tests/src/Functional/ExternalNormalizersTest.php index b28e125..e520a60 100644 --- a/tests/src/Functional/ExternalNormalizersTest.php +++ b/tests/src/Functional/ExternalNormalizersTest.php @@ -135,10 +135,7 @@ class ExternalNormalizersTest extends BrowserTestBase { $core_normalization['field_test'][0]['value'] = static::VALUE_OVERRIDDEN; $denormalized_entity = $this->container->get('serializer')->denormalize($core_normalization, EntityTest::class, 'json', []); $this->assertInstanceOf(EntityTest::class, $denormalized_entity); - // @todo Make this unconditional once https://www.drupal.org/project/drupal/issues/2957385 lands — JSON:API fixed denormalization of properties in https://www.drupal.org/project/jsonapi/issues/2955615, core's Serialization module still has to follow - if ($test_module === 'jsonapi_test_field_type') { - $this->assertSame(static::VALUE_ORIGINAL, $denormalized_entity->field_test->value); - } + $this->assertSame(static::VALUE_ORIGINAL, $denormalized_entity->field_test->value); // Asserts the expected JSON:API normalization. // @todo Remove line below in favor of commented line in https://www.drupal.org/project/jsonapi/issues/2878463. diff --git a/tests/src/Functional/FileTest.php b/tests/src/Functional/FileTest.php index 342cf78..ff67417 100644 --- a/tests/src/Functional/FileTest.php +++ b/tests/src/Functional/FileTest.php @@ -203,8 +203,7 @@ class FileTest extends ResourceTestBase { if ($method === 'GET') { return "The 'access content' permission is required."; } - // @todo Make this unconditional when JSON:API requires Drupal 8.6 or newer. - if (floatval(\Drupal::VERSION) >= 8.6 && ($method === 'PATCH' || $method === 'DELETE')) { + if ($method === 'PATCH' || $method === 'DELETE') { return "Only the file owner can update or delete the file entity."; } return parent::getExpectedUnauthorizedAccessMessage($method); diff --git a/tests/src/Functional/FileUploadTest.php b/tests/src/Functional/FileUploadTest.php index 69e9a77..1c380aa 100644 --- a/tests/src/Functional/FileUploadTest.php +++ b/tests/src/Functional/FileUploadTest.php @@ -19,9 +19,6 @@ use Psr\Http\Message\ResponseInterface; * Tests binary data file upload route. * * @group jsonapi - * @requires function Drupal\file\Plugin\rest\resource\FileUploadResource::post - * - * @todo Remove the "@requires" annotation when JSON:API requires Drupal >=8.6 */ class FileUploadTest extends ResourceTestBase { diff --git a/tests/src/Functional/ImageStyleTest.php b/tests/src/Functional/ImageStyleTest.php index f6d7a36..55193d8 100644 --- a/tests/src/Functional/ImageStyleTest.php +++ b/tests/src/Functional/ImageStyleTest.php @@ -79,7 +79,7 @@ class ImageStyleTest extends ResourceTestBase { */ protected function getExpectedDocument() { $self_url = Url::fromUri('base:/jsonapi/image_style/image_style/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); - $doc = [ + return [ 'jsonapi' => [ 'meta' => [ 'links' => [ @@ -118,10 +118,6 @@ class ImageStyleTest extends ResourceTestBase { ], ], ]; - if (floatval(\Drupal::VERSION) < 8.6) { - unset($doc['data']['attributes']['effects'][$this->effectUuid]['data']['anchor']); - } - return $doc; } /** diff --git a/tests/src/Functional/InternalEntitiesTest.php b/tests/src/Functional/InternalEntitiesTest.php index 1a0a85b..e170222 100644 --- a/tests/src/Functional/InternalEntitiesTest.php +++ b/tests/src/Functional/InternalEntitiesTest.php @@ -7,8 +7,8 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\entity_test\Entity\EntityTestBundle; use Drupal\entity_test\Entity\EntityTestNoLabel; use Drupal\entity_test\Entity\EntityTestWithBundle; -use Drupal\jsonapi\BackwardCompatibility\tests\Traits\EntityReferenceTestTrait; use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\field\Traits\EntityReferenceTestTrait; /** * Makes assertions about the JSON:API behavior for internal entities. diff --git a/tests/src/Functional/JsonApiFunctionalTestBase.php b/tests/src/Functional/JsonApiFunctionalTestBase.php index dbad32e..87ab13e 100644 --- a/tests/src/Functional/JsonApiFunctionalTestBase.php +++ b/tests/src/Functional/JsonApiFunctionalTestBase.php @@ -7,10 +7,10 @@ use Drupal\Core\Url; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\file\Entity\File; -use Drupal\jsonapi\BackwardCompatibility\tests\Traits\EntityReferenceTestTrait; use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Vocabulary; use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\field\Traits\EntityReferenceTestTrait; use Drupal\Tests\image\Kernel\ImageFieldCreationTrait; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; diff --git a/tests/src/Functional/MediaTest.php b/tests/src/Functional/MediaTest.php index 864b56b..30b4bb4 100644 --- a/tests/src/Functional/MediaTest.php +++ b/tests/src/Functional/MediaTest.php @@ -145,7 +145,7 @@ class MediaTest extends ResourceTestBase { $thumbnail = File::load(3); $author = User::load($this->entity->getOwnerId()); $self_url = Url::fromUri('base:/jsonapi/media/camelids/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); - $data = [ + return [ 'jsonapi' => [ 'meta' => [ 'links' => [ @@ -243,12 +243,6 @@ class MediaTest extends ResourceTestBase { ], ], ]; - // @todo Make this unconditional when JSON:API requires Drupal 8.6 or newer. - if (floatval(\Drupal::VERSION) < 8.6) { - $data['data']['relationships']['thumbnail']['data']['meta']['alt'] = 'Thumbnail'; - $data['data']['relationships']['thumbnail']['data']['meta']['title'] = 'Llama'; - } - return $data; } /** @@ -290,16 +284,10 @@ class MediaTest extends ResourceTestBase { return "The following permissions are required: 'administer media' OR 'create media' OR 'create camelids media'."; case 'PATCH': - // @todo Make this unconditional when JSON:API requires Drupal 8.6 or newer. - if (floatval(\Drupal::VERSION) >= 8.6) { - return "The following permissions are required: 'update any media' OR 'update own media' OR 'camelids: edit any media' OR 'camelids: edit own media'."; - } + return "The following permissions are required: 'update any media' OR 'update own media' OR 'camelids: edit any media' OR 'camelids: edit own media'."; case 'DELETE': - // @todo Make this unconditional when JSON:API requires Drupal 8.6 or newer. - if (floatval(\Drupal::VERSION) >= 8.6) { - return "The following permissions are required: 'delete any media' OR 'delete own media' OR 'camelids: delete any media' OR 'camelids: delete own media'."; - } + return "The following permissions are required: 'delete any media' OR 'delete own media' OR 'camelids: delete any media' OR 'camelids: delete own media'."; default: return ''; @@ -348,11 +336,6 @@ class MediaTest extends ResourceTestBase { 'height' => 180, 'title' => NULL, ]; - // @todo Make this unconditional when JSON:API requires Drupal 8.6 or newer. - if (floatval(\Drupal::VERSION) < 8.6) { - $data['meta']['alt'] = 'Thumbnail'; - $data['meta']['title'] = 'Llama'; - } return $data; case 'field_media_file': diff --git a/tests/src/Functional/MenuLinkContentTest.php b/tests/src/Functional/MenuLinkContentTest.php index c60d162..2e6b04c 100644 --- a/tests/src/Functional/MenuLinkContentTest.php +++ b/tests/src/Functional/MenuLinkContentTest.php @@ -139,7 +139,7 @@ class MenuLinkContentTest extends ResourceTestBase { protected function getExpectedUnauthorizedAccessMessage($method) { switch ($method) { case 'DELETE': - return floatval(\Drupal::VERSION >= 8.7) ? "The 'administer menu' permission is required." : ''; + return "The 'administer menu' permission is required."; default: return parent::getExpectedUnauthorizedAccessMessage($method); diff --git a/tests/src/Functional/ResourceTestBase.php b/tests/src/Functional/ResourceTestBase.php index d897d67..5c303a8 100644 --- a/tests/src/Functional/ResourceTestBase.php +++ b/tests/src/Functional/ResourceTestBase.php @@ -25,7 +25,6 @@ use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper; use Drupal\Core\Url; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; -use Drupal\jsonapi\BackwardCompatibility\tests\Traits\ContentModerationTestTrait; use Drupal\jsonapi\JsonApiResource\LinkCollection; use Drupal\jsonapi\JsonApiResource\NullEntityCollection; use Drupal\jsonapi\JsonApiResource\Link; @@ -34,6 +33,7 @@ use Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel; use Drupal\jsonapi\ResourceResponse; use Drupal\path\Plugin\Field\FieldType\PathItem; use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait; use Drupal\user\Entity\Role; use Drupal\user\EntityOwnerInterface; use Drupal\user\RoleInterface; @@ -1787,10 +1787,6 @@ abstract class ResourceTestBase extends BrowserTestBase { $detail = 'The current user is not allowed to view this relationship.'; if (!$entity->access('view') && $entity->access('view label') && $access instanceof AccessResultReasonInterface && empty($access->getReason())) { $access->setReason("The user only has authorization for the 'view label' operation."); - // @todo Remove when we stop supporting Drupal 8.5. - if (floatval(\Drupal::VERSION) < 8.6 && $relationship_field_name === 'roles' && static::$entityTypeId === 'user' && $access->getCacheContexts() === ['user.permissions']) { - $access = $access->setReason(''); - } } $via_link = Url::fromRoute( sprintf('jsonapi.%s.%s.related', $base_resource_identifier['type'], $relationship_field_name), @@ -1953,11 +1949,8 @@ abstract class ResourceTestBase extends BrowserTestBase { // contains the serialized created entity. $created_entity = $this->entityStorage->loadUnchanged(static::$firstCreatedEntityId); $created_entity_document = $this->normalize($created_entity, $url); - // @todo Remove this once JSON:API requires Drupal >=8.6. - if (floatval(\Drupal::VERSION) >= 8.6) { - $decoded_response_body = Json::decode((string) $response->getBody()); - $this->assertSame($created_entity_document, $decoded_response_body); - } + $decoded_response_body = Json::decode((string) $response->getBody()); + $this->assertSame($created_entity_document, $decoded_response_body); // Assert that the entity was indeed created using the POSTed values. foreach ($this->getPostDocument()['data']['attributes'] as $field_name => $field_normalization) { // If the value is an array of properties, only verify that the sent @@ -2110,10 +2103,7 @@ abstract class ResourceTestBase extends BrowserTestBase { $request_options[RequestOptions::BODY] = Json::encode($this->makeNormalizationInvalid($this->getPatchDocument(), 'id')); $response = $this->request('PATCH', $url, $request_options); $id_field_name = $this->entity->getEntityType()->getKey('id'); - $expected_message = (floatval(\Drupal::VERSION) < 8.6) - ? "The current user is not allowed to PATCH the selected field ($id_field_name). The entity ID cannot be changed" - : "The current user is not allowed to PATCH the selected field ($id_field_name). The entity ID cannot be changed."; - $this->assertResourceErrorResponse(403, $expected_message, $url, $response, "/data/attributes/$id_field_name"); + $this->assertResourceErrorResponse(403, "The current user is not allowed to PATCH the selected field ($id_field_name). The entity ID cannot be changed.", $url, $response, "/data/attributes/$id_field_name"); if ($this->entity->getEntityType()->hasKey('uuid')) { // DX: 400 when entity trying to update an entity's UUID field. @@ -2664,10 +2654,7 @@ abstract class ResourceTestBase extends BrowserTestBase { $this->assertTrue($this->container->get('module_installer')->install(['content_moderation'], TRUE), 'Installed modules.'); // Set up an editorial workflow. - $workflow = floatval(\Drupal::VERSION) > 8.5 - ? $this->createEditorialWorkflow() - // @todo Remove when we stop supporting Drupal 8.5. - : entity_load('workflow', 'editorial'); + $workflow = $this->createEditorialWorkflow(); $workflow->getTypePlugin()->addEntityTypeAndBundle(static::$entityTypeId, $this->entity->bundle()); $workflow->save(); diff --git a/tests/src/Functional/ShortcutSetTest.php b/tests/src/Functional/ShortcutSetTest.php index 2eea948..0ab41a3 100644 --- a/tests/src/Functional/ShortcutSetTest.php +++ b/tests/src/Functional/ShortcutSetTest.php @@ -60,7 +60,7 @@ class ShortcutSetTest extends ResourceTestBase { protected function getExpectedUnauthorizedAccessMessage($method) { switch ($method) { case 'GET': - return floatval(\Drupal::VERSION >= 8.7) ? "The 'access shortcuts' permission is required." : ''; + return "The 'access shortcuts' permission is required."; default: return parent::getExpectedUnauthorizedAccessMessage($method); diff --git a/tests/src/Functional/TermTest.php b/tests/src/Functional/TermTest.php index 47e21ab..a8b79a1 100644 --- a/tests/src/Functional/TermTest.php +++ b/tests/src/Functional/TermTest.php @@ -209,18 +209,7 @@ class TermTest extends ResourceTestBase { break; } - // @todo Remove this when JSON:API requires Drupal 8.6 or newer. - if (floatval(\Drupal::VERSION) < 8.6) { - $expected_parent_normalization = [ - 'data' => [], - 'links' => [ - 'related' => ['href' => $self_url . '/parent'], - 'self' => ['href' => $self_url . '/relationships/parent'], - ], - ]; - } - - $expected_document = [ + return [ 'jsonapi' => [ 'meta' => [ 'links' => [ @@ -255,6 +244,7 @@ class TermTest extends ResourceTestBase { ], 'weight' => 0, 'drupal_internal__tid' => 1, + 'status' => TRUE, ], 'relationships' => [ 'parent' => $expected_parent_normalization, @@ -271,12 +261,6 @@ class TermTest extends ResourceTestBase { ], ], ]; - - if (floatval(\Drupal::VERSION) >= 8.6) { - $expected_document['data']['attributes']['status'] = TRUE; - } - - return $expected_document; } /** @@ -284,7 +268,7 @@ class TermTest extends ResourceTestBase { */ protected function getExpectedGetRelationshipDocumentData($relationship_field_name, EntityInterface $entity = NULL) { $data = parent::getExpectedGetRelationshipDocumentData($relationship_field_name, $entity); - if ($relationship_field_name === 'parent' && floatval(\Drupal::VERSION) >= 8.6) { + if ($relationship_field_name === 'parent') { $data = [ 0 => [ 'id' => 'virtual', @@ -329,9 +313,7 @@ class TermTest extends ResourceTestBase { protected function getExpectedUnauthorizedAccessMessage($method) { switch ($method) { case 'GET': - return floatval(\Drupal::VERSION) >= 8.6 - ? "The 'access content' permission is required and the taxonomy term must be published." - : "The 'access content' permission is required."; + return "The 'access content' permission is required and the taxonomy term must be published."; case 'POST': return "The following permissions are required: 'create terms in camelids' OR 'administer taxonomy'."; @@ -352,9 +334,7 @@ class TermTest extends ResourceTestBase { */ protected function getExpectedUnauthorizedAccessCacheability() { $cacheability = parent::getExpectedUnauthorizedAccessCacheability(); - if (floatval(\Drupal::VERSION) >= 8.6) { - $cacheability->addCacheableDependency($this->entity); - } + $cacheability->addCacheableDependency($this->entity); return $cacheability; } @@ -425,11 +405,6 @@ class TermTest extends ResourceTestBase { * @dataProvider providerTestGetIndividualTermWithParent */ public function testGetIndividualTermWithParent(array $parent_term_ids) { - if (floatval(\Drupal::VERSION) < 8.6) { - $this->markTestSkipped('The "parent" field on terms is only available for normalization in Drupal 8.6 and later.'); - return; - } - // Create all possible parent terms. Term::create(['vid' => Vocabulary::load('camelids')->id()]) ->setName('Lamoids') @@ -476,12 +451,7 @@ class TermTest extends ResourceTestBase { * {@inheritdoc} */ public function testCollectionFilterAccess() { - if (floatval(\Drupal::VERSION) >= 8.6) { - $this->doTestCollectionFilterAccessForPublishableEntities('name', 'access content', 'administer taxonomy'); - } - else { - $this->doTestCollectionFilterAccessBasedOnPermissions('name', 'access content'); - } + $this->doTestCollectionFilterAccessBasedOnPermissions('name', 'access content'); } } diff --git a/tests/src/Functional/UserTest.php b/tests/src/Functional/UserTest.php index d149b26..2e37126 100644 --- a/tests/src/Functional/UserTest.php +++ b/tests/src/Functional/UserTest.php @@ -171,10 +171,10 @@ class UserTest extends ResourceTestBase { return "The 'access user profiles' permission is required and the user must be active."; case 'PATCH': - return floatval(\Drupal::VERSION >= 8.7) ? "Users can only update their own account, unless they have the 'administer users' permission." : ''; + return "Users can only update their own account, unless they have the 'administer users' permission."; case 'DELETE': - return floatval(\Drupal::VERSION >= 8.7) ? "The 'cancel account' permission is required." : ''; + return "The 'cancel account' permission is required."; default: return parent::getExpectedUnauthorizedAccessMessage($method); @@ -327,10 +327,7 @@ class UserTest extends ResourceTestBase { $response = $this->request('PATCH', $url, $request_options); // Ensure the email address has not changed. $this->assertEquals('admin@example.com', $this->entityStorage->loadUnchanged(1)->getEmail()); - $expected_message = floatval(\Drupal::VERSION) < 8.6 - ? 'The current user is not allowed to PATCH the selected field (uid). The entity ID cannot be changed' - : 'The current user is not allowed to PATCH the selected field (uid). The entity ID cannot be changed.'; - $this->assertResourceErrorResponse(403, $expected_message, $url, $response, '/data/attributes/uid'); + $this->assertResourceErrorResponse(403, 'The current user is not allowed to PATCH the selected field (uid). The entity ID cannot be changed.', $url, $response, '/data/attributes/uid'); } /** diff --git a/tests/src/Functional/VocabularyTest.php b/tests/src/Functional/VocabularyTest.php index 4ce1fe3..61ecdc8 100644 --- a/tests/src/Functional/VocabularyTest.php +++ b/tests/src/Functional/VocabularyTest.php @@ -59,7 +59,7 @@ class VocabularyTest extends ResourceTestBase { */ protected function getExpectedDocument() { $self_url = Url::fromUri('base:/jsonapi/taxonomy_vocabulary/taxonomy_vocabulary/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); - $expected_document = [ + return [ 'jsonapi' => [ 'meta' => [ 'links' => [ @@ -88,10 +88,6 @@ class VocabularyTest extends ResourceTestBase { ], ], ]; - if (floatval(\Drupal::VERSION) < 8.7) { - $expected_document['data']['attributes']['hierarchy'] = 0; - } - return $expected_document; } /** diff --git a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php index 45a6450..4d2e8a6 100644 --- a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php +++ b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php @@ -289,7 +289,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase { $this->assertSame($this->term1->uuid(), $normalized['included'][1]['id']); $this->assertSame('taxonomy_term--tags', $normalized['included'][1]['type']); $this->assertSame($this->term1->label(), $normalized['included'][1]['attributes']['name']); - $this->assertCount(floatval(\Drupal::VERSION) >= 8.6 ? 8 : 7, $normalized['included'][1]['attributes']); + $this->assertCount(8, $normalized['included'][1]['attributes']); $this->assertTrue(!isset($normalized['included'][1]['attributes']['created'])); // Make sure that the cache tags for the includes and the requested entities // are bubbling as expected. @@ -379,7 +379,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase { $this->assertTrue(empty($normalized['meta']['omitted'])); $this->assertEquals($this->user->uuid(), $normalized['included'][0]['id']); $this->assertCount(1, $normalized['included'][0]['attributes']); - $this->assertCount(floatval(\Drupal::VERSION) >= 8.6 ? 8 : 7, $normalized['included'][1]['attributes']); + $this->assertCount(8, $normalized['included'][1]['attributes']); // Make sure that the cache tags for the includes and the requested entities // are bubbling as expected. $this->assertArraySubset( diff --git a/tests/src/Traits/CommonCollectionFilterAccessTestPatternsTrait.php b/tests/src/Traits/CommonCollectionFilterAccessTestPatternsTrait.php index c815b01..8ac8a39 100644 --- a/tests/src/Traits/CommonCollectionFilterAccessTestPatternsTrait.php +++ b/tests/src/Traits/CommonCollectionFilterAccessTestPatternsTrait.php @@ -7,7 +7,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Url; use Drupal\entity_test\Entity\EntityTest; -use Drupal\jsonapi\BackwardCompatibility\tests\Traits\EntityReferenceTestTrait; +use Drupal\Tests\field\Traits\EntityReferenceTestTrait; use Drupal\Tests\jsonapi\Functional\ResourceTestBase; use GuzzleHttp\RequestOptions; diff --git a/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php b/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php index e3dfba6..7e79c18 100644 --- a/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php +++ b/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php @@ -10,8 +10,6 @@ use JsonSchema\Validator; use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\rest\ResourceResponse; -use Drupal\schemata\SchemaFactory; -use Drupal\schemata\Encoder\JsonSchemaEncoder; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; use Psr\Log\LoggerInterface; @@ -104,76 +102,6 @@ class ResourceResponseValidatorTest extends UnitTestCase { assert_options(ASSERT_ACTIVE, $assert_active_default); } - /** - * @covers ::onResponse - * @requires function Drupal\schemata\SchemaFactory::__construct - */ - public function testValidateResponseSchemata() { - $request = $this->createRequest( - 'jsonapi.node--article.individual', - new ResourceType('node', 'article', NULL) - ); - - $response = $this->createResponse('{"data":null}'); - - // The validator should be called *once* if schemata is *not* installed. - $validator = $this->prophesize(Validator::class); - $validator->check(Argument::any(), Argument::any())->shouldBeCalledTimes(1); - $validator->isValid()->willReturn(TRUE); - $this->subscriber->setValidator($validator->reveal()); - - // Run validations. - $this->subscriber->doValidateResponse($response, $request); - - // The validator should be called *twice* if schemata is installed. - $validator = $this->prophesize(Validator::class); - $validator->check(Argument::any(), Argument::any())->shouldBeCalledTimes(2); - $validator->isValid()->willReturn(TRUE); - $this->subscriber->setValidator($validator->reveal()); - - // Make the schemata factory available. - $schema_factory = $this->prophesize(SchemaFactory::class); - $schema_factory->create('node', 'article')->willReturn('{}'); - $this->subscriber->setSchemaFactory($schema_factory->reveal()); - - // Run validations. - $this->subscriber->doValidateResponse($response, $request); - - // The validator resource specific schema should *not* be validated on - // 'related' routes. - $request = $this->createRequest( - 'jsonapi.node--article.related', - new ResourceType('node', 'article', NULL) - ); - - // Since only the generic schema should be validated, the validator should - // only be called once. - $validator = $this->prophesize(Validator::class); - $validator->check(Argument::any(), Argument::any())->shouldBeCalledTimes(1); - $validator->isValid()->willReturn(TRUE); - $this->subscriber->setValidator($validator->reveal()); - - // Run validations. - $this->subscriber->doValidateResponse($response, $request); - - // The validator resource specific schema should *not* be validated on - // 'relationship' routes. - $request = $this->createRequest( - 'jsonapi.node--article.relationship', - new ResourceType('node', 'article', NULL) - ); - - // Since only the generic schema should be validated, the validator should - // only be called once. - $validator = $this->prophesize(Validator::class); - $validator->check(Argument::any(), Argument::any())->shouldBeCalledTimes(1); - $validator->isValid()->willReturn(TRUE); - $this->subscriber->setValidator($validator->reveal()); - - // Run validations. - $this->subscriber->doValidateResponse($response, $request); - } - /** * @covers ::validateResponse * @dataProvider validateResponseProvider