Problem/Motivation

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

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

+++ b/core/modules/node/src/Tests/NodeEditFormTest.php
@@ -77,8 +78,8 @@ public function testNodeEdit() {
     // Check that the title and body fields are displayed with the correct values.
-    $active = '<span class="visually-hidden">' . t('(active tab)') . '</span>';
-    $link_text = t('!local-task-title!active', array('!local-task-title' => t('Edit'), '!active' => $active));
+    $active = SafeMarkup::format('<span class="visually-hidden">@active_tab</span>', array('@active_tab' => t('(active tab)')));
+    $link_text = t('@local-task-title@active', array('@local-task-title' => t('Edit'), '@active' => $active));
     $this->assertText(strip_tags($link_text), 0, 'Edit tab found and marked active.');
     $this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.');
     $this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.');
Oh, I also agree with @justAChris that this is kinda a WTF. It'd be better to remove both the format() and the t(), and just do a plain simple assertText(). Let's split this one off into its own issue too.

Proposed resolution

Remaining tasks

User interface changes

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Issue summary: View changes
xjm’s picture

Title: Use assertText() instead of t()/SafeMarkup::format() on non-URLs in tests with !placeholder » Use assertText() instead of t()/SafeMarkup::format() in NodeEditFormTest
Status: Needs review » Active

Narrowing the scope a bit.

larowlan’s picture

Assigned: Unassigned » larowlan
larowlan’s picture

Assigned: larowlan » Unassigned
Status: Active » Postponed
dawehner’s picture

Status: Postponed » Needs review
FileSize
1.18 KB

I'm sorry, but the other patch does not touches this particular file at all.

We are certainly overpostponing from time to time.

Status: Needs review » Needs work

The last submitted patch, 6: 2567851-6.patch, failed testing.

The last submitted patch, 6: 2567851-6.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
1.18 KB
843 bytes

IMHO we want to test that the active tab is actually there, so we would need an assertRaw.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Looks right to me.

  • alexpott committed 6905340 on 8.0.x
    Issue #2567851 by dawehner, joelpittet: Use assertText() instead of t()/...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 6905340 and pushed to 8.0.x. Thanks!

xjm’s picture

+++ b/core/modules/node/src/Tests/NodeEditFormTest.php
@@ -77,9 +77,10 @@ public function testNodeEdit() {
-    $active = '<span class="visually-hidden">' . t('(active tab)') . '</span>';
-    $link_text = t('!local-task-title!active', array('!local-task-title' => t('Edit'), '!active' => $active));
-    $this->assertText(strip_tags($link_text), 0, 'Edit tab found and marked active.');
+    // As you see the expected link text has no HTML, but we are using
+    $link_text = 'Edit<span class="visually-hidden">(active tab)</span>';
+    // @todo Ideally assertLink would support HTML, but it doesn't.
+    $this->assertRaw($link_text, 'Edit tab found and marked active.');

Why are we assigning $link_text to a variable at all? It's never used again.

cilefen’s picture

cilefen’s picture

+++ b/core/modules/node/src/Tests/NodeEditFormTest.php
@@ -77,9 +77,10 @@ public function testNodeEdit() {
+    // As you see the expected link text has no HTML, but we are using
+    $link_text = 'Edit<span class="visually-hidden">(active tab)</span>';

I find this comment as a segue in to a line of code odd (is that what it is?). It makes the followup issue of removing $link_text hard to do. Is comment the reason $link_text exists.

Status: Fixed » Closed (fixed)

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