Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#9 | interdiff.txt | 843 bytes | dawehner |
#9 | 2567851-9.patch | 1.18 KB | dawehner |
#6 | 2567851-6.patch | 1.18 KB | dawehner |
Comments
Comment #2
joelpittetComment #3
xjmNarrowing the scope a bit.
Comment #4
larowlanComment #5
larowlanPostponed until #2506445: Replace !placeholder with @placeholder in t() and format_string() for non-URLs in tests lands
Comment #6
dawehnerI'm sorry, but the other patch does not touches this particular file at all.
We are certainly overpostponing from time to time.
Comment #9
dawehnerIMHO we want to test that the active tab is actually there, so we would need an assertRaw.
Comment #10
catchLooks right to me.
Comment #12
alexpottCommitted 6905340 and pushed to 8.0.x. Thanks!
Comment #13
xjmWhy are we assigning
$link_text
to a variable at all? It's never used again.Comment #14
cilefen CreditAttribution: cilefen commented#2568287: NodeEditFormTest::testNodeEdit() sets $link_text but uses it only once
Comment #15
cilefen CreditAttribution: cilefen commentedI 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.