From 3958ddc87b269d40cf9be995ab06bd5f4ace70c1 Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Fri, 2 May 2025 23:54:30 +0100
Subject: [PATCH] Issue #3513129 by quietone, longwave, mstrelan: Remove uses
 of FormattableMarkup in Functional test assertion messages

---
 .../src/Functional/ContentTranslationWorkflowsTest.php |  5 ++---
 .../file/tests/src/Functional/FileFieldTestBase.php    |  7 +++----
 core/modules/help/tests/src/Functional/HelpTest.php    |  3 +--
 .../tests/src/Functional/ShortcutLinksTest.php         |  7 +++----
 .../src/Functional/FilterEntityReferenceWebTest.php    | 10 +++-------
 5 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
index 63e67b7f351c..3034a3156948 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
@@ -4,7 +4,6 @@
 
 namespace Drupal\Tests\content_translation\Functional;
 
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\Core\Url;
 use Drupal\entity_test\Entity\EntityTestMulRevPub;
@@ -249,10 +248,10 @@ public function testWorkflows(): void {
 
       foreach ($ops as $op => $label) {
         if ($op != $current_op) {
-          $this->assertSession()->linkNotExists($label, new FormattableMarkup('No %op link found.', ['%op' => $label]));
+          $this->assertSession()->linkNotExists($label);
         }
         else {
-          $this->assertSession()->linkExists($label, 0, new FormattableMarkup('%op link found.', ['%op' => $label]));
+          $this->assertSession()->linkExists($label, 0);
         }
       }
     }
diff --git a/core/modules/file/tests/src/Functional/FileFieldTestBase.php b/core/modules/file/tests/src/Functional/FileFieldTestBase.php
index bb321bb13757..702a35f0e4b2 100644
--- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php
+++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php
@@ -4,7 +4,6 @@
 
 namespace Drupal\Tests\file\Functional;
 
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\field\Entity\FieldConfig;
 use Drupal\file\FileInterface;
@@ -222,7 +221,7 @@ public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE)
   public function assertFileEntryExists($file, $message = NULL) {
     $this->container->get('entity_type.manager')->getStorage('file')->resetCache();
     $db_file = File::load($file->id());
-    $message = $message ?? new FormattableMarkup('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]);
+    $message = $message ?? sprintf('File %s exists in database at the correct path.', $file->getFileUri());
     $this->assertEquals($file->getFileUri(), $db_file->getFileUri(), $message);
   }
 
@@ -231,7 +230,7 @@ public function assertFileEntryExists($file, $message = NULL) {
    */
   public function assertFileEntryNotExists($file, $message) {
     $this->container->get('entity_type.manager')->getStorage('file')->resetCache();
-    $message = $message ?? new FormattableMarkup('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]);
+    $message = $message ?? sprintf('File %s exists in database at the correct path.', $file->getFileUri());
     $this->assertNull(File::load($file->id()), $message);
   }
 
@@ -239,7 +238,7 @@ public function assertFileEntryNotExists($file, $message) {
    * Asserts that a file's status is set to permanent in the database.
    */
   public function assertFileIsPermanent(FileInterface $file, $message = NULL) {
-    $message = $message ?? new FormattableMarkup('File %file is permanent.', ['%file' => $file->getFileUri()]);
+    $message = $message ?? sprintf('File %s is permanent.', $file->getFileUri());
     $this->assertTrue($file->isPermanent(), $message);
   }
 
diff --git a/core/modules/help/tests/src/Functional/HelpTest.php b/core/modules/help/tests/src/Functional/HelpTest.php
index 3a954ac0eadd..920179bca8ad 100644
--- a/core/modules/help/tests/src/Functional/HelpTest.php
+++ b/core/modules/help/tests/src/Functional/HelpTest.php
@@ -4,7 +4,6 @@
 
 namespace Drupal\Tests\help\Functional;
 
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Tests\BrowserTestBase;
 
 /**
@@ -99,7 +98,7 @@ public function testHelp(): void {
 
     // Make sure links are properly added for modules implementing hook_help().
     foreach ($this->getModuleList() as $module => $name) {
-      $this->assertSession()->linkExists($name, 0, new FormattableMarkup('Link properly added to @name (admin/help/@module)', ['@module' => $module, '@name' => $name]));
+      $this->assertSession()->linkExists($name, 0, "Link properly added to $name (admin/help/$module)");
     }
 
     // Ensure a module which does not provide a module overview page is handled
diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
index 10c1d269da7f..5ae0466a6505 100644
--- a/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
@@ -5,7 +5,6 @@
 namespace Drupal\Tests\shortcut\Functional;
 
 use Drupal\block_content\Entity\BlockContentType;
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Url;
 use Drupal\shortcut\Entity\Shortcut;
 use Drupal\shortcut\Entity\ShortcutSet;
@@ -109,10 +108,10 @@ public function testShortcutLinkAdd(): void {
       $this->assertContains('internal:' . $test_path, $paths, 'Shortcut created: ' . $test_path);
 
       if (in_array($test_path, $test_cases_non_access)) {
-        $this->assertSession()->linkNotExists($title, new FormattableMarkup('Shortcut link %url not accessible on the page.', ['%url' => $test_path]));
+        $this->assertSession()->linkNotExists($title, "Shortcut link $test_path not accessible on the page.");
       }
       else {
-        $this->assertSession()->linkExists($title, 0, new FormattableMarkup('Shortcut link %url found on the page.', ['%url' => $test_path]));
+        $this->assertSession()->linkExists($title, 0, "Shortcut link $test_path found on the page.");
       }
     }
     $saved_set = ShortcutSet::load($set->id());
@@ -486,7 +485,7 @@ public function testShortcutBlockAccess(): void {
    */
   protected function assertShortcutQuickLink(string $label, int $index = 0, string $message = ''): void {
     $links = $this->xpath('//a[normalize-space()=:label]', [':label' => $label]);
-    $message = ($message ?: (string) new FormattableMarkup('Shortcut quick link with label %label found.', ['%label' => $label]));
+    $message = ($message ?: "Shortcut quick link with label $label found.");
     $this->assertArrayHasKey($index, $links, $message);
   }
 
diff --git a/core/modules/views_ui/tests/src/Functional/FilterEntityReferenceWebTest.php b/core/modules/views_ui/tests/src/Functional/FilterEntityReferenceWebTest.php
index 2cfc383f5c77..863ea9dfdf6a 100644
--- a/core/modules/views_ui/tests/src/Functional/FilterEntityReferenceWebTest.php
+++ b/core/modules/views_ui/tests/src/Functional/FilterEntityReferenceWebTest.php
@@ -4,7 +4,6 @@
 
 namespace Drupal\Tests\views_ui\Functional;
 
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Tests\views_ui\Traits\FilterEntityReferenceTrait;
 
@@ -60,8 +59,7 @@ public function testFilterUi(): void {
     });
     $i = 0;
     foreach ($this->targetEntities as $entity) {
-      $message = (string) new FormattableMarkup('Expected target entity label found for option :option', [':option' => $i]);
-      $this->assertEquals($options[$i]['label'], $entity->label(), $message);
+      $this->assertEquals($options[$i]['label'], $entity->label(), "Expected target entity label found for option $i");
       $i++;
     }
 
@@ -79,8 +77,7 @@ public function testFilterUi(): void {
     $options = $this->getUiOptions();
     $i = 0;
     foreach ($this->targetEntities as $entity) {
-      $message = (string) new FormattableMarkup('Expected target entity label found for option :option', [':option' => $i]);
-      $this->assertEquals($options[$i]['label'], $entity->label(), $message);
+      $this->assertEquals($options[$i]['label'], $entity->label(), "Expected target entity label found for option $i");
       $i++;
     }
 
@@ -96,8 +93,7 @@ public function testFilterUi(): void {
     $options = $this->getUiOptions();
     $i = 0;
     foreach ($this->hostEntities + $this->targetEntities as $entity) {
-      $message = (string) new FormattableMarkup('Expected target entity label found for option :option', [':option' => $i]);
-      $this->assertEquals($options[$i]['label'], $entity->label(), $message);
+      $this->assertEquals($options[$i]['label'], $entity->label(), "Expected target entity label found for option $i");
       $i++;
     }
   }
-- 
GitLab