From 6f5a1115b1b94a134ded20df1ddc5c2ac18f7e0d Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 21 Jan 2022 20:55:22 +0000
Subject: [PATCH] Issue #3259850 by Spokje: Having a deprecated module with non
 deprecated dependency leads to test failure in InstallUninstallTest

---
 ...le_with_non_deprecated_dependency.info.yml |  9 +++++
 .../Module/InstallUninstallTest.php           | 11 ++++++
 .../Module/NonStableModulesTest.php           | 39 +++++++++++++++++++
 3 files changed, 59 insertions(+)
 create mode 100644 core/modules/system/tests/modules/deprecated_module_with_non_deprecated_dependency/deprecated_module_with_non_deprecated_dependency.info.yml

diff --git a/core/modules/system/tests/modules/deprecated_module_with_non_deprecated_dependency/deprecated_module_with_non_deprecated_dependency.info.yml b/core/modules/system/tests/modules/deprecated_module_with_non_deprecated_dependency/deprecated_module_with_non_deprecated_dependency.info.yml
new file mode 100644
index 000000000000..25830f763ef0
--- /dev/null
+++ b/core/modules/system/tests/modules/deprecated_module_with_non_deprecated_dependency/deprecated_module_with_non_deprecated_dependency.info.yml
@@ -0,0 +1,9 @@
+name: Deprecated module with non deprecated dependency
+type: module
+description: 'Deprecated module with non deprecated dependency'
+package: Testing
+version: VERSION
+lifecycle: deprecated
+lifecycle_link: 'http://example.com/deprecated'
+dependencies:
+  - drupal:drupal_system_listing_compatible_test
diff --git a/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php b/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php
index f2fca213dae0..1235411a34fa 100644
--- a/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php
+++ b/core/modules/system/tests/src/Functional/Module/InstallUninstallTest.php
@@ -121,6 +121,17 @@ public function testInstallUninstall() {
         }
         $this->submitForm([], 'Continue');
       }
+      // Handle deprecated modules, which require a confirmation screen.
+      elseif ($lifecycle === ExtensionLifecycle::DEPRECATED) {
+        $this->assertSession()->pageTextContains('Are you sure you wish to enable a deprecated module?');
+        if (count($modules_to_install) > 1) {
+          // When there are deprecated modules, needed dependencies do not
+          // result in the same page title, but there will be expected text
+          // indicating they need to be enabled.
+          $this->assertSession()->pageTextContains('You must enable');
+        }
+        $this->submitForm([], 'Continue');
+      }
       // Handle the case where modules were installed along with this one and
       // where we therefore hit a confirmation screen.
       elseif (count($modules_to_install) > 1) {
diff --git a/core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php b/core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php
index c90cfd486f49..5629983d8ee9 100644
--- a/core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php
+++ b/core/modules/system/tests/src/Functional/Module/NonStableModulesTest.php
@@ -250,6 +250,45 @@ public function testDeprecatedConfirmForm(): void {
       'deprecated_module_dependency',
     ]);
 
+    // Check a deprecated module with a non-deprecated dependency.
+    $edit = [];
+    $edit["modules[deprecated_module_with_non_deprecated_dependency][enable]"] = TRUE;
+    $this->drupalGet('admin/modules');
+    $this->submitForm($edit, 'Install');
+
+    // The module should not be enabled and there should be a warning and a
+    // list of the deprecated modules with only this one.
+    $assert->pageTextNotContains('2 modules have been enabled: Deprecated module with non deprecated dependency, Drupal system listing compatible test');
+    $assert->pageTextContains('Deprecated modules are modules that may be removed from the next major release of Drupal core. Use at your own risk.');
+    $assert->pageTextContains('The Deprecated module with non deprecated dependency module is deprecated');
+    $more_information_link = $assert->elementExists('named', [
+      'link',
+      'The Deprecated module with non deprecated dependency module is deprecated. (more information)',
+    ]);
+    $this->assertEquals('http://example.com/deprecated', $more_information_link->getAttribute('href'));
+
+    // There should be a warning about enabling deprecated modules, but no
+    // warnings about experimental modules.
+    $this->assertSession()->pageTextContains('Are you sure you wish to enable a deprecated module?');
+    $this->assertSession()->pageTextNotContains('Are you sure you wish to enable an experimental module?');
+    $this->assertSession()->pageTextNotContains('Are you sure you wish to enable experimental and deprecated modules?');
+
+    // Ensure the non-deprecated dependency module is not listed as deprecated.
+    $assert->pageTextNotContains('The Drupal system listing compatible test module is deprecated');
+
+    // There should be a message about enabling dependencies.
+    $assert->pageTextContains('You must enable the Drupal system listing compatible test module to install Deprecated module with non deprecated dependency.');
+
+    // Enable the module and confirm that it worked.
+    $this->submitForm([], 'Continue');
+    $assert->pageTextContains('2 modules have been enabled: Deprecated module with non deprecated dependency, Drupal system listing compatible test.');
+
+    // Uninstall the modules.
+    \Drupal::service('module_installer')->uninstall([
+      'deprecated_module_with_non_deprecated_dependency',
+      'drupal_system_listing_compatible_test',
+    ]);
+
     // Finally, check both the module and its deprecated dependency. There is
     // still a warning about deprecated modules, but no message about
     // dependencies, since the user specifically enabled the dependency.
-- 
GitLab