From 650ea8745eaaa65ab0785011ad03750e952c2f7e Mon Sep 17 00:00:00 2001
From: tedbow <tedbow@240860.no-reply.drupal.org>
Date: Tue, 21 Sep 2021 19:39:03 +0000
Subject: [PATCH] Issue #3236405 by tedbow: After update old message about
 security update is still displayed

---
 .../automatic_updates_9_3_shim.module         | 43 +++++++++++++++++++
 tests/fixtures/release-history/drupal.0.0.xml |  2 +
 tests/src/Build/CoreUpdateTest.php            |  7 ++-
 tests/src/Functional/UpdaterFormTest.php      |  6 ++-
 4 files changed, 54 insertions(+), 4 deletions(-)
 create mode 100644 automatic_updates_9_3_shim/automatic_updates_9_3_shim.module

diff --git a/automatic_updates_9_3_shim/automatic_updates_9_3_shim.module b/automatic_updates_9_3_shim/automatic_updates_9_3_shim.module
new file mode 100644
index 0000000000..0734d6dafa
--- /dev/null
+++ b/automatic_updates_9_3_shim/automatic_updates_9_3_shim.module
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @file
+ * Contains hook implementations for Automatic Updates 9.3 shim module.
+ */
+
+/**
+ * Implements hook_page_top().
+ */
+function automatic_updates_9_3_shim_page_top() {
+  // @todo Rely on the route option after https://www.drupal.org/i/3236497 is
+  //   committed.
+  // @todo Remove 'system.batch_page.html' after
+  //   https://www.drupal.org/i/3238311 is committed.
+  $skip_routes = [
+    'system.batch_page.html',
+    'automatic_updates.confirmation_page',
+    'automatic_updates.report_update',
+    'automatic_updates.module_update',
+  ];
+  $route_name = \Drupal::routeMatch()->getRouteName();
+  if (!in_array($route_name, $skip_routes, TRUE) && function_exists('update_page_top')) {
+    update_page_top();
+  }
+}
+
+/**
+ * Implements hook_module_implements_alter().
+ *
+ * @todo Remove after https://www.drupal.org/i/3236497 is committed.
+ */
+function automatic_updates_9_3_shim_module_implements_alter(&$implementations, $hook) {
+  if ($hook === 'page_top') {
+    // Remove hook_page_top() implementation from the Update module. This '
+    // implementation displays error messages about security releases. We call
+    // this implementation in our own automatic_updates_page_top() except on our
+    // own routes to avoid stale messages about the security releases after an
+    // update.
+    unset($implementations['update']);
+  }
+
+}
diff --git a/tests/fixtures/release-history/drupal.0.0.xml b/tests/fixtures/release-history/drupal.0.0.xml
index 4d5268378e..dbcb825a86 100644
--- a/tests/fixtures/release-history/drupal.0.0.xml
+++ b/tests/fixtures/release-history/drupal.0.0.xml
@@ -20,6 +20,7 @@
   <terms>
     <term><name>Release type</name><value>New features</value></term>
     <term><name>Release type</name><value>Bug fixes</value></term>
+    <term><name>Release type</name><value>Security update</value></term>
   </terms>
  </release>
  <release>
@@ -32,6 +33,7 @@
    <terms>
      <term><name>Release type</name><value>New features</value></term>
      <term><name>Release type</name><value>Bug fixes</value></term>
+     <term><name>Release type</name><value>Insecure</value></term>
    </terms>
  </release>
 </releases>
diff --git a/tests/src/Build/CoreUpdateTest.php b/tests/src/Build/CoreUpdateTest.php
index 763d554682..78612ad577 100644
--- a/tests/src/Build/CoreUpdateTest.php
+++ b/tests/src/Build/CoreUpdateTest.php
@@ -118,14 +118,17 @@ class CoreUpdateTest extends UpdateTestBase {
     $mink = $this->getMink();
     $page = $mink->getSession()->getPage();
     $assert_session = $mink->assertSession();
-
-    $this->visit('/admin/modules/automatic-update');
+    $this->visit('/admin/modules');
+    $assert_session->pageTextContains('There is a security update available for your version of Drupal.');
+    $page->clickLink('Automatic Updates');
+    $assert_session->pageTextNotContains('There is a security update available for your version of Drupal.');
     $page->pressButton('Download these updates');
     $this->waitForBatchJob();
     $assert_session->pageTextContains('Ready to update');
     $page->pressButton('Continue');
     $this->waitForBatchJob();
     $assert_session->pageTextContains('Update complete!');
+    $assert_session->pageTextNotContains('There is a security update available for your version of Drupal.');
     $this->assertUpdateSuccessful();
   }
 
diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php
index a28216cc80..73e0d983b1 100644
--- a/tests/src/Functional/UpdaterFormTest.php
+++ b/tests/src/Functional/UpdaterFormTest.php
@@ -89,18 +89,20 @@ class UpdaterFormTest extends BrowserTestBase {
     $this->drupalPlaceBlock('local_tasks_block', ['primary' => TRUE]);
     $assert_session = $this->assertSession();
     $this->setCoreVersion('9.8.0');
-
     $this->drupalLogin($this->rootUser);
+    $this->checkForUpdates();
 
     // Navigate to the automatic updates form.
     $this->drupalGet('/admin');
     // @todo Add test coverage of accessing the form via the other path in
     //   https://www.drupal.org/i/3233564
     $this->clickLink('Extend');
+    $assert_session->pageTextContainsOnce('There is a security update available for your version of Drupal.');
     $this->clickLink('Update');
     $assert_session->pageTextContainsOnce('Drupal core updates are supported by the enabled Automatic Updates module');
     $this->clickLink('Automatic Updates module');
-    $cells = $assert_session->elementExists('css', '#edit-projects .update-recommended')
+    $assert_session->pageTextNotContains('There is a security update available for your version of Drupal.');
+    $cells = $assert_session->elementExists('css', '#edit-projects .update-update-security')
       ->findAll('css', 'td');
     $this->assertCount(3, $cells);
     $assert_session->elementExists('named', ['link', 'Drupal'], $cells[0]);
-- 
GitLab