From bcfecbbfa62bac8e773f6b1dc04608cac8e28357 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 5 Aug 2021 09:19:46 +0100
Subject: [PATCH] Issue #3131900 by mondrake, longwave, xjm, alexpott: Refactor
 assertions that assign return values to variables

---
 .../Cache/AssertPageCacheContextsAndTagsTrait.php      |  4 ++--
 .../tests/src/Functional/Session/SessionTest.php       |  3 +--
 .../tests/src/Functional/ToolbarCacheContextsTest.php  | 10 ++--------
 .../tests/src/Functional/Plugin/DisplayPageWebTest.php |  7 ++-----
 4 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php b/core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php
index 4a6d851b4c19..dc375371a8e8 100644
--- a/core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php
+++ b/core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php
@@ -125,7 +125,7 @@ protected function assertCacheTags(array $expected_tags, $include_default_tags =
    *   (optional) Whether the default contexts should automatically be included.
    *
    * @return bool
-   *   TRUE if the assertion succeeded, FALSE otherwise.
+   *   Always returns TRUE.
    */
   protected function assertCacheContexts(array $expected_contexts, $message = NULL, $include_default_contexts = TRUE) {
     if ($include_default_contexts) {
@@ -142,7 +142,7 @@ protected function assertCacheContexts(array $expected_contexts, $message = NULL
     sort($expected_contexts);
     sort($actual_contexts);
     $this->assertSame($expected_contexts, $actual_contexts, $message ?? '');
-    return $actual_contexts === $expected_contexts;
+    return TRUE;
   }
 
   /**
diff --git a/core/modules/system/tests/src/Functional/Session/SessionTest.php b/core/modules/system/tests/src/Functional/Session/SessionTest.php
index acb5321b00a1..bd2b924f41f1 100644
--- a/core/modules/system/tests/src/Functional/Session/SessionTest.php
+++ b/core/modules/system/tests/src/Functional/Session/SessionTest.php
@@ -72,8 +72,7 @@ public function testSessionSaveRegenerate() {
     $this->drupalGet('user/login');
     $this->submitForm($edit, 'Log in');
     $this->drupalGet('user');
-    $pass = $this->assertSession()->pageTextContains($user->getAccountName());
-    $this->_logged_in = $pass;
+    $this->assertSession()->pageTextContains($user->getAccountName());
 
     $this->drupalGet('session-test/id');
     $matches = [];
diff --git a/core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php b/core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php
index e6698f74a5a8..5de4c2d8b62d 100644
--- a/core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php
+++ b/core/modules/toolbar/tests/src/Functional/ToolbarCacheContextsTest.php
@@ -107,9 +107,6 @@ public function testToolbarCacheContextsCaller() {
    *   Expected cache contexts for both users.
    * @param string $message
    *   (optional) A verbose message to output.
-   *
-   * @return
-   *   TRUE if the assertion succeeded, FALSE otherwise.
    */
   protected function assertToolbarCacheContexts(array $cache_contexts, $message = NULL) {
     // Default cache contexts that should exist on all test cases.
@@ -123,16 +120,13 @@ protected function assertToolbarCacheContexts(array $cache_contexts, $message =
     // Assert contexts for user1 which has only default permissions.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('test-page');
-    $return = $this->assertCacheContexts($cache_contexts);
+    $this->assertCacheContexts($cache_contexts, $message);
     $this->drupalLogout();
 
     // Assert contexts for user2 which has some additional permissions.
     $this->drupalLogin($this->adminUser2);
     $this->drupalGet('test-page');
-    $return = $return && $this->assertCacheContexts($cache_contexts);
-
-    $this->assertTrue($return, $message);
-    return $return;
+    $this->assertCacheContexts($cache_contexts, $message);
   }
 
   /**
diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php
index 7d27e584428d..d8e86e5692f7 100644
--- a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php
@@ -160,9 +160,6 @@ public function testPagePaths() {
    *
    * @param string $path
    *   Path that will be set as the view page display path.
-   *
-   * @return bool
-   *   Assertion result.
    */
   public function assertPagePath($path) {
     $view = Views::getView('test_page_display_path');
@@ -172,10 +169,10 @@ public function assertPagePath($path) {
     $this->container->get('router.builder')->rebuild();
     // Check if we successfully changed the path.
     $this->drupalGet($path);
-    $success = $this->assertSession()->statusCodeEquals(200);
+    $this->assertSession()->statusCodeEquals(200);
     // Check if we don't get any error on the view edit page.
     $this->drupalGet('admin/structure/views/view/test_page_display_path');
-    return $success && $this->assertSession()->statusCodeEquals(200);
+    $this->assertSession()->statusCodeEquals(200);
   }
 
 }
-- 
GitLab