With #2544020: CKEditor plugin not written with CKEditor >=4.4 in mind; rewrite it based on core's `drupalimage` plugin, #2282957: Caption should work like the drupalimage plugin (editable in WYSIWYG, not in dialog) and #2511404: Image entities/fields embedded using Entity Embed cannot be linked in CKEditor landing, we're stabilizing the CKEditor Widget. We already have some test coverage for it thanks to #2466013: Write test for CKEditor integration, but while stabilizing it, I discovered additional edge cases that warrant test coverage but did not warrant blocking an RC release since they're solid improvements already.

Furthermore, by taking a high-level overview of the different testing needs (edge case scenarios), I think we can test this more effectively.

This issue is for adding that test coverage.

Known edge cases to test:

  • 👍 Triggering "Source" button does not trigger a blur event on the caption editable, which results in the source being inaccurate. The blur event should be triggered.
  • 👍 Bold, italics etc work in the caption editable *and* are properly HTML-encoded.
  • 👍 Inserting a link in the caption editable fails in the drupallink plugin on this line: var range = selection.getRanges(1)[0];
  • 👍 Bold, italics etc work in the caption editable *and* are properly HTML-encoded *and* are displayed properly in the EntityEmbedDialog *but* upon saving that dialog they're escaped.
  • 👍 Not specifying a caption in EntityEmbedDialog causes no data-caption value to be sent to the client; the client should not fail, and automatically update the preview to be captionless.
  • <drupal-entity> tags without a data-embed-button attribute should be upcast but not be editable, and same for those with that same attribute whose value is not one of the currently enabled text editor buttons (or perhaps even a nonsensical one). Only the remaining ones should trigger the EntityEmbedDialog.

Comments

Wim Leers created an issue. See original summary.

oknate’s picture

StatusFileSize
new8.94 KB

Here's a start for the test for the caption being editable in the wysiwyg. It validates the basic functionality, but not the edge cases in this issue yet.

wim leers’s picture

wim leers’s picture

#2: DUDE THAT WAS SO FAST WHAT THE HELL!? 😀

oknate’s picture

Lol, I started working on it when I saw the original issue (#2282957) was ready for tests when I got up this morning. I can work on it more this evening, or if you want to move it along, that's cool too.

wim leers’s picture

No, I'll be traveling to https://cluj2019.drupaldays.org tomorrow to sprint on Media (which includes integrating Entity Embed with Media Library and generating core patches), I'll be spending tonight with my wife, she'll have to miss me all week (including this long weekend — Monday is a national holiday in Belgium). So if you'd like to continue, that'd be superb 🥳

oknate’s picture

Status: Active » Needs review
StatusFileSize
new18.65 KB
new21.4 KB

Adding coverage for edge cases in the issue summary, except for this:

Triggering "Source" button does not trigger a blur event on the caption editable, which results in the source being inaccurate. The blur event should be triggered.

I'm not sure what the issue is there, nor how to test it. And I don't really see a problem. The source seems accurate. I need some clarification on what the issue to test is there.

Status: Needs review » Needs work

The last submitted patch, 7: entity-embed-3060396-7.patch, failed testing. View results

oknate’s picture

Status: Needs work » Needs review
StatusFileSize
new1.74 KB
new21.42 KB

I can't recreate the error on testbot in #7. I don't see that error locally. I changed that part of the code slightly to see if I can circumvent the issue.

Also adding some coding standard fixes.

Status: Needs review » Needs work

The last submitted patch, 9: entity-embed-3060396-9.patch, failed testing. View results

oknate’s picture

Status: Needs work » Needs review
StatusFileSize
new21.46 KB
new2.87 KB

Still the same failure in #9 as #7. I suspect the double click is not working properly on headless chrome. Testing version without double clicks. Although after I posted this, I figured out how to run it locally headless and tested #7, and I didn't get the error.

oknate’s picture

StatusFileSize
new4.51 KB
new22.09 KB

I realized that one bit of js wasn't executing as I failed to actually execute it. When I updated it to run, I was getting an ajax error. Here's the code in question:

    $select_and_edit_embed = <<<JS
var editor = CKEDITOR.instances['edit-body-0-value'];
var entityEmbed = editor.widgets.getByElement(editor.editable().findOne('div'));
entityEmbed.focus();
editor.execCommand('editdrupalentity');
JS;
    $this->getSession()->executeScript($select_and_edit_embed);

I had left off the execution line.

I've tried various ways of testing whether the widget is editable. There's a function added in the anonymous function isEditableEntityWidget(), so I could possibly check that in the test if it’s exposed outside the anonymous function. But I think it's better to actually run the code rather than just test the attributes.

I propose that the editdrupalentity command above should run without error, whether there is a drupal-embed-button attribute or not.

This also would fix an edge case where the command is run instead of prevented to run.

To get this to work, I added some code to the editdrupalentity command borrowed from isEditableEntityWidget():

          if (typeof embed_button_id === 'undefined' || !editor.config.DrupalEntity_buttons.hasOwnProperty(embed_button_id)) {
            return;
          }

I tried to actually have it run isEditableEntityWidget() there, but I couldn't get it to work I was getting the following error:

1) Drupal\Tests\entity_embed\FunctionalJavascript\MediaImageTest::testJavascriptWidget
WebDriver\Exception\JavaScriptError: javascript error: d.is is not a function
  (Session info: chrome=74.0.3729.169)
  (Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.11.6 x86_64)

/Users/oknate/dev/entity_browser_testing/web/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:155
/Users/oknate/dev/entity_browser_testing/web/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:157
/Users/oknate/dev/entity_browser_testing/web/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:218
/Users/oknate/dev/entity_browser_testing/web/vendor/instaclick/php-webdriver/lib/WebDriver/Container.php:224
/Users/oknate/dev/entity_browser_testing/web/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:931
/Users/oknate/dev/entity_browser_testing/web/vendor/behat/mink/src/Session.php:329
/Users/oknate/dev/entity_browser_testing/web/modules/contrib/entity_embed/tests/src/FunctionalJavascript/EntityEmbedTestBase.php:84
/Users/oknate/dev/entity_browser_testing/web/modules/contrib/entity_embed/tests/src/FunctionalJavascript/MediaImageTest.php:546
/Users/oknate/dev/entity_browser_testing/web/vendor/phpunit/phpunit/src/Framework/TestCase.php:1071
/Users/oknate/dev/entity_browser_testing/web/vendor/phpunit/phpunit/src/Framework/TestCase.php:939
/Users/oknate/dev/entity_browser_testing/web/vendor/phpunit/phpunit/src/Framework/TestResult.php:698
/Users/oknate/dev/entity_browser_testing/web/vendor/phpunit/phpunit/src/Framework/TestCase.php:894

But it worked with the above condition. This allows the code to tests if, when the data-embed-button attribute is missing, it doesn't try to launch a dialog.

I also added another helper function for readability.

wim leers’s picture

StatusFileSize
new15.5 KB
new23.32 KB

I'm not sure what the issue is there, nor how to test it. And I don't really see a problem. The source seems accurate. I need some clarification on what the issue to test is there.

That was fixed prior to commit, hence you can't reproduce it anymore :) It was a bug in an earlier iteration. So don't worry — that actually makes sense!

#12:

  • That's a lot of different things in a single comment. So it's gonna be hard to make this clear what I'm replying to.
  • I propose that the editdrupalentity command above should run without error, whether there is a drupal-embed-button attribute or not.

    Making it a no-op can work. But why do we even need it? Why are we even triggering those embeds without that attribute? I think this is just an artifact of us not being able to double-click the widget due to test infrastructure (webdriver) limitations. We shouldn't be modifying our code just to work around test infra limitations.

  • I tried to actually have it run isEditableEntityWidget() there

    Because that function is not exposed in the global scope. :)


My primary concern is that this is one super long test method testing all the things. I think it'd be better to split it up into different areas that we're exercising expectations against:
the widget's caption's editability
linkability of the overall widget
the upcasting of the widget working always, even if no appropriate button is specified

That's going to make this test much more valuable, because a failing test will now tell us in which area there is a problem.

wim leers’s picture

StatusFileSize
new1.53 KB
new22.76 KB
wim leers’s picture

  • Wim Leers committed 0f1ac9c on 8.x-1.x authored by oknate
    Issue #3060396 by oknate, Wim Leers: Add CKEditor Widget JS test...
wim leers’s picture

Status: Needs review » Fixed

🚢

oknate’s picture

That was fast, too! Thanks.

IRT:

I think this is just an artifact of us not being able to double-click the widget due to test infrastructure (webdriver) limitations.

Exactly. Double clicking was working locally and it was much nicer. I think my solution doesn't hurt anything, and it works. If you can come up with a more elegant way to simulate either double clicking or triggering the context menu, I'm all ears (or eyes, to improve upon the cliché).

It would be especially cool to see the context menu open in the tests and verify the custom text per button displays.

oknate’s picture

Nice job breaking it up. Thanks! I was thinking you might recommend that.

wim leers’s picture

Nice job breaking it up. Thanks! I was thinking you might recommend that.

😀

wim leers’s picture

Issue tags: +Media Initiative, +DevDaysCluj
rosinegrean’s picture

Issue tags: -DevDaysCluj +DevDaysTransylvania

  • Wim Leers committed 04b303f on 8.x-1.x
    Issue #3064782 by Wim Leers: Follow-up for #3060396: make CKEditor...

Status: Fixed » Closed (fixed)

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