Follow-up to #2506445: Replace !placeholder with @placeholder in t() and format_string() for non-URLs in tests
Problem/Motivation
+++ 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
- Remove t() and assert raw expected text.
- Add an assertion to find double escaping.
Remaining tasks
User interface changes
Ideally, fewer completely unexpected double-escaping bugs.
API changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | interdiff.txt | 1.19 KB | dawehner |
| #7 | 2567857-7.patch | 1.32 KB | dawehner |
| #5 | 2567857-5.patch | 1.28 KB | dawehner |
Comments
Comment #2
xjmLet's keep the scope of this narrow since it's blocking a critical.
Comment #3
xjmComment #4
larowlanPostponed until #2506445: Replace !placeholder with @placeholder in t() and format_string() for non-URLs in tests is in
Comment #5
dawehnerWell, we can bring up a patch here already as well.
Comment #6
xjmAgreed, 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.
Comment #7
dawehnerI think this is the max we should do, otherwise it gets really hard to read.
Comment #10
xjmComment #11
chx commentedTests 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.
Comment #12
xjmThanks, that looks great. Committed and pushed to 8.0.x.