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 WebDriverTestBase

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.

martin107’s picture

Status: Active » Needs review
FileSize
3.43 KB

I am cutting out a patch from #2862510: Convert system/tests/src/Ajax to JavascriptTestBase

it transforms drupalPostAjaxForm() with methods calls like selectFIeldOption() etc

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

Status: Needs review » Needs work

This looks great, just some minor things:

  1. +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php
    @@ -1,17 +1,25 @@
    +class AjaxFormCacheTest extends JavascriptTestBase {
    

    This needs to be updated to WebDriverTestBase

  2. +++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php
    @@ -1,17 +1,25 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    

    This can just be {@inheritdoc}

martin107’s picture

Status: Needs work » Needs review
FileSize
3.4 KB
945 bytes

Lendude++

Thanks for picking this up and reviewing.

martin107’s picture

Title: Convert AJAX part of \Drupal\system\Tests\Ajax\AjaxFormCacheTest to JavascriptTestBase » Convert AJAX part of \Drupal\system\Tests\Ajax\AjaxFormCacheTest to WebDriverTestBase
Lendude’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

@martin107 thanks so much for working on these issues.

Feedback has been addressed, looks good to me now.

The last submitted patch, 6: 2809517-6.patch, failed testing. View results

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php
index f3a5ba5dd5..52e095267e 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php
@@ -58,9 +58,8 @@ public function testBlockForms() {
     // Select first option and trigger ajax update.
     $session->getPage()->selectFieldOption('edit-test1', 'option1');
 
-    // Wait for DOM update:
-    // The InsertCommand in the AJAX response changes the text in the option
-    // element to 'Option1!!!'
+    // DOM update: The InsertCommand in the AJAX response changes the text
+    // in the option element to 'Option1!!!'.
     $opt1_selector = $this->assertSession()->waitForElement('css', "select[data-drupal-selector='edit-test1'] option:contains('Option 1!!!')");
     $this->assertNotEmpty($opt1_selector);
     $this->assertTrue($opt1_selector->isSelected());
@@ -94,7 +93,7 @@ public function testQueryString() {
     $session->getPage()->selectFieldOption('edit-test1', 'option1');
 
     // DOM update: The InsertCommand in the AJAX response changes the text
-    // in the option element to 'Option1!!!'
+    // in the option element to 'Option1!!!'.
     $opt1_selector = $this->assertSession()->waitForElement('css', "option:contains('Option 1!!!')");
     $this->assertNotEmpty($opt1_selector);
 

Made the comments consistent and adhering to our coding standards - ending with a full stop - on commit.

Committed and pushed 2f08f6de5e to 8.7.x and 67e7c8cdf6 to 8.6.x. Thanks!

  • alexpott committed 2f08f6d on 8.7.x
    Issue #2809517 by martin107, Lendude: Convert AJAX part of \Drupal\...

  • alexpott committed 67e7c8c on 8.6.x
    Issue #2809517 by martin107, Lendude: Convert AJAX part of \Drupal\...

Status: Fixed » Closed (fixed)

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