From b63ce8e2201c3e13826d39792f48e780b4d2f14a Mon Sep 17 00:00:00 2001 From: Liam Morland <liam@openplus.ca> Date: Tue, 27 Aug 2024 20:50:08 -0400 Subject: [PATCH] Issue #3466008: Avoid sending FormattableMarkup as test error message --- .../src/Functional/FillPdfUploadTestBase.php | 21 +++++++++++++++---- .../Functional/HandlePdfControllerTest.php | 8 ++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/src/Functional/FillPdfUploadTestBase.php b/tests/src/Functional/FillPdfUploadTestBase.php index 2553e56..9530689 100644 --- a/tests/src/Functional/FillPdfUploadTestBase.php +++ b/tests/src/Functional/FillPdfUploadTestBase.php @@ -131,9 +131,12 @@ abstract class FillPdfUploadTestBase extends FillPdfTestBase { // removed both from the disk and the database. $this->submitForm([], self::OP_REMOVE); $this->assertFileDoesNotExist($new_file->getFileUri()); - // @todo Simplify once Core bug gets fixed. + // @todo Remove $message when resolved: // @see https://www.drupal.org/project/drupal/issues/3043127 - $this->assertFileEntryNotExists($new_file, NULL); + $message = (string) new FormattableMarkup('File %file exists in database at the correct path.', [ + '%file' => $new_file->getFileUri(), + ]); + $this->assertFileEntryNotExists($new_file, $message); break; case self::OP_CREATE: @@ -150,7 +153,12 @@ abstract class FillPdfUploadTestBase extends FillPdfTestBase { $this->assertSession()->elementsCount('css', 'tbody > tr', 4); // Make sure the file is permanent and correctly placed. - $this->assertFileIsPermanent($new_file); + // @todo Remove $message when resolved: + // @see https://www.drupal.org/project/drupal/issues/3043127 + $message = (string) new FormattableMarkup('File %file is permanent.', [ + '%file' => $new_file->getFileUri(), + ]); + $this->assertFileIsPermanent($new_file, $message); $expected_file_uri = FillPdf::buildFileUri($this->config('fillpdf.settings')->get('template_scheme'), "fillpdf/{$new_filename}"); $this->assertEquals($new_file->getFileUri(), $expected_file_uri); break; @@ -161,7 +169,12 @@ abstract class FillPdfUploadTestBase extends FillPdfTestBase { $this->assertSession()->pageTextContains('Your previous field mappings have been transferred to the new PDF template you uploaded.'); // Make sure the file is permanent and correctly placed. - $this->assertFileIsPermanent($new_file); + // @todo Remove $message when resolved: + // @see https://www.drupal.org/project/drupal/issues/3043127 + $message = (string) new FormattableMarkup('File %file is permanent.', [ + '%file' => $new_file->getFileUri(), + ]); + $this->assertFileIsPermanent($new_file, $message); $expected_file_uri = FillPdf::buildFileUri($this->config('fillpdf.settings')->get('template_scheme'), "fillpdf/{$new_filename}"); $this->assertEquals($new_file->getFileUri(), $expected_file_uri); diff --git a/tests/src/Functional/HandlePdfControllerTest.php b/tests/src/Functional/HandlePdfControllerTest.php index ccdf5bb..9e3b708 100644 --- a/tests/src/Functional/HandlePdfControllerTest.php +++ b/tests/src/Functional/HandlePdfControllerTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\fillpdf\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\file\Entity\File; use Symfony\Component\HttpFoundation\ResponseHeaderBag; @@ -213,7 +214,12 @@ class HandlePdfControllerTest extends FillPdfUploadTestBase { $this->assertEquals("public://fillpdf/{$expected}/{$expected}.pdf", $uri, "Test case $id: The file has the expected URI."); // Check if file is permanent and has the right format. - $this->assertFileIsPermanent($file); + // @todo Remove $message when resolved: + // @see https://www.drupal.org/project/drupal/issues/3043127 + $message = (string) new FormattableMarkup('File %file is permanent.', [ + '%file' => $file->getFileUri(), + ]); + $this->assertFileIsPermanent($file, $message); $this->drupalGet(\Drupal::service('file_url_generator')->generateAbsoluteString($uri)); $maybe_pdf = $this->getSession()->getPage()->getContent(); static::assertEquals('application/pdf', $this->getMimeType($maybe_pdf), "Test case $id: The file has the correct MIME type."); -- GitLab