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

Remaining tasks

User interface changes

API changes

Data model changes

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

The solution to this issue, is contained as a sub issue in this unreviable issue

https://www.drupal.org/project/drupal/issues/2862510

My solution is to cut out the relevant fraction. and paste it here.

There is one fly in the ointment, things need to be coordinated with other sub issues.

This issue which need review, builds up the ajaxTestBase class which this patch then extends.

#2809521: Convert AJAX part of \Drupal\system\Tests\Ajax\AjaxInGroupTest to WebDriverTestBase

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: Postponed » Needs work

No AjaxTestBase, no need to wait anymore.

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new8.02 KB

Needed a reroll so no interdiff.

We can't test for response code in WebDriverTests, let alone the response code of the AJAX call. So bit of a workaround for that.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

This is ready.

+++ /dev/null
@@ -1,65 +0,0 @@
-      $commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, 'select');
-      $expected = new DataCommand('#ajax_selected_color', 'form_state_value_select', $item);
-      $this->assertCommand($commands, $expected->render(), 'Verification of AJAX form values from a selectbox issued with a correct value.');

+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/FormValuesTest.php
@@ -0,0 +1,82 @@
+      $select = $assertSession->waitForElement('css', "div#ajax_selected_color:contains('$item')");
+      $this->assertNotNull($select, "DataCommand has updated the page with a value of $item.");

I like this change.

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

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Couple of coding standards issues here

FILE: ...e/tests/Drupal/FunctionalJavascriptTests/Ajax/FormValuesTest.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 18 | ERROR | [x] Expected one space after the comma, 0 found
 21 | ERROR | [x] Expected 1 blank line before function; 2 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new582 bytes
new8.05 KB

Feedback addressed.

lendude’s picture

StatusFileSize
new0 bytes
new8.05 KB

Sniff missed one, fixed here.

The last submitted patch, 13: 2809531-13.patch, failed testing. View results

lendude’s picture

StatusFileSize
new407 bytes
new8.05 KB

Sigh, now with the actual change....

The last submitted patch, 14: 2809531-14.patch, failed testing. View results

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 2809531-14.patch, failed testing. View results

lendude’s picture

Status: Needs work » Reviewed & tested by the community

Nightwatch test failure, back to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/FormValuesTest.php
@@ -0,0 +1,83 @@
+
+    $this->drupalGet('ajax_forms_test_get_form');

I'm not sure why we're doing an additional drupalGet() here. Is it necessary?

lendude’s picture

StatusFileSize
new639 bytes
new8.15 KB

@alexpott yup, because the AJAX calls throw errors they never properly finish, so we need to reset the page to avoid:
Unfinished AJAX requests while tearing down a test

Added a comment to the call, because yeah, that isn't really clear.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Back to rtbc now that the comment is added.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 752dd39303 to 8.7.x and 8f2862aaa6 to 8.6.x. Thanks!

  • alexpott committed 752dd39 on 8.7.x
    Issue #2809531 by Lendude, martin107, larowlan: Convert AJAX part of \...

  • alexpott committed 8f2862a on 8.6.x
    Issue #2809531 by Lendude, martin107, larowlan: Convert AJAX part of \...

Status: Fixed » Closed (fixed)

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