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.

In #3133726: [meta] Remove usage of t() in tests not testing translation we identified there are several calls to t() in calls to clickLink() and that removing all these in one go seems to be a suitable way of attacking this problem.

Proposed resolution

Identify and remove all calls to t() wrapped in calls to clickLink(), except those used by translation-related code (if any).

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Hardik_Patel_12 created an issue. See original summary.

Hardik_Patel_12’s picture

Status: Active » Needs review
FileSize
90.34 KB

Kindly review the patch.

joseph.olstad’s picture

If I install Drupal in another language using this patch and run the tests, they will fail.
Not sure about the rationale behind this change?

Status: Needs review » Needs work

The last submitted patch, 2: 3153469-2.patch, failed testing. View results

Hardik_Patel_12’s picture

Status: Needs work » Needs review
FileSize
90.22 KB
4.88 KB

@joseph.olstad , 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. We will need to ensure to leave t() where the test actually tests the translation system.

Solving failed test cases.

Status: Needs review » Needs work

The last submitted patch, 5: 3153469-5.patch, failed testing. View results

joseph.olstad’s picture

what if we want to test an install profile for automated tests and that install profile uses a default language other than english?
those tests would break, no?

For such a minuscule performance difference, not sure if this change is worth the effort given that at some point it might be useful to test an install profile test runner in a language other than english.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

longwave’s picture

Title: Remove uses of t() in clickLink(), responseContains() and assertUniqueText() calls » Remove uses of t() in clickLink() calls

I'm going to rescope this a bit tighter as the three methods in the original issue don't seem very closely related, and at the time of writing clickLink() is one of the biggest remaining uses of t() calls.

longwave’s picture

Status: Needs work » Needs review
FileSize
90.17 KB
longwave’s picture

Issue summary: View changes
FileSize
91.09 KB
939 bytes

Let's add a deprecation so we can find the remaining uses.

Status: Needs review » Needs work

The last submitted patch, 11: 3153469-11.patch, failed testing. View results

longwave’s picture

Status: Needs work » Needs review
FileSize
92.52 KB
2.45 KB

Fixed the remaining failures.

clickLink already asserts that the link exists, so we can remove some redundancy here too.

longwave’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
longwave’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
91.08 KB
90.17 KB

First patch includes a deprecation to check that nothing was missed. Second patch is probably the one that should be committed, as we don't strictly need to deprecate this.

The last submitted patch, 15: 3153469-15-with-deprecation.patch, failed testing. View results

longwave’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
hmendes’s picture

Re-rolled both patches.
Please review.

Status: Needs review » Needs work

The last submitted patch, 20: 3153469-20-with-deprecation.patch, failed testing. View results

hmendes’s picture

longwave’s picture

Status: Needs review » Reviewed & tested by the community

I have worked on some patches in this issue but this is mostly a trivial find and replace, and the reroll looks good to me.

I think the "without deprecation" patch is the one to commit - I am not sure we should enforce strings as it might get in the way of downstream users testing with translations enabled.

catch’s picture

Version: 9.3.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

what if we want to test an install profile for automated tests and that install profile uses a default language other than english?
those tests would break, no?

@joseph.olstad this is just not how the tests are written - every browser test installs Drupal again, with a profile specified in the test. The Drupal install itself that you're running tests from has as little as possible to do with this.

If you write a test for an install profile or site where English isn't the default language, then rather than using t() you'd want to specific the correct text in the language under test.

Committed/pushed (the 'without deprecation' version - if we wanted to deprecate we'd need a follow-up issue that only does that) to 9.3.x, thanks!

This doesn't cherry-pick cleanly for 9.2.x, so needs a re-roll there.

  • catch committed 686951d on 9.3.x
    Issue #3153469 by longwave, hmendes, Hardik_Patel_12: Remove uses of t...
catch’s picture

Title: Remove uses of t() in clickLink() calls » [backport] Remove uses of t() in clickLink() calls
longwave’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
90.49 KB
catch’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the re-roll, looks good. Will commit this tomorrow if no objections.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x, thanks!

  • catch committed 87feede on 9.2.x
    Issue #3153469 by longwave, hmendes, Hardik_Patel_12: Remove uses of t...

Status: Fixed » Closed (fixed)

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