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
The ajax command order is covered by \Drupal\Tests\Core\Ajax\AjaxResponseTest
, so we can remove part of that without losing coverage.
These tests are about the Ajax commands and are testing the actual commands in the responses, so we need to copy parts of WebTestBase that deal with getting these commands from responses (like drupalGetAjax). These methods should just be available of these tests, not on BrowserTestBase since in normal situations you should not need these commands and should just use a Javascript test.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#16 | 2809533-16.patch | 25.49 KB | Lendude |
Comments
Comment #3
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedComment #7
LendudeFirst roll.
I've stripped a bit of stuff that has to do with command ordering, especially in the Javascript test, since this is covered by
\Drupal\Tests\Core\Ajax\AjaxResponseTest
.I've added some methods from WebTestBase to the BrowserTestBase test since these methods returns the Ajax commands and those are what are under test here. So in this particular case it actually makes sense to have those commands.
testLazyLoadOverriddenCSS
doesn't work yet because it seems this statement:is incorrect, the file under test isn't removed at all currently. Haven't figured out why yet, so that will fail.
Comment #8
LendudeComment #10
LendudeOk, so that test should just pass. Opened #3006625: 'stylesheets-remove' test is broken to figure out if the functionality is broken or the test setup is wrong.
Comment #11
Lendudethis passes with the patch in #3006625: 'stylesheets-remove' test is broken so this needs to wait for that to land.
cleaned up a bit.
Comment #12
LendudeComment #14
Lendude#3006625: 'stylesheets-remove' test is broken landed so this should be green now...
Comment #15
jibranGreat work!
Let's convert these to WDTB as well just like #2809531-9: Convert AJAX part of \Drupal\system\Tests\Ajax\FormValuesTest::testSimpleAjaxFormValue to JavascriptTestBase and get rid of
assertCommand
anddrupalGetAjax
Local vars please.
Comment #16
LendudeThanks for the review!
#15.1 I feel they are needed in this case, since these tests are about testing the actual Commands and not about the results of these commands (as is usually the case, and which is what we test in a Javascript test). Updated the IS to reflect this. Make sense?
#15.2 fixed
Comment #17
jibranIf that's the case then let's convert those to KTB/Unit test and only test the JS functionality in JS Test. If you think this is out of scope then feel free to RTBC. It is RTBC other than this.
Can be fixed on commit.
Comment #18
borisson_I feel like that is out of scope. This one is good to go.
Comment #19
alexpottCommitted and pushed f762c6a708 to 8.7.x and b1d24dd33c to 8.6.x. Thanks!
Fixed spaces on commit.
Comment #23
alexpottThe 8.6.x version of this somehow broke so reverted.
Comment #24
Lendude@alexpott #3006625: 'stylesheets-remove' test is broken wasn't backported to 8.6.x, hence the fail. Since that is a test only fix, they can probably both be backported.
Comment #26
alexpott@lendude thanks! Done what you suggested. Tests in sync across dev and bug branches is helpful :)