From fd11c5a42cb026e7d51ef2112af83f28070f5f81 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 10 Mar 2020 22:15:20 +0000
Subject: [PATCH] Issue #3098475 by Berdir, catch, TravisCarden, xjm,
 benjifisher, alexpott, larowlan, webchick, dww: Add more strict checking of
 hook_update_last_removed() and better explanation

---
 .../update_test_last_removed.info.yml                |  2 +-
 .../update_test_last_removed.install                 |  4 ++--
 .../UpdateSystem/UpdatePathLastRemovedTest.php       | 12 ++++++------
 core/tests/Drupal/Tests/UpdatePathTestTrait.php      |  3 ++-
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/core/modules/system/tests/modules/update_test_last_removed/update_test_last_removed.info.yml b/core/modules/system/tests/modules/update_test_last_removed/update_test_last_removed.info.yml
index f4828a780734..934ded52bc58 100644
--- a/core/modules/system/tests/modules/update_test_last_removed/update_test_last_removed.info.yml
+++ b/core/modules/system/tests/modules/update_test_last_removed/update_test_last_removed.info.yml
@@ -1,4 +1,4 @@
-name: 'Update test with update_last_removed implementation'
+name: 'Update test with hook_update_last_removed() implementation'
 type: module
 description: 'Support module for update testing.'
 package: Testing
diff --git a/core/modules/system/tests/modules/update_test_last_removed/update_test_last_removed.install b/core/modules/system/tests/modules/update_test_last_removed/update_test_last_removed.install
index 7b9700fca0ec..1ba6ad1750c0 100644
--- a/core/modules/system/tests/modules/update_test_last_removed/update_test_last_removed.install
+++ b/core/modules/system/tests/modules/update_test_last_removed/update_test_last_removed.install
@@ -2,11 +2,11 @@
 
 /**
  * @file
- * Install, update and uninstall functions for the update_test_invalid_hook module.
+ * Update functions for the update_test_invalid_hook module.
  */
 
 /**
- * Implements hook_update_last_removed()
+ * Implements hook_update_last_removed().
  */
 function update_test_last_removed_update_last_removed() {
   return 8002;
diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php
index fc34b6adb912..30f8b38905ab 100644
--- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php
+++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathLastRemovedTest.php
@@ -47,21 +47,21 @@ protected function setUp() {
   }
 
   /**
-   * Test that a module with a too old schema version can not be updated.
+   * Tests that a module with a too old schema version can not be updated.
    */
   public function testLastRemovedVersion() {
     drupal_set_installed_schema_version('update_test_last_removed', 8000);
     drupal_set_installed_schema_version('system', 8804);
 
-    // Access the update page with too old versions for system and the test
-    // module, only the generic core message should be shown.
+    // Access the update page with a schema version that is too old for system
+    // and the test module, only the generic core message should be shown.
     $this->drupalLogin($this->updateUser);
     $this->drupalGet($this->updateUrl);
     $assert_session = $this->assertSession();
     $assert_session->pageTextContains('Requirements problem');
     $assert_session->pageTextContains('The version of Drupal you are trying to update from is too old');
     $assert_session->pageTextContains('Updating to Drupal 9 is only supported from Drupal version 8.8.0 or higher. If you are trying to update from an older version, first update to the latest version of Drupal 8');
-    $assert_session->pageTextNotContains('Unsupported schema version: Update test with update_last_removed implementation');
+    $assert_session->pageTextNotContains('Unsupported schema version: Update test with hook_update_last_removed() implementation');
 
     $assert_session->linkNotExists('Continue');
 
@@ -72,8 +72,8 @@ public function testLastRemovedVersion() {
 
     $assert_session->pageTextNotContains('The version of Drupal you are trying to update from is too old');
 
-    $assert_session->pageTextContains('Unsupported schema version: Update test with update_last_removed implementation');
-    $assert_session->pageTextContains('The installed version of the Update test with update_last_removed implementation module is too old to update. Update to an intermediate version first (last removed version: 8002, installed version: 8000).');
+    $assert_session->pageTextContains('Unsupported schema version: Update test with hook_update_last_removed() implementation');
+    $assert_session->pageTextContains('The installed version of the Update test with hook_update_last_removed() implementation module is too old to update. Update to an intermediate version first (last removed version: 8002, installed version: 8000).');
     $assert_session->linkNotExists('Continue');
 
     // Set the expected schema version for the node and test module, updates are
diff --git a/core/tests/Drupal/Tests/UpdatePathTestTrait.php b/core/tests/Drupal/Tests/UpdatePathTestTrait.php
index 8c3fc723d504..421f7097f81b 100644
--- a/core/tests/Drupal/Tests/UpdatePathTestTrait.php
+++ b/core/tests/Drupal/Tests/UpdatePathTestTrait.php
@@ -58,7 +58,8 @@ protected function runUpdates($update_url = NULL) {
         $this->fail('The update failed with the following message: "' . reset($failure)->getText() . '"');
       }
 
-      // Ensure that there are no pending updates.
+      // Ensure that there are no pending updates. Clear the schema version
+      // static cache first in case it was accessed before running updates.
       drupal_get_installed_schema_version(NULL, TRUE);
       foreach (['update', 'post_update'] as $update_type) {
         switch ($update_type) {
-- 
GitLab