From 2d6ae27e2fba7ff02df163e78c98d309d97ad4dd Mon Sep 17 00:00:00 2001
From: Lauri Eskola <lauri.eskola@acquia.com>
Date: Fri, 17 Mar 2023 11:29:16 +0200
Subject: [PATCH] Issue #2869868 by AaronBauman, immaculatexavier, smustgrave:
 Requirements errors in "General System Information" are not visually apparent

---
 .../system/src/Element/StatusReportPage.php   |  4 +-
 .../src/Functional/System/StatusTest.php      | 43 ++++++++++++++++++-
 2 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/core/modules/system/src/Element/StatusReportPage.php b/core/modules/system/src/Element/StatusReportPage.php
index a70c67fabb2c..79111ae30572 100644
--- a/core/modules/system/src/Element/StatusReportPage.php
+++ b/core/modules/system/src/Element/StatusReportPage.php
@@ -59,7 +59,9 @@ public static function preRenderGeneralInfo($element) {
         case 'php_memory_limit':
           $element['#general_info']['#' . $key] = $requirement;
           if (isset($requirement['severity']) && $requirement['severity'] < REQUIREMENT_WARNING) {
-            unset($element['#requirements'][$key]);
+            if (empty($requirement['severity']) || $requirement['severity'] == REQUIREMENT_OK) {
+              unset($element['#requirements'][$key]);
+            }
           }
           break;
       }
diff --git a/core/modules/system/tests/src/Functional/System/StatusTest.php b/core/modules/system/tests/src/Functional/System/StatusTest.php
index 0c9b123f060c..4347d13a36c0 100644
--- a/core/modules/system/tests/src/Functional/System/StatusTest.php
+++ b/core/modules/system/tests/src/Functional/System/StatusTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Url;
 use Drupal\Tests\BrowserTestBase;
+use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
 
 /**
  * Tests output on the status overview page.
@@ -92,7 +93,7 @@ public function testStatusPage() {
     $this->drupalGet('admin/reports/status/php');
     $this->assertSession()->statusCodeEquals(200);
 
-    // Check if cron error is displayed in errors section
+    // Check if cron error is displayed in errors section.
     $cron_last_run = \Drupal::state()->get('system.cron_last');
     \Drupal::state()->set('system.cron_last', 0);
     $this->drupalGet('admin/reports/status');
@@ -175,4 +176,44 @@ public function testStatusPage() {
     }
   }
 
+  /**
+   * Tests that the Error counter matches the displayed number of errors.
+   */
+  public function testErrorElementCount() {
+    // Trigger "cron has not run recently" error:
+    $cron_config = \Drupal::config('system.cron');
+    $time = \Drupal::time()->getRequestTime();
+    \Drupal::state()->set('install_time', $time);
+    $threshold_error = $cron_config->get('threshold.requirements_error');
+    \Drupal::state()->set('system.cron_last', $time - $threshold_error - 1);
+
+    $this->drupalGet('admin/reports/status');
+
+    $error_elements = $this->cssSelect('.system-status-report__status-icon--error');
+    $this->assertNotEquals(count($error_elements), 0, 'Errors are listed on the page.');
+    $expected_text = new PluralTranslatableMarkup(count($error_elements), 'Error', 'Errors');
+    $expected_text = count($error_elements) . ' ' . $expected_text;
+    $this->assertSession()->responseContains((string) $expected_text);
+  }
+
+  /**
+   * Tests that the Warning counter matches the displayed number of warnings.
+   */
+  public function testWarningElementCount() {
+    // Trigger "cron has not run recently" with warning threshold:
+    $cron_config = \Drupal::config('system.cron');
+    $time = \Drupal::time()->getRequestTime();
+    \Drupal::state()->set('install_time', $time);
+    $threshold_warning = $cron_config->get('threshold.requirements_warning');
+    \Drupal::state()->set('system.cron_last', $time - $threshold_warning - 1);
+
+    $this->drupalGet('admin/reports/status');
+
+    $warning_elements = $this->cssSelect('.system-status-report__status-icon--warning');
+    $this->assertNotEquals(count($warning_elements), 0, 'Warnings are listed on the page.');
+    $expected_text = new PluralTranslatableMarkup(count($warning_elements), 'Warning', 'Warnings');
+    $expected_text = count($warning_elements) . ' ' . $expected_text;
+    $this->assertSession()->responseContains((string) $expected_text);
+  }
+
 }
-- 
GitLab