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

  1. Figure out which part of the test is testing PHP code and which part ajax behaviour
  2. 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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

michielnugter’s picture

Component: phpunit » system.module
Issue tags: +phpunit initiative

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Lendude’s picture

First 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:

// The test theme overrides js.module.css without an implementation,
// thereby removing it.

is incorrect, the file under test isn't removed at all currently. Haven't figured out why yet, so that will fail.

Lendude’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 7: 2809533-7.patch, failed testing. View results

Lendude’s picture

Ok, 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.

Lendude’s picture

Status: Needs work » Needs review
FileSize
976 bytes
25.45 KB

this passes with the patch in #3006625: 'stylesheets-remove' test is broken so this needs to wait for that to land.

cleaned up a bit.

Lendude’s picture

Status: Needs review » Needs work

The last submitted patch, 11: 2809533-11.patch, failed testing. View results

Lendude’s picture

Status: Needs work » Needs review

#3006625: 'stylesheets-remove' test is broken landed so this should be green now...

jibran’s picture

Status: Needs review » Needs work

Great work!

  1. +++ b/core/modules/system/tests/src/Functional/Ajax/FrameworkTest.php
    @@ -0,0 +1,158 @@
    +  public function testAJAXRender() {
    ...
    +  public function testOrder() {
    

    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 and drupalGetAjax

  2. +++ b/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php
    @@ -0,0 +1,113 @@
    +    $this->getSession()->getPage()->checkField('add_files');
    +    $this->getSession()->getPage()->pressButton('Submit');
    +    $this->assertSession()->assertWaitOnAjaxRequest();
    ...
    +    $this->assertSession()->responseNotContains('js.module.css?', 'Ajax lazy loading does not add overridden CSS files.');
    

    Local vars please.

Lendude’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
3.56 KB
25.49 KB

Thanks 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

jibran’s picture

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

If 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.

+++ b/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php
@@ -0,0 +1,122 @@
+    ¶

Can be fixed on commit.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I feel like that is out of scope. This one is good to go.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed f762c6a708 to 8.7.x and b1d24dd33c to 8.6.x. Thanks!

diff --git a/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php b/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php
index a63262b614..60f10b35f9 100644
--- a/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php
+++ b/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php
@@ -106,7 +106,7 @@ public function testLazyLoadOverriddenCSS() {
     $this->drupalGet('ajax_forms_test_lazy_load_form');
     $page = $this->getSession()->getPage();
     $assert = $this->assertSession();
-    
+
     $page->checkField('add_files');
     $page->pressButton('Submit');
     $assert->assertWaitOnAjaxRequest();

Fixed spaces on commit.

  • alexpott committed f762c6a on 8.7.x
    Issue #2809533 by Lendude, jibran: Convert AJAX part of \Drupal\system\...

  • alexpott committed 3c7cf83 on 8.6.x
    Issue #2809533 by Lendude, jibran: Convert AJAX part of \Drupal\system\...

  • alexpott committed e294daf on 8.6.x
    Revert "Issue #2809533 by Lendude, jibran: Convert AJAX part of \Drupal\...
alexpott’s picture

The 8.6.x version of this somehow broke so reverted.

Lendude’s picture

@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.

  • alexpott committed 4f81a1d on 8.6.x
    Revert "Revert "Issue #2809533 by Lendude, jibran: Convert AJAX part of...
alexpott’s picture

@lendude thanks! Done what you suggested. Tests in sync across dev and bug branches is helpful :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.