Closed (fixed)
Project:
Drupal core
Version:
8.8.x-dev
Component:
jsonapi.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
11 Jun 2019 at 09:21 UTC
Updated:
28 Aug 2019 at 09:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #4
alexpottComment #5
shreyal999 commentedComment #6
shreyal999 commentedThe Test Case EntityResourceTest has been removed and tested accordingly. Kindly review and suggest changes if any.
Comment #7
wim leersQuoting myself from #3042745-41: Remove group @legacy from jsonapi tests and fix deprecation messages:
Comment #8
alexpott@Wim Leers the thing is I can't find any other test coverage of
\Drupal\jsonapi\Controller\EntityResource::getIndividual()- well maybe I can I guess\Drupal\Tests\jsonapi\Functional\ResourceTestBase::testGetIndividual()is but that's not easy for me to find. I would be good if someone who knows the Json test coverage can prove that:Are all covered elsewhere.
Comment #9
wim leers#3036285: Add a \JsonApiResource\Relationship object to carry relationship data, metadata and a link collection. is having to update quite a lot in
EntityResourceTest. Just like in #3042745: Remove group @legacy from jsonapi tests and fix deprecation messages, its tight coupling is rearing its ugly consequences. So working on this again.This is definitely true. I should have done that from the start. Sorry about that.
Did that below.
\Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::testGetIndividual(): this is only testing that given aNodeobject that is passed to\Drupal\jsonapi\Controller\EntityResource::getIndividual(), aJsonApiDocumentTopLevelobject is returned byEntityResource::getIndividual()and that contains the node's UUID.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s..., where the expectation
$this->getExpectedDocument()is asserting not only the UUID, but also everything else (all fields, the expected (Dynamic) Page Cache response headers, and so on). See https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s... for an example.testGetIndividualDenied(): this is asserting that when the current user does not have theaccess contentpermission, the controller throwsEntityAccessDeniedHttpException.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s..., where a 403 response is asserted, plus the expected error message, plus cacheability, and more.
testGetCollection(): this is testing that given a request to the collection of article nodes when sorted by NID, aJsonApiDocumentTopLevelobject is returned byEntityResource::getCollection(), it contains at least the primary test node's UUID and it also has the cache tags for each of the returned article nodes.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s..., where a NID-sorted collection request is also tested, but it tests all cacheability (not just cache tags), and the exact expected response (not just the presence of a single particular UUID) and hence it also tests the ordering.
testGetFilteredCollection(): this is only testing filtering by requesting the list ofNodeTypeconfig entities restricted to those who havetype=article. It then tests that both the list cache tag and the cache tag of the sole matching entity (that of the "article"NodeTypeconfig entity) are present.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s..., where first we generate a collection of entities that we expect the server to return, then we construct a filter, and finally we perform a request and assert that this matches the expected collection. Rather than only asserting cache tags, all cacheability is asserted, as well as the full response body and the expected (Dynamic) Page Cache response headers.
testGetSortedCollection(): analogous answer, superset can be found at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s...testGetPagedCollection(): HAH! This is the one thing so far that AFAICT we do not have test coverage for in\Drupal\Tests\jsonapi\Functional\ResourceTestBase::testCollection(). So we should keep this.testGetEmptyCollection(): The functional test coverage explicitly does not test this: https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s....testGetRelated(): this is testing both a to-one (article author) and a to-many relationship (related articles). In both cases, it's testing the presence of the cache tags of the related data.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s..., where for each related field much more is tested than only the related entities' cache tags (it's again asserting all of the expected data, plus all cacheability, plus (Dynamic) Page Cache response headers, etc.), but also does this for every entity reference field.
testGetRelationship(): analogous answer, superset can be found at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s...testCreateIndividual(): this is testing the creation of an article node and asserting a 201 response.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s....
testCreateIndividualWithMissingRequiredData(): the same request body as the previous bullet, but now without the sole required field (the label field). Asserts a validation error occurs.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s..., with many more error edge cases before and after it.
testCreateIndividualDuplicateError(): the same request body as 2 bullets up, but now after that same entity was already created. Asserts a 409 ("conflict") exception is thrown.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s..., with it also testing the error response's body.
testPatchIndividual(): this is testing the changing of a title and adding a reference to another entity. It's asserting that after executingEntityResource::patchIndividual(), the entity was indeed updated, and those values do exist in the response returned byEntityResource::patchIndividual().A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s.... Before and after that orders of magnitude more edge cases are exercised.
testDeleteIndividual(): this is testing the deletion of an entity results in a 204 response and actually did delete the entity.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s..., with again many more edge cases being exercised.
testAddToRelationshipData(): this is sending a POST request to a "relationship" route, to append to it. It is asserting that the call toEntityResource::addToRelationshipData()results in a 204 response with the newly referenced entity's ID being asserted.A superset is tested at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s..., with again orders of magnitude more edge cases being tested before and after it.
testReplaceRelationshipData(): analogous answer, superset at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s...testRemoveFromRelationshipData(): analogous answer, superset at https://github.com/drupal/drupal/blob/8.7.6/core/modules/jsonapi/tests/s...Based on this, retitled and rerolled. The rerolled patch keeps
EntityResourceTest, but removes all methods except for the two that the above research has identified to not have a superset of test coverage in the functional tests.Comment #10
larowlanComment #11
larowlanCommitted 103d362 and pushed to 8.8.x. Thanks!
Comment #13
wim leers🥳