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.
Per #1812866-65: Rebuild the server side AJAX API, it's important that settings, js, and css get added before new markup that relies on them. The code is currently correct, but is missing test coverage. Here's the test coverage.
Per #1812866-68: Rebuild the server side AJAX API, this is adding coverage to the old system, but will move to the new system with everything else in follow ups.
Comment | File | Size | Author |
---|---|---|---|
#14 | ajax_command_order-1848880-13.patch | 29.8 KB | Wim Leers |
#14 | interdiff.txt | 21.4 KB | Wim Leers |
#3 | ajax_command_order-1848880-3-fail.patch | 14.78 KB | Wim Leers |
#3 | ajax_command_order-1848880-3.patch | 15.17 KB | Wim Leers |
#3 | interdiff.txt | 12.43 KB | Wim Leers |
Comments
Comment #1
Wim LeersYay! :)
Comment #2
Wim LeersTurns out the original tests were broken & incomplete to begin with… :(
Furthermore, these tests actually test
ajax.inc/ajax_render()
, because the tests leverage Form API's AJAX integration, which is still being ported to the new AJAX API at #1843220-35: Convert form AJAX to new AJAX API. So this won't help prevent bugs inAjaxResponse.php
yet.As said at #1812866-65: Rebuild the server side AJAX API by myself (after reading the D7 code — which has always worked well — carefully):
Despite being blocked by #1843220: Convert form AJAX to new AJAX API to test the order of AJAX commands (in
testLazyLoad()
), it is in fact possible to test the order if we don't use the Form API integration with the AJAX API to do so. That being said, I think it's still valuable to keep the order checks intestLazyLoad()
that were added in the OP.Attached is a patch that does so.
Over at #1875632-39: JS settings merging behavior: preserve integer keys (allow for array literals in drupalSettings), quicksketch reported a regression introduced accidentally by effulgentsia at #1875632-31: JS settings merging behavior: preserve integer keys (allow for array literals in drupalSettings). That's the second time now (first time: #1812866-54: Rebuild the server side AJAX API, solution: #1812866-65: Rebuild the server side AJAX API) that AJAX command ordering got broken, because there is no test coverage for it. Hence I've bumped this to major.
I've rolled the patch twice:
Comment #3
Wim LeersUgh, these two patches were based on top of a Drupal core which had the bug reported by quicksketch already fixed, so they're wrong. So much careful work and planning only to be ruined by such a stupid mistake!
Ignore files of #2.
Rerolled.
Comment #4
Wim LeersBetter title as per #2/#3.
Comment #6
Wim Leers#3: ajax_command_order-1848880-3.patch queued for re-testing.
Comment #8
Wim Leers#3: ajax_command_order-1848880-3.patch queued for re-testing.
Comment #9
Wim LeersLast breakage caused by #1883152-54: Field level access for EntityNG. Hopefully this time it'll come back green.
Comment #11
Wim Leers#3: ajax_command_order-1848880-3.patch queued for re-testing.
Comment #12
mkadin CreditAttribution: mkadin commentedTake my 'needs work' here lightly as I've never reviewed a core test before and haven't written one for D8.
Generally this looks pretty good to me. Few small comments / ideas below.
Might it make sense to actually create an Ajax Command object and use its render() method to produce the expected command arrays? That way if the data / structure of this array ever changes, the test won't need to be re-written.
Good catch.
'AJAX' vs. 'ajax' vs. 'Ajax' :) What's the right way and do we care? There are several of these scattered throughout your docs.
Since we want to make sure that the CSS and JS get lazy loaded before the html command, it might make sense to put the HTML command before the drupal_add_*. Wouldn't affect the order in how we have it set up now, but who knows in the future?
Comment #13
tstoecklerThe right way is "Ajax".
Comment #14
Wim LeersThanks for the review!
RE: "Might it make sense to actually create an Ajax Command object and use its render() method to produce the expected command arrays? That way if the data / structure of this array ever changes, the test won't need to be re-written."
Great point!
I've done this, at the cost of introducing changes that are — strictly seen — unrelated to this patch.
It does make for a nice interdiff though: 94 insertions, 164 deletions :)
RE: "AJAX" capitalization
I don't want to waste time on this while it is extremely inconsistent already. Anything user-facing is "AJAX", most code in the AJAX framework is "Ajax", but e.g. in
WebTestCase
, it'sdrupalPostAJAX()
. I'd much rather stick to "AJAX" everywhere except in function names, which is the simplest and most logical thing to do, but what we really should do is defer "Bring consistency to Ajax vs. AJAX vs. ajax" to a separate issue, which settles this once and for all and then applies it everywhere, consistently.RE: "[…] it might make sense to put the HTML command […]"
Agreed. Changed.
Comment #15
mkadin CreditAttribution: mkadin commentedLooks good to me.
Comment #16
webchickWow, great job withe the refactoring/tests in this patch! Thanks for the review as well, mkadin! :)
Committed and pushed to 8.x. Thanks!
Comment #17
quicksketchYay, thanks guys!
Comment #18
Wim Leers.