Write tests to ensure that embed buttons are properly added to the CKEditor configuration toolbar and that it can be enabled/disabled by the user.

  1. Ensure that the correct tag/attributes are added to the allowed HTML configuration when someone adds the button (covers #2554687: <drupal-entity> tag not being automatically added when an Entity Embed button is added to active editor toolbar)
  2. Ensure that the CKEditor plugin can be used to insert and edit entity embeds, as well as correctly previewing the embedded entity.
CommentFileSizeAuthor
#33 2466013-33.patch9.26 KBWim Leers
#33 interdiff.txt2.83 KBWim Leers
#32 2466013-32.patch8.58 KBWim Leers
#32 interdiff.txt2.61 KBWim Leers
#31 entity-embed-integration-test-2466013-31.patch7.93 KBoknate
#31 2466013--interdiff-24-31.txt5.99 KBoknate
#24 2466013-24.patch6.54 KBWim Leers
#24 interdiff.txt4.09 KBWim Leers
#23 2466013-23.patch6.27 KBWim Leers
#23 interdiff.txt1.3 KBWim Leers
#21 entity-embed-ckeditor-integration-test-2466013-21.patch6.73 KBoknate
#21 interdiff-20-21.txt4.39 KBoknate
#19 entity-embed-ckeditor-integration-test-2466013-20.patch6.47 KBoknate
#19 interdiff-13-20.txt3.43 KBoknate
#18 entity-embed-ckeditor-integration-test-2466013-18.patch6.45 KBoknate
#18 interdiff-13-18.txt3.42 KBoknate
#17 entity-embed-ckeditor-integration-test-2466013-17.patch6.42 KBoknate
#17 interdiff-13-17.txt2.49 KBoknate
#13 entity-embed-ckeditor-integration-test-2466013-13.patch5.93 KBoknate
#13 interdiff-10-13.txt1.17 KBoknate
#10 entity-embed-ckeditor-integration-test-2466013-10.patch5.49 KBoknate
#8 entity-embed-ckeditor-integration-test-2466013-8.patch5.48 KBoknate
#7 entity-embed-ckeditor-integration-test-2466013-7.patch5.57 KBoknate
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

slashrsm’s picture

Issue tags: +Media Initiative, +sprint
slashrsm’s picture

Issue tags: -sprint +D8Media
Dave Reid’s picture

Issue summary: View changes
Dave Reid’s picture

Issue summary: View changes
Wim Leers’s picture

Title: Write test for CKEditor integration » [PP-1] Write test for CKEditor integration
Status: Active » Postponed
Issue tags: +JavaScript, +Needs JS tests
Related issues: +#2328659: Convert all existing entity_embed tests from WebTestBase to BrowserTestBase
Wim Leers’s picture

Title: [PP-1] Write test for CKEditor integration » Write test for CKEditor integration
Status: Postponed » Active
oknate’s picture

oknate’s picture

Removing test code "createScreenshot".

oknate’s picture

Note: I had to add some extra code because of a bug in #2752253: Document correct filter_html_image_secure + filter_align + filter_caption + entity_embed filters order, write tests, and ensure correct by default. Once that issue is resolved, I can update the test.

oknate’s picture

Coding standard fix (makes comment multiline).

oknate’s picture

Status: Active » Needs review
oknate’s picture

Status: Needs review » Needs work

- Needs to cover "Ensure that the correct tag/attributes are added to the allowed HTML configuration when someone adds the button"

oknate’s picture

Adding check that allowed formats are automatically updated in the filter format.

oknate’s picture

Status: Needs work » Needs review
oknate’s picture

In testing ImageFieldFormatter, I noticed that it requires "alt" and "title" attributes on the drupal-entity in order to function properly.

See: #3022768: Validate that `alt` and `title` are required attributes for `<drupal-entity>`, and ensure they're added by default.

I added a fix and a test class that adds functional test coverage. I would say that it's more test coverage for CKEditor integration, so it would be good to add that too.

I also noticed that there's some javascript testing that I missed in #13. When the user drags and drops the button into the toolbar it automatically updates the allowed_html via javascript. I didn't add test coverage for that, but rather after the form was saved. It would be easy to add.

So I'll mark this back as Needs Work.

oknate’s picture

Status: Needs review » Needs work
oknate’s picture

- adds assertion before drop and drag that allowed_html doesn't have drupal-entity, and after drop and drag it does.

+    $allowed_html = $this->assertSession()->fieldExists('filters[filter_html][settings][allowed_html]')->getValue();
+    $this->assertNotContains('drupal-entity', $allowed_html);
+
+    $target = $this->assertSession()->waitForElementVisible('css', 'ul.ckeditor-toolbar-group-buttons');
+    $nodeButton = $this->assertSession()->elementExists('xpath', '//li[@data-drupal-ckeditor-button-name="node"]');
+    $nodeButton->dragTo($target);
+
+    $allowed_html_updated = $this->assertSession()->fieldExists('filters[filter_html][settings][allowed_html]')->getValue();
+    $this->assertContains('drupal-entity data-entity-type data-entity-uuid data-entity-embed-display data-entity-embed-display-settings data-align data-caption data-embed-button', $allowed_html_updated);
oknate’s picture

Hmm, not sure why that failed. It passed on my local drupalci_testbot. Here's a slightly reorganized version.

oknate’s picture

oknate’s picture

Status: Needs work » Needs review
oknate’s picture

Changing $button to $this->button, which allows referencing it later. This will be useful because I plan to copy this test to test other usages.

Wim Leers’s picture

Priority: Normal » Major

O M G

EPIC progress here, thanks so much @oknate! 🥳🥳🙏

Wim Leers’s picture

#9 has been fixed in that other issue, so this patch can become slightly simpler again :)

Wim Leers’s picture

Fix nits.

Wim Leers’s picture

Status: Needs review » Needs work
+++ b/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
@@ -0,0 +1,170 @@
+    // Verify that the Entity Embed button shows up and results in an
+    // operational entity embedding experience in the text editor.
+    $this->drupalGet('/node/add/page');
+    $this->assertSession()->elementExists('css', 'a.cke_button__' . $this->button->id())->click();
+    $this->assertSession()->waitForId('drupal-modal');
+    $title = $this->node->label() . ' (' . $this->node->id() . ')';
+    $this->assertSession()->fieldExists('entity_id')->setValue($title);
+    $this->assertSession()->elementExists('css', 'button.js-button-next')->click();
+    $this->assertSession()->assertWaitOnAjaxRequest();
+    $this->assertSession()->responseContains('Selected entity');
+    $this->assertSession()->responseContains($this->node->label());
+    $this->assertSession()->elementExists('css', 'button.button--primary')->press();
+    $this->assertSession()->assertWaitOnAjaxRequest();
+    $this->assertSession()->waitForElementVisible('css', 'drupal-entity[data-embed-button="' . $this->button->id() . '"]');
+    $this->getSession()->getPage()->find('css', 'input[name="title[0][value]"]')->setValue('Testing Page with Embed');
+    $this->assertSession()->buttonExists('Save')->press();
+    $this->assertSession()->responseContains($this->node->label());

This is testing that a "Entity Embed" button in the text editor can insert an embedded entity into the text editor. (And that it is rendered when viewed.)

What this is not yet testing is that it's possible to edit an already existing <drupal-entity> in the content.

So adding something like

$this->drupalGet('/node/1/edit');
// double-click existing embed
// change something in dialog
// save dialog
// verify preview updated
// verify filtered result updated

would finish this.

Would you like to take his on? :)

Wim Leers’s picture

#25 is just to to have complete functional testing, but don't get me wrong: I'm super grateful for how far you've already pushed this! 🙏🙏🙏 Excellent work, extremely valuable contributions! 🤩

oknate’s picture

Sure I can work on this. Thanks for the review!

Wim Leers’s picture

LOVELY! Are you going to any Drupal events in the coming months? I totally owe you Belgian beer and chocolates for this :D

oknate’s picture

I don't have immediately plans. I'll let you know. Belgian beer and chocolates sounds great! If you're ever in New York, you can come visit me in the World Trade Center. It's a nice view.

Wim Leers’s picture

Oh wow! My wife and I may be coming to visit NYC this summer, then we'll bring Belgian beer & chocolates and take you up on your offer! :D

oknate’s picture

That would be lovely, DM me when you know your plans.

Here's an updated patch that replaces the embed, per #25.

Wim Leers’s picture

GREAT work, thanks so much @oknate!

  1. +++ b/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
    @@ -90,20 +95,30 @@ class CKEditorIntegrationTest extends WebDriverTestBase {
    +      'title' => 'Billy Bones',
    +      'body' => [
    +        'value' => 'He lacks two fingers.',
    ...
    +      'title' => 'Long John Silver',
    +      'body' => [
    +        'value' => 'A one-legged seafaring man.',
    

    😆

  2. +++ b/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
    @@ -90,20 +95,30 @@ class CKEditorIntegrationTest extends WebDriverTestBase {
    +        'format' => 'custom_format',
    

    Nit: this format does not exist. Fixed.

  3. +++ b/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
    @@ -153,18 +170,58 @@ class CKEditorIntegrationTest extends WebDriverTestBase {
    +    // Go back to main iFrame.
    +    $this->getSession()->switchToIFrame();
    ...
    +    // Go back to main iFrame.
    +    $this->getSession()->switchToIFrame();
    

    There's no need for switching back if we didn't switch to something else first.

  4. +++ b/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
    @@ -153,18 +170,58 @@ class CKEditorIntegrationTest extends WebDriverTestBase {
    +    // Test opening the dialog and switching embedded nodes.
    +    $this->assertSession()->waitForText('Billy Bones');
    

    This isn't quite testing what it seems to be testing; this was just waiting for the max timeout.

    That's because this is not switching to the CKEditor iframe, and it's only in that iframe that this text is supposed to appear.

    Fixed.

Wim Leers’s picture

This addresses #32.3, adds a few additional comments to clarify what's being tested and adds matching before/after assertions to make the existing assertions more trustworthy and hence more valuable.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Still green — YAY — let's do this! This will certainly help ensure that #2544020: CKEditor plugin not written with CKEditor >=4.4 in mind; rewrite it based on core's `drupalimage` plugin does not introduce regressions! 🥳

Wim Leers’s picture

Issue summary: View changes

Updating IS, assigning appropriate attribution.

Wim Leers’s picture

Component: Code » CKEditor integration
Status: Reviewed & tested by the community » Fixed

  • Wim Leers committed 112414b on 8.x-1.x
    Issue #2466013 by oknate, Wim Leers, Dave Reid: Write test for CKEditor...
Wim Leers’s picture

UGH I just noticed that this was attributed to me instead of @oknate because I uploaded the last patch. d.o's default attribution algorithm often trips me up that way :( Very sorry, @oknate :/ Because you definitely are the primary author of this patch!

To compensate, I'll attribute you instead of myself on the next thing I actually am the primary author of.

oknate’s picture

No problem, thanks for getting it in! I would like to add test coverage for media to this test, since that's what we're looking to move into core. I'll look into that. Maybe a separate issue: Add test coverage for media embed.

Wim Leers’s picture

If you're willing to do that, that'd be lovely! 🙏😃

That would also help #2998005: [PP-1] Support Drupal core's Media Library go faster 💪

Status: Fixed » Closed (fixed)

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