From e71ddea02d7c4e02c6125ff6a614b3df03110648 Mon Sep 17 00:00:00 2001
From: catch <6915-catch@users.noreply.drupalcode.org>
Date: Sun, 11 Aug 2024 10:06:55 +0900
Subject: [PATCH] Issue #3464431 by idebr, Lendude: Attach Ajax dialog library
 for Views Entity Operations

---
 .../NodeDeleteConfirmTest.php                 | 32 +++++++++++++++----
 .../Plugin/views/field/EntityOperations.php   |  4 +++
 .../views/field/EntityOperationsUnitTest.php  |  6 ++++
 3 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/core/modules/node/tests/src/FunctionalJavascript/NodeDeleteConfirmTest.php b/core/modules/node/tests/src/FunctionalJavascript/NodeDeleteConfirmTest.php
index 2e040fee4c79..5eb912c577cd 100644
--- a/core/modules/node/tests/src/FunctionalJavascript/NodeDeleteConfirmTest.php
+++ b/core/modules/node/tests/src/FunctionalJavascript/NodeDeleteConfirmTest.php
@@ -5,6 +5,7 @@
 namespace Drupal\Tests\node\FunctionalJavascript;
 
 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
+use Drupal\views\Views;
 
 /**
  * Tests JavaScript functionality specific to delete operations.
@@ -65,10 +66,10 @@ public function testNodeDelete(): void {
     $this->assertEquals('Are you sure you want to delete the content item Delete article from content list?', $assert_session->waitForElement('css', '.ui-dialog-title')->getText());
     $page->find('css', '.ui-dialog-buttonset')->pressButton('Delete');
 
-    $assert_session->waitForText('The Article Delete article from content list has been deleted.');
+    $assert_session->pageTextContains('The Article Delete article from content list has been deleted.');
     // Assert that the node is deleted in above operation.
-    $this->drupalGet('/admin/content');
-    $assert_session->waitForText('There are no content items yet.');
+    $this->drupalGet('admin/content');
+    $assert_session->pageTextContains('There are no content items yet.');
 
     $node = $this->createNode([
       'type' => 'article',
@@ -82,11 +83,28 @@ public function testNodeDelete(): void {
     $this->assertEquals('Are you sure you want to delete the content item Delete article from entity form?', $assert_session->waitForElement('css', '.ui-dialog-title')->getText());
 
     $page->find('css', '.ui-dialog-buttonset')->pressButton('Delete');
-    $this->assertSession()->pageTextContains('The Article Delete article from entity form has been deleted.');
+    $assert_session->pageTextContains('The Article Delete article from entity form has been deleted.');
 
-    // Assert that the node is deleted in above operation.
-    $this->drupalGet('/admin/content');
-    $assert_session->waitForText('There are no content items yet.');
+    $node = $this->createNode([
+      'type' => 'article',
+      'title' => 'Delete article from views entity operations',
+    ]);
+    $node->save();
+
+    \Drupal::service('module_installer')->install(['views']);
+    $view = Views::getView('content');
+    $view->storage->enable()->save();
+    \Drupal::service('router.builder')->rebuildIfNeeded();
+
+    $this->drupalGet('admin/content');
+    $page->find('css', '.dropbutton-toggle button')->click();
+    $page->clickLink('Delete');
+    // Asserts a dialog opens with the expected text.
+    $this->assertEquals('Are you sure you want to delete the content item Delete article from views entity operations?', $assert_session->waitForElement('css', '.ui-dialog-title')->getText());
+    $page->find('css', '.ui-dialog-buttonset')->pressButton('Delete');
+
+    $assert_session->pageTextContains('The Article Delete article from views entity operations has been deleted.');
+    $assert_session->pageTextContains('No content available.');
   }
 
   /**
diff --git a/core/modules/views/src/Plugin/views/field/EntityOperations.php b/core/modules/views/src/Plugin/views/field/EntityOperations.php
index 8b70254489c1..b397d477824e 100644
--- a/core/modules/views/src/Plugin/views/field/EntityOperations.php
+++ b/core/modules/views/src/Plugin/views/field/EntityOperations.php
@@ -147,6 +147,10 @@ public function render(ResultRow $values) {
     $build = [
       '#type' => 'operations',
       '#links' => $operations,
+      // Allow links to use modals.
+      '#attached' => [
+        'library' => ['core/drupal.dialog.ajax'],
+      ],
     ];
 
     return $build;
diff --git a/core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php b/core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php
index a1c2a78a99ee..d357d5a0a47c 100644
--- a/core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php
+++ b/core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php
@@ -134,6 +134,9 @@ public function testRenderWithDestination(): void {
     $expected_build = [
       '#type' => 'operations',
       '#links' => $operations,
+      '#attached' => [
+        'library' => ['core/drupal.dialog.ajax'],
+      ],
     ];
     $expected_build['#links']['foo']['query'] = ['destination' => 'foobar'];
     $build = $this->plugin->render($result);
@@ -176,6 +179,9 @@ public function testRenderWithoutDestination(): void {
     $expected_build = [
       '#type' => 'operations',
       '#links' => $operations,
+      '#attached' => [
+        'library' => ['core/drupal.dialog.ajax'],
+      ],
     ];
     $build = $this->plugin->render($result);
     $this->assertSame($expected_build, $build);
-- 
GitLab