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.
Problem/Motivation
drupalPostAjaxForm()
is simulating the behaviour of ajax.js
, so using it, doesn't really provide fundamental guarantees.
#2809161: Convert Javascript/AJAX testing to use JavascriptTestBase suggests to convert them to JavascriptTestBase
Proposed resolution
- Figure out which part of the test is testing PHP code and which part ajax behaviour
- Extract the ajax behaviour into a test that extends JavascriptTestBase
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#19 | 2809529-19.patch | 4.06 KB | Lendude |
#19 | interdiff-2809529-17-19.txt | 2.3 KB | Lendude |
#17 | 2809529-17.patch | 4.1 KB | Lendude |
#17 | interdiff-2809529-15-17.txt | 1.73 KB | Lendude |
#15 | 2809529-15.patch | 4.25 KB | Lendude |
Comments
Comment #3
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedComment #6
martin107 CreditAttribution: martin107 as a volunteer commentedThe solution to this conversion exists in this issue.
#2862510: Convert system/tests/src/Ajax to JavascriptTestBase
but by common consent that issue is being shipwrecked -- broken up for parts and spares.
In this patch I am cutting out the conversion specific to ElementValidationTest
This shipwrecking has to be coordinated... the issue below, which is in review, is creating a AjaxTestBase class which this sub-putach assumes in already in core. Therefore I am postponing this issue with the solution almost working.
#2809521: Convert AJAX part of \Drupal\system\Tests\Ajax\AjaxInGroupTest to WebDriverTestBase
Comment #8
LendudeThe AjaxTestBase class was scuttled (in keeping with the maritime theme here), in #2809521: Convert AJAX part of \Drupal\system\Tests\Ajax\AjaxInGroupTest to WebDriverTestBase, so no need to wait for that anymore
Comment #9
martin107 CreditAttribution: martin107 as a volunteer commentedThanks for taking the time to dig through old issues and see that...
Lendude++
The patch needed a reroll... but the patch was so old and the changes so small... that I just started again.
Comment #11
martin107 CreditAttribution: martin107 as a volunteer commentedHmm .. that passes locally. I will look into it.
Comment #12
martin107 CreditAttribution: martin107 as a volunteer commentedI have just checked again today. Regarding 2809529-9.patch
I should qualify what I mean by works for me. I'm on PHP 7.2.9
So
composer run-script drupal-phpunit-upgrade
php core/scripts/run-tests.sh --file core/tests/Drupal/FunctionalJavascriptTests/Ajax/ElementValidationTest.php
Comment #13
martin107 CreditAttribution: martin107 as a volunteer commentedJust a minor problem I can see -- which I want to fold into the next meaningful change.
should be protected.
Comment #15
LendudeFails for me locally too. We need to do some extra things to get the ajax to trigger here.
This form though does some interesting thing when you do trigger ajax. The focus starts bouncing between the two field and this goes into an ajax request loop, so you need to take some steps to break out of that again.
This is more about getting this green than about getting this right. If we can prevent the ajax ping-pong this would probably be cleaner.
Comment #16
martin107 CreditAttribution: martin107 as a volunteer commentedThanks for solving the problem,
Having that understanding it really useful...
PS
I am currently starting a online petition to get the "Gordian Knot" renamed the "Lendude Knot".
Comment #17
Lendude@martin107 I'm always up for a nice puzzle :)
Little clean up. The ping-pong happens because after the ajax call the focus returns to the text field that triggered it, so if you go to another field with a blur event that returns the focus to itself when its own ajax call finishes.....ping pong!
So the only safe way to clear focus is to reload the page. This seems like a bug to me, but that seems out of scope for this conversion.
proper javascript testing++
I think this version is as clean as we can get it.
Comment #18
jibranOverall patch looks good to me. Just found some nits.
At least we can have $session local var. :)
$assert_session please.
Comment #19
Lendude@jibran thanks as always for the review.
Feedback addressed.
Comment #20
jibranThanks, for addressing the feedback.
Comment #23
larowlanCommitted ebee0dc and pushed to 8.7.x. Thanks!
Cherry picked as f2e993d2c8 and pushed to 8.6.x