Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We would like to extend the output of #2930028: Comprehensive JSON API integration test coverage phase 1: for every entity type, individual resources only to include tests for all entity types. #2930028 only covered the most essential entity types.
This issue should:
- add test coverage to prove that 100% of entity types have test coverage, this would alert us about new entity types in Drupal core that do not yet have test coverage (akin to core's #2868035: Test that all core content+config entity types have functional REST test coverage)
- then get that test passing, hence having integration tests for 100% of core's entity types (akin to #2824572: Write EntityResourceTestBase subclasses for every other entity type.)
Comment | File | Size | Author |
---|---|---|---|
#58 | 2932031-58.patch | 17 KB | gabesullice |
#57 | interdiff-commit.txt | 613 bytes | Wim Leers |
#54 | 2932031-54.patch | 158.3 KB | Wim Leers |
| |||
#54 | interdiff-52-54.txt | 2.1 KB | Wim Leers |
#52 | 2932031-52.patch | 157.97 KB | Wim Leers |
Comments
Comment #2
gabesulliceComment #3
Wim LeersPostponed on #2930028: Comprehensive JSON API integration test coverage phase 1: for every entity type, individual resources only.
Comment #4
e0ipsoComment #5
Wim Leers#2930028: Comprehensive JSON API integration test coverage phase 1: for every entity type, individual resources only has been pretty much completed. Time to get started here.
Comment #6
e0ipsoGreat! 💪🏽
Let me know if you want to brainstorm on what this issue should cover.
Comment #7
Wim LeersFirst: a test coverage test that ensures we have complete test coverage. This is pretty much copied from #2868035: Test that all core content+config entity types have functional REST test coverage.
Comment #8
Wim LeersOf course this didn't fail as expected
/facepalm
Comment #10
Wim LeersThat failed for the wrong reasons on 8.4, but for the right reasons on 8.6. This interdiff should ensure they behave consistently.
8.6 failed like this:
😀🤘
Comment #12
Wim LeersI now see that this issue says
. I'd actually propose to limit it to just . I think we should have a separate issue for complex use cases. Just adding test coverage for all other entity types will already make this patch plenty big.Thoughts?
Comment #13
Wim LeersThis adds test coverage for
MenuLinkContent
.Comment #15
gabesulliceI'm fine separating them into two issues, "remaining types" & "complex cases".
Unless remaining types is pretty trivial, I'd prefer to see complex cases worked on before remaining types. I think "complex cases" will be more likely to uncover higher impact bugs.
Comment #16
Wim LeersI disagree.
Getting remaining types done can be done in a shorter amount of time. And then when we add the generic test coverage for the complex cases to
ResourceTestBase
, it will run automatically for all entity types. Which means we'll be able to uncover entity type-specific bugs in those complex cases.IOW: doing "remaining types" first will make "complex cases" more reliable.
Comment #17
Wim LeersI started tackling this alphabetically. So I started with
aggregator_item
. Which immediately runs into the one edge case in all of Drupal core: that's the only entity type that does NOT support UUIDs… and hence breaks horrendously in JSON API:Fixing that is blocked on #2149851: Remove todo about GUID field on the 'aggregator_item' entity and add UUID field.
This adds test coverage for
aggregator_item
+aggregator_feed
.Comment #19
Wim Leersblock_content_type
+block_content
Comment #21
Wim Leers#10:
#19:
More progress tomorrow!
Comment #22
Wim Leerscomment_type
+contact_message
+contact_form
.Here,
contact_message
is another special case, because those entities are never stored. That means they can only bePOST
ed. All other verbs are not allowed. And no routes should be created for them. We have no way to signal this just yet. Core's REST module achieves this viacontact_rest_resource_alter()
overriding the default REST resource plugin class.I was contemplating making JSON API respect this automatically for any entity type using the
Drupal\Core\Entity\ContentEntityNullStorage
storage handler. But because JSON API has a single route for multiple methods, that's less easy to achieve, and merits more debate. So, created a new issue for that: #2944977: Message entities can only be created (POSTed), they cannot be read or modified.(I already had to make some changes to account for the fact that not every JSON API
POST
response would contain aLocation
header.)Comment #24
Wim Leerseditor
+filter_format
For
editor
, I had to comment a piece of code that calculated data for an assertion, and that assertion itself was already commented due to #2942561: Assert denormalizing the JSON API response results in the expected object. Config entity denormalization is unsurprisingly unreliable.For
filter_format
, I ran into a show-stopping bug: JSON API is normalizing the config entity's data in a way that results in data loss. We should see:but instead see:
In other words: it's stripping an entire level… This seems to have the same root cause as #2930028-33: Comprehensive JSON API integration test coverage phase 1: for every entity type, individual resources only. #2939800: FieldNormalizerValue::rasterizeValue() respects cardinality === 1, but doesn't verify that this is true improved the situation in that previously discovered case. But in this case, it's still breaking things. The fix is to not just check whether there's >1 value in the array, but whether it's a numerically indexed array or an associatively indexed array. In the latter case, indexes/keys have meaning, and shouldn't be dropped! I have yet to create an issue for this, but wanted the problem to appear in the failed tests.
Comment #26
gabesulliceI think that's still a little too naive and will break some lauded JSON API DX improvements. We want to check (1) the cardinality of the field and (2) whether its data definition is a sequence or a map.
Comment #27
Wim LeersExcept there are no data definitions for config entity types.
Which brings me to what I think we actually need to do: special case config entities and just make it output exactly what is stored, no attempts to simplify the data structure can be made.
Comment #28
Wim Leersfield_storage_config
+field_config
+base_field_override
field_storage_config
has a dependency, and therefore runs into the exact same problem asblock
in #2930028-55: Comprehensive JSON API integration test coverage phase 1: for every entity type, individual resources only and similar tofilter_format
in #24. #2942979: JSON API's normalization of config entities' "dependencies" key-value pair omits essential information when there's only a single dependency is the issue that was created for that. Same exact problem forbase_field_override
.(
field_config
would run into that same problem, if it weren't for the fact it has multiple dependencies and thanks to that is able to escape this fate!)Comment #29
Wim LeersConfirmed that the problem surfaced in #24 and discussed in #26 + #27, and surfaced again in #28, and that we have an issue for it already: #2942979: JSON API's normalization of config entities' "dependencies" key-value pair omits essential information when there's only a single dependency.
I moved the discussion in #24+#26+#27 over to #2942979-4: JSON API's normalization of config entities' "dependencies" key-value pair omits essential information when there's only a single dependency. Let's continue there.
Attached patch is updating
FilterFormatTest
to expect the current behavior and with a@todo
to fix it there.Comment #32
Wim Leerslanguage_content_settings
+configurable_language
+image_style
+rdf_mapping
+responsive_image_style
configurable_language
has one extra test, because the REST test also does:\Drupal\Tests\rest\Functional\EntityResource\ConfigurableLanguage\ConfigurableLanguageResourceTestBase::testGetDefaultConfig())
, added by #2915414: Omit "_core" key from normalized config entities, which includes the default config hash. The JSON API port of that issue is in #2915539: Omit "_core" key from normalized config entities, which includes the default config hash. The test coverage is currently asserting HEAD's behavior, which is wrong, but in doing so it paves the path for #2915539!Comment #34
Wim Leersnode_type
+rest_resource_config
(HAH!) +search_page
+menu
+action
(Also fixed
configurable_language_test
from #32, the file was incorrectly named.)Comment #36
Wim Leers#19 (~20 hours ago):
#34:
Hopefully at 100% later today.
Comment #37
Wim Leersentity_view_mode
+entity_form_mode
+entity_view_display
+entity_form_display
Comment #39
Wim Leersshortcut_set
+tour
+workflow
+view
+date_format
Comment #41
Wim LeersUpdated IS and created #2945093: Comprehensive JSON API integration test coverage phase 3: test JSON API-specific use cases: related/relationship routes, includes and sparse field sets for the "complex use cases" aka JSON API-specific features part.
Comment #42
Wim Leersd.o can be so broken in cross-posting situations … not only did it lose my IS update, it also unpublished this node! WTF.
Fixed.
Comment #43
Wim Leersfile
+shortcut
shortcut
does something special with the cache tags to invalidate: it doesn't have its own cache tags, instead it defers to theshortcut_set
entity it belongs to, and hence uses that cache tag instead. Due to pre-existing bugs in JSON API wrt caching, there is only one way forward: hardcode a work-around forshortcut
inResourceTestBase
— but fortunately the existing work-arounds can be modified so that there is no need for a hardcoded special case forshortcut
!Comment #45
Wim LeersFrom 94 coding standards violations to 0.
Comment #47
Wim LeersDisabled
BlockContentTest
on 8.4, it needs 8.5 per #2835845: EntityResource: Provide comprehensive test coverage for BlockContent entity.Comment #49
Wim LeersSimilar story for
EntityViewDisplay
andEntityFormDisplay
: they need 8.5 because they need #2866666: Add proper access handlers for view and form displays. Same forFile
.This patch should now be green on 8.4! But we'll need to add test coverage for two more entity types for it to pass on 8.6. That's for tomorrow!
Comment #50
Wim LeersAnother crosspost, another time that d.o unpublishes this node! 😡
Fortunately, the patch is green! ✅
Comment #51
Wim LeersFor 8.6:
media
+media_type
. They both required extra care to also work on 8.4 and 8.5.Comment #52
Wim LeersAnd now with documentation in
jsonapi.api.php
.Comment #53
gabesulliceremove "-"
s/by test/by testing/
this allows custom entity type developers to get
My only other suggestion might be to refactor all the getExpectedDocument methods to use something like:
But I don't feel strongly about it.
Comment #54
Wim LeersRE: only nit: I'd rather keep it like this, at least for now, because that means less magic. The expected result is there, plain to see, with as little dynamism as possible. That's valuable for complex data structure-based assertions/expectations. Plus, it also leaves the door open to put these expectations in static JSON files rather than as PHP code … which is something we should investigate/evaluate in another follow-up.
#52 passed on 8.4 but failed on 8.6 because #2939729: Do not provide links to related/relationship routes for internal resource types. landed after #51, which causes some changes in certain JSON API documents. Fixed that too.
Comment #55
gabesulliceComment #57
Wim LeersRTBC and green on both 8.4 and 8.5. One coding standards message, that can be fixed on commit.
Because:
… I went ahead and committed this. HURRAY! HUGE milestone! JSON API now has equally strong test coverage as core's REST module!
But still has many
@todo
s in that test coverage to fix — so not quite on par with REST yet.)Comment #58
gabesulliceThe previous commit erroneously included the patch from #2943176-25: Spec Compliance: when error object 'id' key exists, it contains the individual resource URI, instead of "a unique identifier for this particular occurrence of the problem".
This is the revert. Will commit if tests pass.
Comment #59
Wim LeersOops… 😅
Comment #62
Wim Leers👍 — thanks!
Comment #63
Wim LeersLooks like #58 was reported again, but this time by a JSON API module user: #2948044: Exceptions no longer have an "errors" parent key.