Problem/Motivation

There is no need to use t() in tests, unless we're testing translations, however in core we do not follow this consistently, which does not set a good example for new contributions.

#3153468: Strip HTML tags when using assertEquals() to compare markup exists to deal with some tricky cases in assertEquals() calls.

If we ignore those then there are just under 300 cases remaining across core:

$ find core -type f -iname '*Test.php' | xargs grep '[^a-zA-Z]t(' | grep -v assertEqual | wc -l
279

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3231781

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs work

About halfway done.

longwave’s picture

Status: Needs work » Needs review

Remaining cases are:

  • t() with $langcode passed in (ie. actually testing translations)
  • Some validation messages that use % placeholders
  • setDescription/setLabel calls
  • form tests that people might copy
  • comments

Otherwise I think this is done.

longwave’s picture

Assigned: longwave » Unassigned

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

longwave’s picture

Thanks for fixing that :)

mondrake’s picture

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

This is close. Please see a few comments on the MR.

@core committers please see @TR's request for crediting people in the peer issue #2552067-50: Remove t() from assertion messages in tests.

longwave’s picture

Status: Needs work » Needs review

Thanks for reviewing, feedback addressed.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Thanks

larowlan credited DuaelFr.

larowlan credited GoZ.

larowlan credited TR.

larowlan credited benjy.

larowlan credited nlisgo.

larowlan credited no_angel.

larowlan credited xxAlHixx.

larowlan’s picture

Issue summary: View changes

Adding credit per remaining tasks

larowlan’s picture

Crediting @mondrake for reviewing

larowlan’s picture

Getting a second opinion as to whether this needs to wait for a disruptive patch window.

Reviewed the diff and it looks good to me, thanks for using an MR here, the word-diff formatting in gitlab was much easier to review than it would have been with dreditor.

mondrake’s picture

Rerolled

alexpott’s picture

I think we should go for a disruptive window here because the MR doesn't apply to 9.2.x as well. If we could apply it there we could say this isn't going to make security releases harder but it will so let's apply during the 9.3.x beta.

mondrake’s picture

Rerolled

mondrake’s picture

Title: Remove remaining uses of t() in tests » [D9.3 beta - w/c Nov 8, 2021] Remove remaining uses of t() in tests
longwave’s picture

Bumping for visibility, patch still applies cleanly for me.

TR’s picture

I agree it applies cleanly and fixes a whole lot of problems and should be committed soon.

There are a few cases that the regexp in the summary misses, but I think those are exceptions and should be handled in a clean-up issue. For example, in FileTestBase there are two blocks of code like this:

    if (!isset($message)) {
      $message = t('Expected file permission to be %expected, actually were %actual.', ['%actual' => decoct($actual_mode), '%expected' => decoct($expected_mode)]);
    }
    $this->assertEquals($expected_mode, $actual_mode, $message);

This is missed because the message is a variable rather than an in-line use of t().

But again, I don't want to derail this patch just because of a small number of things like this - what's in this patch is good and appropriate and correct. I would rather add a new child issue in the meta to handle any exceptions like this.

  • larowlan committed a83a7a7 on 9.4.x
    Issue #3231781 by longwave, mondrake, Feuerwagen, larowlan, TR, nlisgo,...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed a83a7a7 and pushed to 9.4.x. Thanks!

To maximize the chance of future backports applying cleanly, backported to 9.3.x

Nice work all.

  • larowlan committed 6af996b on 9.3.x
    Issue #3231781 by longwave, mondrake, Feuerwagen, larowlan, TR, nlisgo,...
mondrake’s picture

I think the idea was to port it down to 9.2.x to alleviate potential efforts with security patches? Otherwise I do not see much sense to wait for 'disruptive patch windows'

larowlan’s picture

9.2 has had its last bugfix release, any security release would be on top of that tag, so backporting to 9.2.x HEAD won't help security patches apply cleaner unfortunately

Status: Fixed » Closed (fixed)

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