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

  1. Fix all the TODO tags in the test.

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.

michielnugter’s picture

Assigned: Unassigned » michielnugter
michielnugter’s picture

Work in progress patch. I converted 1 of the 2 tests and can't get it to work yet. I have a lot of @TODO's for behavior I don't understand (yet) in there but wanted to share the progress.

Would love some early feedback on it as to why my first test fails.

michielnugter’s picture

Status: Active » Needs work
Lendude’s picture

Adding a drupalGet before the loading makes it pass. Makes little sense to me at the moment why that is.

The rest is just a little cleanup to make the method calls easier to trace.

michielnugter’s picture

Thanks for looking into it. It's very weird. I expect it to work even without the form submit but somehow it doesn't. The UI actually displays everything correctly. I don't really know at the moment how to fix it. For now I'll just accept the drupalGet and make the test work and convert the other test.

Nice code cleanup btw.

michielnugter’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
18.74 KB
40.67 KB

I updated the test and implemented the second test. This test has the same problems though.. The tests to pass right now so it's a start. Still some weird requirements that I can't explain with my limited knowledge of fields in D8.

For now this is all I can do and I'll continue working on other tests. I've already spend several hours trying to figure this out, maybe someone with more fields knowledge has some more insights?

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 » field_ui.module
Issue tags: +phpunit initiative
michielnugter’s picture

Status: Needs review » Needs work

Setting to proper status.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
40.54 KB

Rerolled #7, there was a conflict on core/modules/field_ui/src/Tests/ManageDisplayTest.php.

Mile23’s picture

Status: Needs review » Needs work

Testbot shows 25 coding standards errors: https://www.drupal.org/pift-ci-job/695080

Most are old-style array() declarations, which is unusual since we already fixed all those. That suggests the patch in #7 is out of date enough that the code being moved around doesn't reflect those array syntax fixes.

So one wonders what other changes aren't carried forward. Git log for ManageDisplayTest tells us that it's at least #2878369: Tests for local tasks in Manage Display are not correct which might be enough to fail a test or two. And maybe other changes since Nov. 2016.

That means that the code being moved into the trait here should be re-done so that we're sure we got all the changes.

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.

jibran’s picture

Issue tags: +Needs reroll

This should be converted to WTB.

MerryHamster’s picture

Reroll patch from #11 and fixed coding standards errors.

MerryHamster’s picture

Status: Needs work » Needs review
MerryHamster’s picture

MerryHamster’s picture

Status: Needs review » Needs work

The last submitted patch, 17: 2809501-17.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

savkaviktor16@gmail.com’s picture

Issue tags: -Needs reroll
Lendude’s picture

Assigned: michielnugter » Unassigned
Status: Needs work » Needs review
FileSize
16.04 KB
35.34 KB

Well, this take me back :)

Removed the new trait and just moved the one method to the test class. Removed all the todo's, cause if it's green it's green. Removed the weird third party assertion that was checking for something to be empty when we wouldn't actually expect it to be.

Lets see what the bot makes of this...

jibran’s picture

Perfect! this looks ready to me. Thank you.

+++ b/core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
@@ -429,2 +393,69 @@
+    $machine_name = $assert_session->waitForElementVisible('css', '[name="label"] + * .machine-name-value');

Haha, what makes you change your mind? :P

+++ b/core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
@@ -0,0 +1,461 @@
+    $display_storage = $this->entity_type_manager->getStorage('entity_view_display');
...
+    \Drupal::service('module_installer')->uninstall(['field_third_party_test']);
...
+    $display = $display_storage->loadUnchanged($display_id);

Pro Tip: Be careful about using the variables like this. After module uninstall we have a new container and storage is still old.

Lendude’s picture

#25.1 Haha! I was hoping you would spot that :-) In this case the actual machine name is never used (like it was in the other test), we just need the link to show up so we can click on it.

#25.2 Yeah there are a number of assertions/tricks in this test that don't belong in a functional test. But 1-1 conversion, and moving them to a kernel test and getting the site in the right state would be a bit of bloat.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Should have RTBCed 3 days ago sorry. :)

Manuel Garcia’s picture

Awesome to see this ready!

I had a look and it seems patch has some (tiny) CS issues:

  1. +++ b/core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
    @@ -0,0 +1,461 @@
    +  public static $modules = ['node', 'field_ui', 'field_test', 'field_third_party_test', 'block'];
    

    Nit: can we put these on a separate line each?

  2. +++ b/core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
    @@ -0,0 +1,461 @@
    +  protected $type;
    

    Missing docblock

  3. +++ b/core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
    @@ -0,0 +1,461 @@
    +
    

    Dont need this extra line.

  4. +++ b/core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
    @@ -0,0 +1,461 @@
    +    // Make sure we can save the third party settings when there are no settings available
    

    Line over 80 chars :)

Lendude’s picture

@Manuel Garcia thanks for taking a look. Feedback addressed, leaving it RTBC since its only cosmetic changes.

jibran’s picture

RTBC +1

Manuel Garcia’s picture

Thanks @Lendude for addressing those :)
RTBC++

  • catch committed 0855561 on 8.7.x
    Issue #2809501 by Lendude, michielnugter, MerryHamster, Manuel Garcia,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Fixed these on commit:

FILE: ...es/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
----------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
----------------------------------------------------------------------
 23 | WARNING | [x] A comma should follow the last multiline array
    |         |     item. Found: 'block'
 69 | ERROR   | [x] Visibility must be declared on method
    |         |     "testFormatterUI"
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Committed 0855561 and pushed to 8.7.x. Thanks!

Status: Fixed » Closed (fixed)

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