From b566c9859a1b1d062c45d174ba1a7cc724e9bf79 Mon Sep 17 00:00:00 2001
From: "kunal.sachdev" <kunal.sachdev@3685163.no-reply.drupal.org>
Date: Mon, 1 Aug 2022 14:29:32 +0000
Subject: [PATCH] Issue #3300006 by kunal.sachdev: Assert exactly which updates
 are shown on form in
 automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php

---
 .../tests/src/Functional/UpdaterFormTest.php           |  8 +++++++-
 .../tests/src/Traits/FormTestTrait.php                 | 10 ++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php
index a621711ae6..c37a5a5d73 100644
--- a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php
+++ b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php
@@ -176,9 +176,11 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
       $installed_version,
       $target_version
     );
+    $assert_session = $this->assertSession();
+    $this->assertUpdatesCount(1);
+
     // Submit without selecting a project.
     $page->pressButton('Update');
-    $assert_session = $this->assertSession();
     $assert_session->pageTextContains('Please select one or more projects.');
 
     // Submit with a project selected.
@@ -238,6 +240,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     $this->drupalGet('admin/reports/updates/automatic-update-extensions');
     $assert->pageTextContains('Other updates were found, but they must be performed manually. See the list of available updates for more information.');
     $this->assertTableShowsUpdates('Semver Test', '8.1.0', '8.1.1');
+    $this->assertUpdatesCount(1);
 
     // Both of the modules not installed through composer.
     $fixture_dir = __DIR__ . '/../../fixtures/no_project';
@@ -265,6 +268,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     $this->drupalLogin($user);
     $this->checkForUpdates();
     $this->assertTableShowsUpdates('Semver Test', '8.1.0', '8.1.1');
+    $this->assertUpdatesCount(1);
     $assert->pageTextContains('Automatic Updates Form');
     $assert->buttonExists('Update');
   }
@@ -309,6 +313,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     $this->checkForUpdates();
     $this->drupalGet('admin/reports/updates/automatic-update-extensions');
     $this->assertTableShowsUpdates('Semver Test', '8.1.0', '8.1.1');
+    $this->assertUpdatesCount(1);
     $message = t("You've not experienced Shakespeare until you have read him in the original Klingon.");
     $error = ValidationResult::createError([$message]);
     TestSubscriber1::setTestResult([$error], ReadinessCheckEvent::class);
@@ -334,6 +339,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     $this->drupalGet('/admin/reports/updates');
     $this->clickLink('Update Extensions');
     $this->assertTableShowsUpdates('Semver Test', '8.1.0', '8.1.1');
+    $this->assertUpdatesCount(1);
     $assert->pageTextContains(static::$warningsExplanation);
     $assert->pageTextNotContains(static::$errorsExplanation);
     $assert->buttonExists('Update');
diff --git a/automatic_updates_extensions/tests/src/Traits/FormTestTrait.php b/automatic_updates_extensions/tests/src/Traits/FormTestTrait.php
index 3b12fa8c95..4dfa5b0bfe 100644
--- a/automatic_updates_extensions/tests/src/Traits/FormTestTrait.php
+++ b/automatic_updates_extensions/tests/src/Traits/FormTestTrait.php
@@ -30,4 +30,14 @@ trait FormTestTrait {
     $assert->elementTextContains('css', $row_selector . ' td:nth-of-type(4)', $expected_target_version);
   }
 
+  /**
+   * Asserts the table shows the expected number of updates.
+   *
+   * @param int $expected_update_count
+   *   The no of rows in table.
+   */
+  private function assertUpdatesCount(int $expected_update_count): void {
+    $this->assertSession()->elementsCount('css', '.update-recommended tbody tr', $expected_update_count);
+  }
+
 }
-- 
GitLab