js/plugins/drupalentity/plugin.js | 6 +++--- tests/src/FunctionalJavascript/MediaImageTest.php | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/js/plugins/drupalentity/plugin.js b/js/plugins/drupalentity/plugin.js index 6f8f72b..08c25f3 100644 --- a/js/plugins/drupalentity/plugin.js +++ b/js/plugins/drupalentity/plugin.js @@ -235,15 +235,15 @@ // Now that the caption is available in the DOM, make it editable. if (this.initEditable('caption', this.definition.editables.caption)) { // And ensure that any changes made to it are persisted. - var captionDomNode = this.editables.caption.$; + var captionEditable = this.editables.caption; var config = {characterData: true, attributes: false, childList: true, subtree: true}; var widget = this; this.captionEditableMutationObserver = new MutationObserver(function () { var entityAttributes = CKEDITOR.tools.clone(widget.data.attributes); - entityAttributes['data-caption'] = captionDomNode.innerHTML; + entityAttributes['data-caption'] = captionEditable.getData(); widget.setData('attributes', entityAttributes); }); - this.captionEditableMutationObserver.observe(captionDomNode, config); + this.captionEditableMutationObserver.observe(captionEditable.$, config); } }, diff --git a/tests/src/FunctionalJavascript/MediaImageTest.php b/tests/src/FunctionalJavascript/MediaImageTest.php index ac579a0..8c8757d 100644 --- a/tests/src/FunctionalJavascript/MediaImageTest.php +++ b/tests/src/FunctionalJavascript/MediaImageTest.php @@ -496,13 +496,29 @@ class MediaImageTest extends EntityEmbedTestBase { $this->assertSession()->elementExists('css', 'button.form-submit')->press(); $this->assertSession()->assertWaitOnAjaxRequest(); + $this->getSession()->switchToIFrame('ckeditor'); + + $figcaption = $this->assertSession()->waitForElement('css', 'figcaption'); + + $figcaption->find('css', 'a')->click(); + + $this->setCaption('Gotta leave you all behind and face the truth'); + + $this->pressEditorButton('source'); + + $source = $this->assertSession() + ->elementExists('xpath', "//textarea[contains(@class, 'cke_source')]"); + $value = $source->getValue(); + $this->assertContains('https://www.drupal.org/project/issues/entity_embed', $value); + $this->assertNotContains('data-cke-saved-href', $value); + // Save the entity. $this->assertSession()->buttonExists('Save')->press(); // Verify the saved entity when viewed also contains the captioned media. $link = $this->assertSession()->elementExists('xpath', '//figcaption//a'); - $this->assertEquals('http://www.drupal.org', $link->getAttribute('href')); - $this->assertEquals("I'm just a poor boy, I need no sympathy!", $link->getText()); + $this->assertEquals('https://www.drupal.org/project/issues/entity_embed', $link->getAttribute('href')); + $this->assertEquals("Gotta leave you all behind and face the truth", $link->getText()); // Edit it again, type a different caption in the widget. $this->drupalGet('node/' . $this->host->id() . '/edit');