From d890962445bff6751a74577e062a0d74fd0f0bbf Mon Sep 17 00:00:00 2001 From: nod_ <nod_@598310.no-reply.drupal.org> Date: Thu, 25 Jul 2024 21:28:35 +0200 Subject: [PATCH] Issue #3308432 by devkinetic, BramDriesen, Shifali Baghel, cilefen, smustgrave, quietone, bnjmnm: The link on the Image tag is redirecting to an undefined page from the node preview screen (cherry picked from commit bd6abf7c4d6e5f4e92f0d8b63284844b7c8e9765) --- core/modules/node/node.preview.js | 2 +- .../NodePreviewLinkTest.php | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/modules/node/node.preview.js b/core/modules/node/node.preview.js index 071d190fd8f3..50bc58ade774 100644 --- a/core/modules/node/node.preview.js +++ b/core/modules/node/node.preview.js @@ -46,7 +46,7 @@ { text: Drupal.t('Leave preview'), click() { - window.top.location.href = event.target.href; + window.top.location.href = event.currentTarget.href; }, }, ], diff --git a/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php b/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php index 2a80ebe41452..33a8795a6498 100644 --- a/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php +++ b/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php @@ -54,15 +54,29 @@ public function testPreviewLinks(): void { $assertSession = $this->assertSession(); $this->drupalGet('node/add/test'); $this->submitForm([ - 'title[0][value]' => 'Test node', - 'body[0][value]' => '<a href="#foo">Anchor link</a><a href="/foo">Normal link</a>', + 'title[0][value]' => 'Test anchor link', + 'body[0][value]' => '<a href="#foo">Anchor link</a>', ], 'Preview'); $this->clickLink('Anchor link'); $assertSession->pageTextNotContains('Leave preview?'); + $this->drupalGet('node/add/test'); + $this->submitForm([ + 'title[0][value]' => 'Test normal link', + 'body[0][value]' => '<a href="/foo">Normal link</a>', + ], 'Preview'); $this->clickLink('Normal link'); $assertSession->pageTextContains('Leave preview?'); $this->click('button:contains("Leave preview")'); $this->assertStringEndsWith('/foo', $this->getUrl()); + $this->drupalGet('node/add/test'); + $this->submitForm([ + 'title[0][value]' => 'Test child element link', + 'body[0][value]' => '<a href="/foo" class="preview-child-element"><span>Child element link</span></a>', + ], 'Preview'); + $this->getSession()->getPage()->find('css', '.preview-child-element span')->click(); + $assertSession->pageTextContains('Leave preview?'); + $this->click('button:contains("Leave preview")'); + $this->assertStringEndsWith('/foo', $this->getUrl()); } } -- GitLab