This is a follow-up to: #2945093: Comprehensive JSON API integration test coverage phase 3: test JSON API-specific use cases: related/relationship routes, includes and sparse field sets
Comprehensive JSON API integration test coverage phase 5: nested includes and sparse field sets
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | 2976909-2.patch | 807 bytes | gabesullice |
| #25 | interdiff.txt | 1.03 KB | wim leers |
| #24 | 2953321-24.patch | 30.51 KB | wim leers |
| #24 | interdiff.txt | 2.86 KB | wim leers |
| #23 | 2953321-23.patch | 30.19 KB | gabesullice |
Comments
Comment #2
gabesulliceComment #3
pixelwhip commented@gabesullice Attached is a patch for the work we started in order to test nested includes.
Comment #4
wim leers@pixelwhip WOOT! Thank you for getting this going! 👍❤️
Comment #5
gabesulliceAlright, this got significantly more difficult than I anticipated... but! I think it's just on the cusp of working. Needs a testbot run, I think there's gotta be an error in there somewhere :P
Comment #6
gabesullice@pixelwhip, the good news is that this is the only piece that we'll need to change to enable tests for intermediate inclusion in #2946537: Test coverage: Inclusion of intermediate resources when include is a multi-part relationship path!
Comment #7
wim leersInterdiff from #3 to #5?
Comment #8
gabesulliceDidn't post because it's almost equal to the patch size.
Comment #9
wim leersDo you want reviews already, or do you want to get the patch green first?
Comment #10
gabesullice@Wim Leers, yeah, let's get it green and I'll set the issue to Needs Review :)
Here's the fix to #5.
I should say, this only addresses nested includes and not sparse field sets for secondary resource types... which I actually think should be de-scoped in this issue. I can't see a practical way to do that in an automated way. I think it would be sufficient to ensure something is in JsonApiFunctionalTest though, and I'll add that in my next patch.
Comment #11
wim leersShouldn't this conditionally grant permissions based on the fields in
$field_set?(In this implementation and all others.)
I'm confused why this needs
administer permissions.Also, wouldn't
access user profilesbe sufficient, isn'tadminister usersoverkill?Nit: s/The/The expected/
Nit: method name says "data", but actually returns a response.
Nit: CS violations around the commas.
Nit:
string|nullWhy move this?
This just moved some of the existing logic into a new helper method 👍
Nit: s/self/'self'/ (to make it slightly less ambiguous/slightly easier to understand)
Why didn't I think of this helper method? Surprisngly elegant! 😍
s/given operation, field and entity./given field operation on the given entity./
I think this is meant to mean *all* nested include paths?
❤️
Comment #12
wim leersNote that #2953207: Can't get the right target type when filtering on relationship with bundle-specific target entity type is making changes to fix a bug, but in doing so it introduced another bug. Fortunately they were caught by
\Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTest::testRead(). The test coverage that this issue is adding will help ensure with more reliability that such regressions won't occur :)Comment #13
wim leersComment #14
gabesullice1. Yes, also refactored a little.
2. Because of the include path
uid.type(IOW, to view the user role entity type). I think the change for #1 should make that more apparent.3-6. Done.
7. I don't remember :P moved back.
8. 🤘
9. Done.
10. ❤️
11. Done.
12. I thing my reasoning was that it could be overridden by a more specific set of includes that wouldn't necessarily be "all" of them. I changed it to "Gets an array of of all nested include paths to be tested." which I think splits the difference.
13. 🙂
In #10, I mentioned de-scoping nested sparse field sets. @Wim Leers, what do you think?
Comment #15
gabesulliceComment #16
wim leers#14.1: oohh, I think I like that!
I'm open to that.
But here's an idea: what if we only do this for entity types implementing
EntityOwnerInterface? Then the tested secondary resource type for which we're testing sparse fieldsets would always beUser, which would make it easy to test only those well-known entity types' fields.Because you're absolutely right of course: not every entity type has an entity reference (relationship), and if they do, it's often to config entity types (e.g.
Node->NodeType,Term->Vocabulary). By only doing it for entity types with required relationships toUserentities, you're still testing >1 use case, yet keeping it simpler to test.What do you think?
Comment #17
gabesulliceI really like that idea.
Rerolling before implementing that suggestion.
Comment #19
gabesulliceFixing some errors that didn't get corrected in the reroll.
Comment #20
gabesulliceHopefully this is the last fix needed to bring everything back to passing...
Comment #21
gabesulliceK, finally implementing @Wim Leers excellent suggestion in #16. That led me to discover #2976108: Spec Compliance: Impossible to include related resources when relationship field is not in a request's sparse fieldset
Comment #23
gabesulliceAnd, this should be all green again.
Comment #24
wim leersI was initially confused by the need for #17+#19+#20 to make this patch pass tests again. But then I understood: the patches before then were applied to HEAD, and since then #2953318: Comprehensive JSON API integration test coverage phase 4: collections, filtering and sorting landed! Hence the need for quite a bit of rebasing.
#21: I'm glad you found #2976108: Spec Compliance: Impossible to include related resources when relationship field is not in a request's sparse fieldset and created an issue for it! 👌
I'm of course super glad that we now have test coverage for sparse field sets!
Re-reviewed the entire patch.
👌
This specified that the sparse fieldset should be
[uid].Yet this hardcodes it to
name. Easy fix!Oh wait … this too is blocked on #2976108: Spec Compliance: Impossible to include related resources when relationship field is not in a request's sparse fieldset! So, for now, the solution is to not hardcode but respect the specified fieldset, yet make that fieldset temporarily
['uid'], until #2976108 lands, then we can make it['name']again! (Or better yet, something like['name','preferred_langcode']. Because then we're testing multiple fields being requested in a sparse fieldset.)I made the necessary changes and added a
@todo.Nit: Gets.
Comment #25
wim leersStill green, let's get this done so we can move on to #2972808: Comprehensive JSON API integration test coverage phase 6: POST/PATCH/DELETE of relationships, the final test coverage piece! This patch is pure test coverage, so there's zero risk of BC breaks by committing this!
(I'll fix the CS violations on commit. See attached interdiff.)
Comment #26
wim leersComment #28
gabesulliceThis
stringtype hint broke HEAD's tests on PHP 5.5.If this passes, it will be committed in #2976909: Follow-up for #2953321; fixes PHP 5.5 test failure
Comment #31
gabesullice