Follow-up to #2506445: Replace !placeholder with @placeholder in t() and format_string() for non-URLs in tests

Problem/Motivation

From #2506445-184: Replace !placeholder with @placeholder in t() and format_string() for non-URLs in tests

+++ b/core/modules/node/src/Tests/NodeRevisionsUiTest.php
+++ b/core/modules/node/src/Tests/NodeRevisionsUiTest.php
@@ -119,17 +119,17 @@ public function testNodeRevisionDoubleEscapeFix() {

@@ -119,17 +119,17 @@ public function testNodeRevisionDoubleEscapeFix() {
     // Assert the old revision message.
     $date = format_date($nodes[0]->revision_timestamp->value, 'short');
     $url = new Url('entity.node.revision', ['node' => $nodes[0]->id(), 'node_revision' => $nodes[0]->getRevisionId()]);
-    $old_revision_message = t('!date by !username', [
-      '!date' => \Drupal::l($date, $url),
-      '!username' => $editor,
+    $old_revision_message = t('@date by @username', [
+      '@date' => \Drupal::l($date, $url),
+      '@username' => $editor,
     ]);
     $this->assertRaw($old_revision_message);

     // Assert the current revision message.
     $date = format_date($nodes[1]->revision_timestamp->value, 'short');
-    $current_revision_message = t('!date by !username', [
-      '!date' => $nodes[1]->link($date),
-      '!username' => $editor,
+    $current_revision_message = t('@date by @username', [
+      '@date' => $nodes[1]->link($date),
+      '@username' => $editor,
     ]);
     $current_revision_message .= '<p class="revision-log">' . $revision_log . '</p>';
     $this->assertRaw($current_revision_message);
This test also needs a followup. It's supposed to be a test for a double-escaping fix, but it does an assertRaw() on the result of t() rather than asserting the actual raw expected output. This means that if our changes to t() end up reintroducing double-escaping, this test will just test that it's double-escaped.

Proposed resolution

  1. Remove t() and assert raw expected text.
  2. Add an assertion to find double escaping.

Remaining tasks

User interface changes

Ideally, fewer completely unexpected double-escaping bugs.

API changes

None.

CommentFileSizeAuthor
#7 interdiff.txt1.19 KBdawehner
#7 2567857-7.patch1.32 KBdawehner
#5 2567857-5.patch1.28 KBdawehner

Comments

joelpittet created an issue. See original summary.

xjm’s picture

Title: Fix !placeholders for non-URLs in tests where they are not testing what they are expecting. » Remove !placeholder in NodeRevisionUiTest and make it actually test the expected output
Category: Task » Bug report

Let's keep the scope of this narrow since it's blocking a critical.

xjm’s picture

Status: Needs review » Active
larowlan’s picture

dawehner’s picture

Status: Postponed » Needs review
StatusFileSize
new1.28 KB

Well, we can bring up a patch here already as well.

xjm’s picture

Agreed, these should not to be postponed; the intent was specifically to do them in parallel.

As in #2567851: Use assertText() instead of t()/SafeMarkup::format() in NodeEditFormTest, is there any need to assign these to variables at all? They're never used outside the assertion.

dawehner’s picture

StatusFileSize
new1.32 KB
new1.19 KB

I think this is the max we should do, otherwise it gets really hard to read.

Status: Needs review » Needs work

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

dawehner queued 7: 2567857-7.patch for re-testing.

xjm’s picture

Status: Needs work » Needs review
chx’s picture

Status: Needs review » Reviewed & tested by the community

Tests run a known state and it's not translated so this should be good. There's HTML in both asserts so they are testing what they should.

xjm’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, that looks great. Committed and pushed to 8.0.x.

  • xjm committed 695deff on 8.0.x
    Issue #2567857 by dawehner, joelpittet, chx: Remove !placeholder in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.