Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Status: Active » Needs review
FileSize
1.72 KB

Here's a patch that fixes the problem, but does not yet add test coverage.

In the standard profile, create an article node. Then visit node/1/body/und/full.

Before patch: 404.
After patch: Ajax response.

Wim Leers’s picture

Title: Editor's in-place editing AJAX endpoint broken because of #1043198 and routing system bug + missing test coverage » Editor's in-place editing AJAX endpoint broken because of #1043198 and routing system bug

\Drupal\editor\Tests\EditorIntegrationTest::testGetUntransformedTextCommand() already unit tests the logic.

I don't see the need to add "defend against API changes" integration tests.

webchick’s picture

Status: Needs review » Fixed

Confirmed test results from #2. This fixes a pretty major bug with Edit module and is a simple find/replace of a variable name, so I'm comfortable committing from needs review. And yeah "defend against API changes" doesn't really need test coverage.

Committed and pushed to 8.x. Thanks!

Gábor Hojtsy’s picture

Priority: Normal » Major
Status: Fixed » Needs work
Issue tags: +Needs tests

This makes in-place editing broken on the full node view. Elevating to major bug as per #2037687: Can no longer in-place edit body fields. I think it would be important to have test coverage for this path to ensure it has an AJAX response (with the right kind of data?). This is not the first time we had issues in core with router handling changing. While this sounds like protecting against future API changes, when we find regressions like this, we usually add tests to ensure they don't happen again. Especially since this is not for the first time.

Gábor Hojtsy’s picture

Priority: Major » Normal

I disagree this would not need test coverage, but since the fix itself was committed now, we can demote to normal.

webchick’s picture

That's definitely a good point. Sorry, I did not get much sleep last night. ;P Or the past 8 weeks, hehe.

Thomas Brekelmans’s picture

I'll try to add a test / expand the current tests inside the edit module to get coverage for this scenario.

The \Drupal\edit\Tests\EditLoadingTest class has a big testUserWithPermission() method that I could extend to do something similar as done here (asserting if the metadata for that field can be retrieved by checking if the HTTP response code is 200):

    $response = $this->retrieveMetadata(array('node/1/body/und/full'));
    $this->assertResponse(200);

I plan to check for the response of the editor URL in a similar fashion. I'll upload a patch with this idea later (after I've tested it locally).

Thomas Brekelmans’s picture

Status: Needs work » Needs review
FileSize
2.83 KB

Here's a patch that adds a couple of assertions around the existence of a route for POST /editor/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode_id} by checking if a cURL POST request with AJAX headers to "editor/node/1/body/und/full" gives the expected response.
(The field is already created during the tests for other assertions as well).

I had to include the editor module in the static $modules (to enable) property of the test because that's the module that actually defines the route.

Does this provide enough coverage for this scenario or do we need more?

tstoeckler’s picture

Can you upload a patch that reverts the committed patch, to prove that the tests do as advertised? Thanks.

Thomas Brekelmans’s picture

Here's a patch that reverts the changes from the patch in #1, but has my extra test assertions from #8 in place.

For me locally this results in 4 fails inside EditLoadingTest.php: the 4 assertions I added. I've included a screenshot of those errors/fails:
edit-editor-AJAX-endpoint-broken-tests-2031385-10-test-fails.png

Edit: and the patch has failed as expected, with the same 4 fails and messages. :)

I've also added an interdiff so you can easily see which lines I 'reverted' to re-create the original problem.

Status: Needs review » Needs work

The last submitted patch, edit-editor-AJAX-endpoint-broken-tests-2031385-10.patch, failed testing.

tstoeckler’s picture

Issue tags: -Needs tests, -sprint, -Spark

Awesome! Thanks for the quick turnaround. I'm not viable for RTBC-ing this myself, however.

tstoeckler’s picture

Issue tags: +sprint, +Spark

Didn't mean to remove those tags, but "Needs tests" is now in fact not necessary anymore.

Wim Leers’s picture

Wim Leers’s picture

#8 still passes — yay :)

I'll review this on Monday.

Wim Leers’s picture

The test in #8/#10 is being added to core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php, which is owned by edit.module, but the test itself tests an endpoint that is owned by editor.module. It is unacceptable that a edit.module test requires editor.module to be enabled.

So, I'm moving largely the same testing code (good job, Thomas Brekelmans!) into a new Drupal\editor\Tests\EditIntegrationLoadingTest test class. Yes, another WebTestBase test that will test the exact same thing as \Drupal\editor\Tests\EditIntegrationTest::testGetUntransformedTextCommand(), but now with with an HTTP request.

Furthermore, the test coverage that Thomas Brekelmans introduced was not yet testing:

  • the case of the user not having sufficient permissions
  • the returned data, only the fact that it was returning any data at all

While working on this, I happily ran into epic routing system crappiness, which I reported at #1984528-53: Follow-up: Allow for more robust access checking (they made a huge API change without updating existing code!).

And then, I got stuck on yet another routing system fail: the dreaded A fatal error occurred: (this happens when the route controller never even gets called), which is the very thing #1996378: Edit broken because of #1043198 and routing system bug + missing test coverage fixed and what we're providing test coverage for in this issue. But it turns out it happens whenever AjaxResponse. So one assertion is commented out, while waiting for that issue to get resolved. Issue for that: #2063303: A Drupal 8 AjaxResponse that must return a 403, returns a 403 and prints "A fatal error occurred: ".


Because of these two core bugs, getting this done took pretty much an entire day! But, at least, this patch should be RTBC'able… :)

Wim Leers’s picture

I forgot to remove one @todo that I fixed.

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Woot, thanks for the tests! The fix looks pretty good. I think the @todo in the test makes sense as-is, it would indeed be good to test for the empty response, but currently not possible.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Yay more tests! Committed and pushed to 8.x. Thanks!

Wim Leers’s picture

Issue tags: -sprint

.

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