From 666434b89341e31cebd8e1a5fa57784d52ce49b5 Mon Sep 17 00:00:00 2001
From: lucashedding <lucashedding@1463982.no-reply.drupal.org>
Date: Mon, 15 Apr 2019 09:43:43 -0500
Subject: [PATCH] Issue #3046857 by heddn, eiriksm: Add entry to site status
 page when PSAs are posted

---
 automatic_updates.info.yml                    |  2 ++
 automatic_updates.install                     | 35 +++++++++++++++++++
 tests/src/Functional/AutomaticUpdatesTest.php |  7 ++++
 3 files changed, 44 insertions(+)
 create mode 100644 automatic_updates.install

diff --git a/automatic_updates.info.yml b/automatic_updates.info.yml
index 3bcad2cfac..5488d289eb 100644
--- a/automatic_updates.info.yml
+++ b/automatic_updates.info.yml
@@ -4,3 +4,5 @@ description: 'Drupal Automatic Updates'
 core: 8.x
 package: 'Security'
 configure: automatic_updates.admin_form
+dependencies:
+  - drupal:update
diff --git a/automatic_updates.install b/automatic_updates.install
new file mode 100644
index 0000000000..10f6b1155e
--- /dev/null
+++ b/automatic_updates.install
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * @file
+ * Automatic updates install file.
+ */
+
+use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
+
+/**
+ * Requirements checks for automatic updates.
+ */
+function automatic_updates_requirements() {
+  $requirements = [];
+  if (!\Drupal::config('automatic_updates.settings')->get('enable_psa')) {
+    return $requirements;
+  }
+  /** @var \Drupal\automatic_updates\Services\AutomaticUpdatesPsa $psa */
+  $psa = \Drupal::service('automatic_updates.psa');
+  $messages = $psa->getPublicServiceMessages();
+  $requirements['automatic_updates_psa'] = [
+    'title' => t('Drupal public service announcements'),
+    'severity' => REQUIREMENT_OK,
+    'value' => t('No announcements requiring attention.'),
+  ];
+  if (!empty($messages)) {
+    $requirements['automatic_updates_psa']['severity'] = REQUIREMENT_ERROR;
+    $requirements['automatic_updates_psa']['value'] = new PluralTranslatableMarkup(count($messages), '@count urgent announcement requiring your attention:', '@count urgent announcements requiring your attention:');
+    $requirements['automatic_updates_psa']['description'] = [
+      '#theme' => 'item_list',
+      '#items' => $messages,
+    ];
+  }
+  return $requirements;
+}
diff --git a/tests/src/Functional/AutomaticUpdatesTest.php b/tests/src/Functional/AutomaticUpdatesTest.php
index 807851dfcc..aa8ca8040f 100644
--- a/tests/src/Functional/AutomaticUpdatesTest.php
+++ b/tests/src/Functional/AutomaticUpdatesTest.php
@@ -20,6 +20,7 @@ class AutomaticUpdatesTest extends BrowserTestBase {
   public static $modules = [
     'automatic_updates',
     'test_automatic_updates',
+    'update',
   ];
 
   /**
@@ -56,6 +57,10 @@ class AutomaticUpdatesTest extends BrowserTestBase {
     $this->assertSession()->pageTextContains('Drupal Contrib Project PSA: Seven - Moderately critical - Access bypass - SA-CONTRIB-2019');
     $this->assertSession()->pageTextContains('Drupal Contrib Project PSA: Standard - Moderately critical - Access bypass - SA-CONTRIB-2019');
 
+    // Test site status report.
+    $this->drupalGet(Url::fromRoute('system.status'));
+    $this->assertSession()->pageTextContains('4 announcements requiring your attention:');
+
     // Test cache.
     $end_point = 'http://localhost/automatic_updates/test-json-denied';
     $this->config('automatic_updates.settings')
@@ -78,6 +83,8 @@ class AutomaticUpdatesTest extends BrowserTestBase {
     drupal_flush_all_caches();
     $this->drupalGet(Url::fromRoute('system.admin'));
     $this->assertSession()->pageTextNotContains('Drupal Core PSA: Critical Release - PSA-2019-02-19');
+    $this->drupalGet(Url::fromRoute('system.status'));
+    $this->assertSession()->pageTextNotContains('4 announcements requiring your attention:');
   }
 
 }
-- 
GitLab