Problem/Motivation

Follow-up to #2527360: Review all usages of Xss::filter(), Xss::filterAdmin(), and Html::escape()

This was originally about only using SafeMarkup::format() and format_string in tests only when testing those methods. SafeMarkup::format() was deprecated in Drupal 8 and replaced with FormattableMarkup::format() and format_string() was also deprecated in favor of FormattableMarkup in tests apart from explicit tests of those methods

So, this is now about ensuring that FormattableMarkup is only used in tests when testing that API.

SafeMarkup::format() and format_string() in tests apart from explicit tests of those methods

We're using SafeMarkup::format in tests. We should not as this pollutes the safe string list and is irrelevant.

Where we are using it in $this->assertRaw() we should just convert it to a string. Where we are using it in an assertion message we should just convert it to a string with the variables inserted like "This is a $lol test".

Steps to reproduce

git grep FormattableMarkup | grep -i tests | awk -F: '{print $1}' | sort -u | grep -v UserHooksTest | grep -v FormattableMarkupKernelTest | grep -v MarkupInterfaceComparatorTest | grep -v TwigMarkupInterfaceTest.php | grep -v FormattableMarkupTest.php | grep -v PlainTextOutputTest.php | grep -v TranslatableMarkupTest.php

This excludes these tests, which test the API itself.

  1. core/modules/user/tests/modules/user_hooks_test/src/Hook/UserHooksTest.php
  2. core/tests/Drupal/KernelTests/Component/Render/FormattableMarkupKernelTest.php
  3. core/tests/Drupal/KernelTests/Core/Test/Comparator/MarkupInterfaceComparatorTest.php
  4. core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php
  5. core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php
  6. core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php
  7. core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php

Also, no changed needed for these
In comment or string array key

  • core/tests/Drupal/KernelTests/AssertContentTrait.php
  • core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php
  • core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php
  • core/tests/Drupal/Tests/WebAssert.php

Proposed resolution

Remove usages in child issue.

Remaining tasks

#3569421: Remove remaining unnecessary uses of Formattable markup in tests

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-2549805

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

xjm’s picture

Title: Remove all usage of SafeMarkup::format and format_string in tests apart from explicit tests of those methods » Remove all usage of SafeMarkup::format() and format_string() in tests apart from explicit tests of those methods
alexpott’s picture

      $text = SafeMarkup::format('<b>‹</b> @label', array('@label' => $previous->label()));
      $this->assertRaw(\Drupal::l($text, $url), 'Previous page link found.');

So how would be convert this? From BookTest.php

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new1.76 KB

A couple of example conversions. Placeholders are going to be annoying.

geertvd’s picture

StatusFileSize
new130.53 KB

Just posting my progress, curious if I missed any placeholders.
This is still unfinished.

Status: Needs review » Needs work

The last submitted patch, 5: 2549805-5.patch, failed testing.

geertvd’s picture

Status: Needs work » Needs review
StatusFileSize
new4.85 KB
new131.8 KB

This should fix the test fails for now.
Still a work in progress, anyone feel free to work on this, I'll assign myself when i'm doing so.

geertvd’s picture

So how would be convert this? From BookTest.php

+++ b/core/modules/book/src/Tests/BookTest.php
@@ -266,8 +265,9 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F
-      $text = "<b>‹</b> {$previous->label()}";
-      $this->assertRaw(\Drupal::l($text, $url), 'Previous page link found.');
+      $unrendered_text = ['#markup' => '<b>‹</b> ' . $previous->label()];
+      $rendered_text = \Drupal::service('renderer')->renderRoot($unrendered_text);
+      $this->assertRaw(\Drupal::l($rendered_text, $url), 'Previous page link found.');

@alexpott, i fixed that like this, does that seem acceptable?

lauriii queued 7: 2549805-7.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 7: 2549805-7.patch, failed testing.

joelpittet’s picture

Issue tags: +Needs reroll

Looks like it needs a re-roll.

lokapujya’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new125.85 KB

Rerolled.

lokapujya’s picture

@@ -166,21 +166,21 @@ protected function doTestMultilingualProperties($entity_type) {
+    $this->assertEqual($default_langcode, $field->getLangcode(), "$entity_type: The field object has the expect langcode.");

s/expect/expected/g

Tempted to fix this here. Is it allowed or out of scope?

Status: Needs review » Needs work

The last submitted patch, 12: 2549805-12.patch, failed testing.

joelpittet’s picture

In scope imo. It's in a changed hunk so won't effect other patches more than what we are changing.

geertvd’s picture

Just pointing out that there still are a lot of occurrences of SafeMarkup::format() and format_string() that need replacing. My patch in #7 was just a work in progress.

joelpittet’s picture

Issue tags: +rc eligible

Since this is improving only tests. this can be done during RC. https://www.drupal.org/core/d8-allowed-changes#rc

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new134.29 KB
new15.23 KB

Fixed errors, fixed typos mentioned in #13, and removed a few more usages.

Status: Needs review » Needs work

The last submitted patch, 18: 2549805-18.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
StatusFileSize
new134.31 KB
new3.56 KB

Fix some mistakes that I added in #18.

lokapujya’s picture

1.) Some of these strings are displayed in the browser when viewing test results. Why wouldn't those messages need to use SafeMarkup? Are they getting escaped later? I think they are auto-escpaped, but just making sure.
2.) Maybe we can split this issue up since there are over 100 instances.

duaelfr’s picture

Thank you very mush @lokapujya!

To anwser your questions I think that variables in tests can be considered as safe as they are never taken from user inputs. Even if one of these variables were not safe, tests are not likely run from the UI on a production server so there would be no impact to an XSS injection in the tests results.

About the size of this patch I think that core maintainers would like to have some smaller changes to review but I don't know how they'd like them to be splitted. One should ask them what they prefer.

Finally, I have a remark about some changes introduced by your patch. For example in:

+++ b/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php
@@ -66,7 +64,7 @@ public function testBlockLinks() {
-    $this->assert(isset($links[0]), format_string('Link to href %href found.', array('%href' => $href)));
+    $this->assert(isset($links[0]), "Link to href $href found.");

The fact is that %href get transformed in something like <em>$href</em>. So, your patch make us loose something. As <em>something</em> is painful while reading tests results in command line, I'd suggest to add double quotes around the variable to keep the value separated from the other part of the message:

"Link to href \"$href\" found."
lokapujya’s picture

Thanks for reviewing!

The fact is that %href get transformed in something like $href. So, your patch make us loose something.

Good point. Maybe the <em> is important for messages?

As <em>something</em> is painful while reading tests results in command line

I don't know if we should worry about this part. One could argue that is command line's problem. Command line could eventually support interpreting <em> tag.

mpdonadio’s picture

Why don't we add a trait onto WebTestbase for a ::format() method that essentially does the same thing, but w/o the safe string handling? That should allow for nearly one-to-one replacement in tests?

duaelfr’s picture

@mpdonadio I like your idea. Ready to provide a patch? :)

mpdonadio’s picture

Assigned: Unassigned » mpdonadio

Sure. Probably not tomorrow, but I'll have something ready on Monday or Tuesday.

xjm’s picture

So the current patch is changing both assertions themselves, and assertion messages. These are two separate scopes actually and I think we should split them into two separate issues. The former (removing it from non-messages) is important to make sure our tests are testing the right thing. The latter (removing format_string() from assertion messages) does not affect the integrity of the test and is a separate discussion. At first @alexpott had suggested doing so, but then said once "actually SimpleTest result display sanitization works differently than I thought" and so said it would need to be considered more carefully. There may be a different issue for that somewhere.

Also, I'm not actually in favor of adding additional assertion methods for the string formatting.

Finally, we should actually consider first off which of these assertion messages are unneeded. Often with an assertText() or assertRaw() the custom assertion message is not actually adding any additional information.

So my suggestion would be:

  1. One patch (this issue) that removes any format_string() and friends that are not on the message parameter.
  2. Take what's left over, and look at what messages are simply redundant that also use format_string(), and just remove the parameter so only the default message is used.
  3. Take what's left over from this patch after that, and then look into whether the message needs to be sanitized or not for output.
lokapujya’s picture

StatusFileSize
new19.38 KB
new112.13 KB

reroll + beginning #27-1. So, this only includes what we already discovered in the previous patch. Many more may have been added.

Status: Needs review » Needs work

The last submitted patch, 28: 2549805-28.patch, failed testing.

lokapujya’s picture

Assigned: mpdonadio » Unassigned
Status: Needs work » Needs review
StatusFileSize
new553 bytes
new19.12 KB
lokapujya’s picture

StatusFileSize
new34.35 KB
new15.7 KB

I think I've identified all of them. Left some as @todos. Do we still want to do this? If so, then if anyone wants to finish it off, go ahead.

Status: Needs review » Needs work

The last submitted patch, 31: 2549805-31.patch, failed testing.

lokapujya’s picture

+++ b/core/modules/contact/src/Tests/ContactSitewideTest.php
@@ -130,7 +130,7 @@ function testSiteWideContact() {
-    $this->assertText(format_string('Machine-readable name cannot be longer than @max characters but is currently @exceeded characters long.', array('@max' => $max_length, '@exceeded' => $max_length_exceeded)));
+    $this->assertText('Machine-readable name cannot be longer than ' . $max_length . ' characters but is currently @' . $max_length_exceeded . ' characters long.');

remove the @

dawehner’s picture

Status: Needs work » Needs review

Just some quick feedback.

+++ b/core/modules/book/src/Tests/BookTest.php
@@ -271,8 +271,9 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F
+      $unrendered_text = ['#markup' => '<b>‹</b> ' . $previous->label()];
+      $rendered_text = \Drupal::service('renderer')->renderRoot($unrendered_text);

a renderPlain would be enough here. In general it feels weird though that we require to do that, but yeah this more or less how its expected to work.

lokapujya’s picture

StatusFileSize
new3.71 KB
new34.36 KB

I feel responsible for fixing the errors.

lokapujya’s picture

What would be the ideal branch to commit this?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mile23’s picture

Version: 8.1.x-dev » 8.2.x-dev
Issue tags: -rc eligible +@deprecated
StatusFileSize
new34.56 KB

Rerolled to 8.2.x.

@xjm in #27 might disagree, but we could preserve the effort here by reviewing and committing, add a follow-up to split things out for assertion strings vs. message strings, and maybe even scope for format_string() only, and one for SafeMarkup::format().

After this patch, NetBeans says: Found 581 matches of format_string in 158 files and Found 179 matches of SafeMarkup::format in 63 files. That's searching through files that end in *Test.php.

Status: Needs review » Needs work

The last submitted patch, 38: 2549805_38.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 38: 2549805_38.patch, failed testing.

joelpittet’s picture

Custom test seemed to pass but it's stuck. @Mile23 mind uploading that again?

mile23’s picture

StatusFileSize
new34.56 KB

I see this in the jenkins log:

23:52:14 Completed publish:gather_artifacts
23:52:14 Executing publish:junit_xmlformat
23:52:16 Reformatted test results written to /var/lib/drupalci/web/jenkins-default-179672/artifacts/xml/testresults.xml
23:52:16 Completed publish:junit_xmlformat
23:52:16 Completed publish
23:52:17 Checking console output
23:52:17 Recording test results
23:52:18 Finished: SUCCESS

But I'll re-up anyway.

mile23’s picture

Status: Needs work » Needs review

Ewps.

mile23’s picture

Version: 8.2.x-dev » 8.3.x-dev

Patch still applies to 8.3.x. Re-running tests.

lokapujya’s picture

The patch in @28 basically filters the changes down to what was suggested in the #27.1 comment. So patch #20 has a lot more conversions in it.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joelpittet’s picture

Status: Needs review » Needs work
mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new39.67 KB

Reroll of #43.

There are still a lot more usages. We might finish up here with the remainder of either SafeMarkup or format_string, and then do a follow-up for the other one. For the sake of reviewability.

format_string() in *Test.php: 156 files.

SafeMarkup::format() in *Test.php: 63 files.

Let's finish out SafeMarkup::format() here when this patch passes.

mile23’s picture

Status: Needs review » Needs work

The last submitted patch, 51: 2549805_51.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mohit1604’s picture

Assigned: Unassigned » mohit1604
mohit1604’s picture

Assigned: mohit1604 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new8.88 KB
new41.03 KB

Status: Needs review » Needs work

The last submitted patch, 55: 2549805-55-D8.patch, failed testing. View results

alexpott’s picture

Some of this is going to be done automatically by #2958429: Properly deprecate SafeMarkup::format() - and some of this is going to be done by #2228741: Replace calls to format_string() with Drupal\Component\Render\FormattableMarkup. I think we should postpone on those two issue so that this issue only has to deal with FormattableMarkup usage in tests and not with any deprecated code.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

It could be closed, no more usage found in core

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

xjm’s picture

Title: Remove all usage of SafeMarkup::format() and format_string() in tests apart from explicit tests of those methods » Remove all usage of FormattableMarkup in tests apart from explicit tests of those methods

@andypost Well, no, the original scope wasn't only about removing deprecated API use; it was the followup to getting rid of t() in tests. The equivalent of the safe string list is still being polluted by whatever's left in tests.

xjm’s picture

Title: Remove all usage of FormattableMarkup in tests apart from explicit tests of those methods » Remove all usage of FormattableMarkup in tests apart from explicit tests of that API
mrinalini9’s picture

Assigned: Unassigned » mrinalini9
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new123.98 KB

Rerolled patch for 9.1.x and removed FormattableMarkup and t() from tests, please review.

mrinalini9’s picture

Assigned: Unassigned » mrinalini9
Status: Needs review » Needs work
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new123.97 KB

Fixed PHPLint issues in #66, please review.

shalinigaur’s picture

Assigned: Unassigned » shalinigaur
shalinigaur’s picture

Assigned: shalinigaur » Unassigned
StatusFileSize
new26.52 KB

Status: Needs review » Needs work

The last submitted patch, 70: 2549805-70.patch, failed testing. View results

mohrerao’s picture

Assigned: Unassigned » mohrerao

Working on failed tests

mohrerao’s picture

1. Ran grep -r "FormattableMarkup" * and could find FormattableMarkup still in many places.
2. Also found t() being used in many asserts.

longwave’s picture

We have a separate meta for t() as there are thousands of these to replace. This issue should be for FormattableMarkup only.

mohrerao’s picture

@longwave in #63, it was requested for.

mohrerao’s picture

Assigned: mohrerao » Unassigned
Status: Needs work » Needs review
mohrerao’s picture

Status: Needs review » Needs work

Moved to back to needs work and working on failed tests.

mohrerao’s picture

StatusFileSize
new26.63 KB
new4.74 KB

Fixed failing tests in #70. Also removes t() from many places.
I second #74. It would be better to have a separate issue from removal of t().

longwave’s picture

That issue already exists: #3133726: [meta] Remove usage of t() in tests not testing translation

There are 933 instances of "new FormattableMarkup" in tests, is this too much to fix in one issue? As with the t() issue, should we convert this to a meta and try and break this down into smaller patches that are easier to write and review?

mohrerao’s picture

@longwave, I think it would be better not to pollute the scope of this issue. We can group all issues for removal of t() under one meta and then address it from there. Also want to know @xjm's view on this as she mentioned that the scope also includes removal of t() in #63.

mohrerao’s picture

Status: Needs work » Needs review

Moving to Needs review and expecting comments form @longwave and @xjm

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

We are almost done with removing t() in tests, there are two child issues of #3133726: [meta] Remove usage of t() in tests not testing translation open and then we should be done.

There are roughly just under 1000 references to FormattableMarkup in tests:

$ rg FormattableMarkup|grep -i test|wc -l
995

Some of those will be use statements and comments, or tests of FormattableMarkup itself. If we cut this down into just assertions there are about 600:

$ rg assert.*Formattable|wc -l
599

If we then break those down into kernel and functional tests, those seem manageable amounts to do in separate child issues:

$ rg assert.*Formattable|grep Kernel|wc -l
359

$ rg assert.*Formattable|grep Functional|wc -l
235

Does that seem OK as a rescoping of this problem? We can then clean up any final leftovers in this issue.

mondrake’s picture

Component: simpletest.module » phpunit

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joachim’s picture

Status: Needs review » Needs work

Based on #84, it looks like this needs work?

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Closed (duplicate)
quietone’s picture

Status: Closed (duplicate) » Active

I think I should not have closed this. I was probably focused on t() at the time but today I see uses of FormattableMarkup in tests where it could be removed. And I guess I didn't read #74.

Sorry folks.

nikolay shapovalov’s picture

Thanks everyone for your effort.

It looks like title and summary are different, as already mentioned at #51, and it's extremely difficult to understand what is happening here/
As I understand original issue was "Remove all usage of SafeMarkup::format() and format_string() in tests apart from explicit tests of those methods".

I checked patch #78, at the top we remove t() function.

My suggestion:
revert issue title to original value and close this issue, and create new one with focus to remove FormattableMarkup.

In order to provide code contribution is better to use child issue #3227598: Remove remaining uses of FormattableMarkup in kernel test assertions.

quietone’s picture

Title: Remove all usage of FormattableMarkup in tests apart from explicit tests of that API » [Meta] Remove all usage of FormattableMarkup in tests apart from explicit tests of that API
Issue summary: View changes
Issue tags: -Needs followup, -Needs issue summary update

Since SafeMarkup was replaced by FormattableMarkup I think we can continue with this issue. There is already a child issue here for Kernel tests. Another one is needed for Functional tests.

As I understand #51, the follow up was to manage the number of changes. Since then, a separate issue has been created for Kernel test, which will help manage the scale of the changes. So, I don't think the tag is necessary any more.

quietone’s picture

Issue summary: View changes
quietone’s picture

The current child issues have been fixed. So, time for a last check for any remaining occurrences that need to be changed.
There are 128 usages of FormattableMarkup in tests in 32 files, according to results from the following.

git grep FormattableMarkup | grep Test.php: | wc -l
git grep FormattableMarkup | grep Test.php: | awk -F: '{print $1}' | sort -u | nl

Expanding the search to 5 lines before and after results and searching for 'assert' results in 12 instances to check.

$ git grep -A5 -B5 FormattableMarkup | grep Test.php: | grep -i assert | nl
     1  core/modules/comment/tests/src/Functional/CommentAdminTest.php:    $this->assertSession()->responseContains(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', ['@label' => $comment1->label()]));
     2  core/modules/comment/tests/src/Functional/CommentAdminTest.php:    $this->assertSession()->responseContains(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', ['@label' => $comment2->label()]));
     3  core/modules/contact/tests/src/Functional/ContactPersonalTest.php:    $this->assertSession()->responseContains(new FormattableMarkup('@sender_name (@sender_email) sent @recipient_name an email.', $placeholders));
     4  core/modules/field/tests/src/Functional/FunctionalString/StringFieldTest.php:    $this->assertSession()->responseContains(new FormattableMarkup('placeholder="A placeholder on @widget_type"', ['@widget_type' => $widget_type]));
     5  core/modules/system/tests/src/Functional/Form/FormTest.php:            $this->assertSession()->responseContains(new FormattableMarkup($message, $placeholders));
     6  core/modules/system/tests/src/Functional/Form/FormTest.php:            $this->assertSession()->responseNotContains(new FormattableMarkup($message, $placeholders));
     7  core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php:    $this->assertSession()->responseContains(new FormattableMarkup('Are you sure you want to delete the vocabulary %name?', ['%name' => $edit['name']]));
     8  core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php:    $this->assertSession()->responseContains(new FormattableMarkup('Deleted vocabulary %name.', ['%name' => $edit['name']]));
     9  core/modules/views/tests/src/Functional/Plugin/DisplayTest.php:    $this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', ['%relationship_name' => 'uid', '%handler_type' => 'field', '%handler' => 'User: Last login', '%display_name' => 'Default']), $errors['default'][0]);
    10  core/modules/views/tests/src/Functional/Plugin/DisplayTest.php:    $this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', ['%relationship_name' => 'uid', '%handler_type' => 'field', '%handler' => 'User: Created', '%display_name' => 'Default']), $errors['default'][1]);
    11  core/tests/Drupal/KernelTests/Component/Render/FormattableMarkupKernelTest.php:    $this->assertSame($expected, (string) new FormattableMarkup($string, $args));
    12  core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php:  public function testIsStringAssertionWithFormattableMarkup(): void {
quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes

Searching for remaining usages with the following. I then struck out the ones that are testing the API

$ git grep FormattableMarkup | grep -v "Test\.php:\s*\* " | grep Test.php: | awk -F: '{print $1}' | sort -u | nl
     1  core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php
     2  core/modules/system/tests/src/Kernel/Theme/FunctionsTest.php
     3  <del>core/modules/user/tests/modules/user_hooks_test/src/Hook/UserHooksTest.php</del>
     4  core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
     5 <del> core/tests/Drupal/KernelTests/Component/Render/FormattableMarkupKernelTest.php</del>
     6  core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php
     7  core/tests/Drupal/KernelTests/Core/Test/Comparator/MarkupInterfaceComparatorTest.php
     8  <del>core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php</del>
     9  <del>core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php</del>
    10  <del>core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php</del>
    11  core/tests/Drupal/Tests/Core/Config/Checkpoint/LinearHistoryTest.php
    12  <del>core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php</del>
    13  core/tests/Drupal/Tests/Core/Mail/Plugin/Mail/SymfonyMailerTest.php
    14  <del>core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php</del>

quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes

to check

  1. core/modules/system/tests/src/Kernel/Theme/FunctionsTest.php
  2. core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php
quietone’s picture

Status: Active » Needs review

There is one failing test, \Drupal\FunctionalTests\Bootstrap\UncaughtExceptionTest::testUncaughtFatalError, which passes locally for different versions of PHP. Not sure why it is failing here though.

Setting to NR because the existing changes can be reviewed as well as checking if there are other instances that need to change.

smustgrave’s picture

Status: Needs review » Needs work

Besides UncaughtExceptionTest the other replacements seem fine. Think this one should be one that remains as FormattableMarkup

quietone’s picture

Issue summary: View changes
quietone’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Needs work

A handful of places left where we can get rid of this still:

core/modules/node/tests/src/Traits/ContentTypeCreationTrait.php
7:use Drupal\Component\Render\FormattableMarkup;
55:      $this->assertSame($status, SAVED_NEW, (new FormattableMarkup('Created content type %type.', ['%type' => $type->id()]))->__toString());
58:      $this->assertEquals(SAVED_NEW, $status, (new FormattableMarkup('Created content type %type.', ['%type' => $type->id()]))->__toString());

core/modules/node/tests/src/Functional/NodeTestBase.php
7:use Drupal\Component\Render\FormattableMarkup;
103:    return new FormattableMarkup(

core/modules/comment/tests/src/Functional/CommentTestBase.php
8:use Drupal\Component\Render\FormattableMarkup;
300:    $this->setCommentSettings('anonymous', $level, new FormattableMarkup('Anonymous commenting set to level @level.', ['@level' => $level]));
313:    $this->setCommentSettings('per_page', $number, new FormattableMarkup('Number of comments per page set to @number.', ['@number' => $number]), $field_name);

core/modules/system/tests/src/Kernel/Theme/FunctionsTest.php
7:use Drupal\Component\Render\FormattableMarkup;
333:        'title' => new FormattableMarkup('<span class="unescaped">@text</span>', ['@text' => 'potentially unsafe text that <should> be escaped']),

core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php
7:use Drupal\Component\Render\FormattableMarkup;
190:    $message = new FormattableMarkup('%type: @message in %function (line ', $error);
200:    $message = new FormattableMarkup('%type: @message in %function (line ', $error);
harivansh’s picture

Assigned: Unassigned » harivansh
harivansh’s picture

Assigned: harivansh » Unassigned
Status: Needs work » Needs review

tobiasb made their first commit to this issue’s fork.

tobiasb’s picture

The comment of core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php was outdated.

The $message parameter in \Drupal\Tests\shortcut\Functional\ShortcutLinksTest::assertShortcutQuickLink is not used by core itself, but I just changed the text also.

quietone’s picture

Issue summary: View changes
Status: Needs review » Needs work

So, I see my grep was limited to *Test.php, I have updated the issue summary with an improved search.

There are out of scope changes in core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php and
core/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTestBaselineTrait.php that need to be removed.

After applying the diff and searching these are the remaining instances that need to be checked.

  1. core/modules/config/tests/config_test/src/ConfigTestForm.php
  2. core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPlaceholders.php
  3. core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php
  4. core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php
  5. core/modules/system/tests/modules/menu_test/src/TestControllers.php
  6. core/modules/system/tests/modules/session_test/src/Form/SessionTestForm.php
  7. core/modules/system/tests/modules/update_test_schema/src/Hook/UpdateTestSchemaRequirements.php
  8. core/modules/system/tests/modules/update_test_schema/update_test_schema.install
  9. core/tests/Drupal/KernelTests/AssertContentTrait.php
  10. core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php
  11. core/tests/Drupal/Tests/WebAssert.php

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Issue summary: View changes
Status: Needs work » Active
Issue tags: -@deprecated
quietone’s picture

Issue summary: View changes
quietone’s picture