From 97986f688ebc73e0a37169a37d58f2528a315298 Mon Sep 17 00:00:00 2001
From: "kunal.sachdev" <kunal.sachdev@3685163.no-reply.drupal.org>
Date: Mon, 25 Oct 2021 11:59:05 +0000
Subject: [PATCH] Issue #3244360 by kunal.sachdev: Add more context to
 UpdateVersionValidator error messages

---
 src/Validator/UpdateVersionValidator.php             | 12 ++++++++----
 tests/fixtures/fake-site/.htaccess                   |  1 +
 tests/fixtures/fake-site/cache/.htaccess             |  1 +
 tests/src/Functional/UpdaterFormTest.php             |  3 ++-
 .../UpdateVersionValidatorTest.php                   |  8 ++++++--
 5 files changed, 18 insertions(+), 7 deletions(-)
 create mode 100644 tests/fixtures/fake-site/.htaccess
 create mode 100644 tests/fixtures/fake-site/cache/.htaccess

diff --git a/src/Validator/UpdateVersionValidator.php b/src/Validator/UpdateVersionValidator.php
index b46d34a0dc..a824ab44fe 100644
--- a/src/Validator/UpdateVersionValidator.php
+++ b/src/Validator/UpdateVersionValidator.php
@@ -68,15 +68,19 @@ class UpdateVersionValidator implements EventSubscriberInterface {
       $event->addValidationResult($error);
     }
     elseif ($from_version->getMajorVersion() !== $to_version->getMajorVersion()) {
-      $error = ValidationResult::createError([
-        $this->t('Updating from one major version to another is not supported.'),
+      $messages[] = $this->t('Drupal cannot be automatically updated from its current version, @from_version, to the recommended version, @to_version, because automatic updates from one major version to another are not supported.', [
+        '@to_version' => $to_version_string,
+        '@from_version' => $from_version_string,
       ]);
+      $error = ValidationResult::createError($messages);
       $event->addValidationResult($error);
     }
     elseif ($from_version->getMinorVersion() !== $to_version->getMinorVersion()) {
-      $error = ValidationResult::createError([
-        $this->t('Updating from one minor version to another is not supported.'),
+      $messages[] = $this->t('Drupal cannot be automatically updated from its current version, @from_version, to the recommended version, @to_version, because automatic updates from one minor version to another are not supported.', [
+        '@from_version' => $this->getCoreVersion(),
+        '@to_version' => $event->getPackageVersions()[$core_package_name],
       ]);
+      $error = ValidationResult::createError($messages);
       $event->addValidationResult($error);
     }
 
diff --git a/tests/fixtures/fake-site/.htaccess b/tests/fixtures/fake-site/.htaccess
new file mode 100644
index 0000000000..14249c50bd
--- /dev/null
+++ b/tests/fixtures/fake-site/.htaccess
@@ -0,0 +1 @@
+Deny from all
\ No newline at end of file
diff --git a/tests/fixtures/fake-site/cache/.htaccess b/tests/fixtures/fake-site/cache/.htaccess
new file mode 100644
index 0000000000..14249c50bd
--- /dev/null
+++ b/tests/fixtures/fake-site/cache/.htaccess
@@ -0,0 +1 @@
+Deny from all
\ No newline at end of file
diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php
index 193bc951ba..a5c486492b 100644
--- a/tests/src/Functional/UpdaterFormTest.php
+++ b/tests/src/Functional/UpdaterFormTest.php
@@ -224,11 +224,12 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
    */
   public function testMinorVersionUpdateNotSupported(string $update_form_url): void {
     $this->setCoreVersion('9.7.1');
+    $this->checkForUpdates();
 
     $this->drupalGet($update_form_url);
 
     $assert_session = $this->assertSession();
-    $assert_session->pageTextContainsOnce('Updating from one minor version to another is not supported.');
+    $assert_session->pageTextContainsOnce('Drupal cannot be automatically updated from its current version, 9.7.1, to the recommended version, 9.8.1, because automatic updates from one minor version to another are not supported.');
     $assert_session->buttonNotExists('Update');
   }
 
diff --git a/tests/src/Kernel/ReadinessValidation/UpdateVersionValidatorTest.php b/tests/src/Kernel/ReadinessValidation/UpdateVersionValidatorTest.php
index f4a1d06e82..b98fb2027f 100644
--- a/tests/src/Kernel/ReadinessValidation/UpdateVersionValidatorTest.php
+++ b/tests/src/Kernel/ReadinessValidation/UpdateVersionValidatorTest.php
@@ -32,7 +32,9 @@ class UpdateVersionValidatorTest extends AutomaticUpdatesKernelTestBase {
    */
   public function testMajorUpdates(): void {
     $this->setCoreVersion('8.9.1');
-    $result = ValidationResult::createError(['Updating from one major version to another is not supported.']);
+    $result = ValidationResult::createError([
+      'Drupal cannot be automatically updated from its current version, 8.9.1, to the recommended version, 9.8.1, because automatic updates from one major version to another are not supported.',
+    ]);
     $this->assertCheckerResultsFromManager([$result], TRUE);
 
   }
@@ -42,7 +44,9 @@ class UpdateVersionValidatorTest extends AutomaticUpdatesKernelTestBase {
    */
   public function testMinorUpdates(): void {
     $this->setCoreVersion('9.7.1');
-    $result = ValidationResult::createError(['Updating from one minor version to another is not supported.']);
+    $result = ValidationResult::createError([
+      'Drupal cannot be automatically updated from its current version, 9.7.1, to the recommended version, 9.8.1, because automatic updates from one minor version to another are not supported.',
+    ]);
     $this->assertCheckerResultsFromManager([$result], TRUE);
   }
 
-- 
GitLab