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.
The exact same frustrations and symptoms as #1996378: Edit broken because of #1043198 and routing system bug + missing test coverage apply here.
Due to lack of testing coverage (which is really about "defend against API changes", not about "guarantee correctness"), this was not noticed for well over a month.
Comments
Comment #1
Wim LeersHere's a patch that fixes the problem, but does not yet add test coverage.
In the standard profile, create an article node. Then visit
node/1/body/und/full
.Before patch: 404.
After patch: Ajax response.
Comment #2
Wim Leers\Drupal\editor\Tests\EditorIntegrationTest::testGetUntransformedTextCommand()
already unit tests the logic.I don't see the need to add "defend against API changes" integration tests.
Comment #3
webchickConfirmed test results from #2. This fixes a pretty major bug with Edit module and is a simple find/replace of a variable name, so I'm comfortable committing from needs review. And yeah "defend against API changes" doesn't really need test coverage.
Committed and pushed to 8.x. Thanks!
Comment #4
Gábor HojtsyThis makes in-place editing broken on the full node view. Elevating to major bug as per #2037687: Can no longer in-place edit body fields. I think it would be important to have test coverage for this path to ensure it has an AJAX response (with the right kind of data?). This is not the first time we had issues in core with router handling changing. While this sounds like protecting against future API changes, when we find regressions like this, we usually add tests to ensure they don't happen again. Especially since this is not for the first time.
Comment #5
Gábor HojtsyI disagree this would not need test coverage, but since the fix itself was committed now, we can demote to normal.
Comment #6
webchickThat's definitely a good point. Sorry, I did not get much sleep last night. ;P Or the past 8 weeks, hehe.
Comment #7
Thomas Brekelmans CreditAttribution: Thomas Brekelmans commentedI'll try to add a test / expand the current tests inside the edit module to get coverage for this scenario.
The \Drupal\edit\Tests\EditLoadingTest class has a big testUserWithPermission() method that I could extend to do something similar as done here (asserting if the metadata for that field can be retrieved by checking if the HTTP response code is 200):
I plan to check for the response of the editor URL in a similar fashion. I'll upload a patch with this idea later (after I've tested it locally).
Comment #8
Thomas Brekelmans CreditAttribution: Thomas Brekelmans commentedHere's a patch that adds a couple of assertions around the existence of a route for POST /editor/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode_id} by checking if a cURL POST request with AJAX headers to "editor/node/1/body/und/full" gives the expected response.
(The field is already created during the tests for other assertions as well).
I had to include the editor module in the static $modules (to enable) property of the test because that's the module that actually defines the route.
Does this provide enough coverage for this scenario or do we need more?
Comment #9
tstoecklerCan you upload a patch that reverts the committed patch, to prove that the tests do as advertised? Thanks.
Comment #10
Thomas Brekelmans CreditAttribution: Thomas Brekelmans commentedHere's a patch that reverts the changes from the patch in #1, but has my extra test assertions from #8 in place.
For me locally this results in 4 fails inside EditLoadingTest.php: the 4 assertions I added. I've included a screenshot of those errors/fails:
Edit: and the patch has failed as expected, with the same 4 fails and messages. :)
I've also added an interdiff so you can easily see which lines I 'reverted' to re-create the original problem.
Comment #12
tstoecklerAwesome! Thanks for the quick turnaround. I'm not viable for RTBC-ing this myself, however.
Comment #13
tstoecklerDidn't mean to remove those tags, but "Needs tests" is now in fact not necessary anymore.
Comment #14
Wim Leers#8: edit-editor-AJAX-endpoint-broken-tests-2031385-8.patch queued for re-testing.
Comment #15
Wim Leers#8 still passes — yay :)
I'll review this on Monday.
Comment #16
Wim LeersThe test in #8/#10 is being added to
core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php
, which is owned byedit.module
, but the test itself tests an endpoint that is owned byeditor.module
. It is unacceptable that aedit.module
test requireseditor.module
to be enabled.So, I'm moving largely the same testing code (good job, Thomas Brekelmans!) into a new
Drupal\editor\Tests\EditIntegrationLoadingTest
test class. Yes, anotherWebTestBase
test that will test the exact same thing as\Drupal\editor\Tests\EditIntegrationTest::testGetUntransformedTextCommand()
, but now with with an HTTP request.Furthermore, the test coverage that Thomas Brekelmans introduced was not yet testing:
While working on this, I happily ran into epic routing system crappiness, which I reported at #1984528-53: Follow-up: Allow for more robust access checking (they made a huge API change without updating existing code!).
And then, I got stuck on yet another routing system fail: the dreaded
A fatal error occurred:
(this happens when the route controller never even gets called), which is the very thing #1996378: Edit broken because of #1043198 and routing system bug + missing test coverage fixed and what we're providing test coverage for in this issue. But it turns out it happens wheneverAjaxResponse
. So one assertion is commented out, while waiting for that issue to get resolved. Issue for that: #2063303: A Drupal 8 AjaxResponse that must return a 403, returns a 403 and prints "A fatal error occurred: ".Because of these two core bugs, getting this done took pretty much an entire day! But, at least, this patch should be RTBC'able… :)
Comment #17
Wim LeersI forgot to remove one
@todo
that I fixed.Comment #18
Gábor HojtsyWoot, thanks for the tests! The fix looks pretty good. I think the @todo in the test makes sense as-is, it would indeed be good to test for the empty response, but currently not possible.
Comment #19
webchickYay more tests! Committed and pushed to 8.x. Thanks!
Comment #20
Wim Leers.