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() from various methods, and removing all calls from submitForm() calls 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 submitForm(), except those used by translation-related code (if any).

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs review
StatusFileSize
new9.25 KB

Unsure if we should actually deprecate this, but it will tell us if I missed anything.

Status: Needs review » Needs work

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

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new9.65 KB

Status: Needs review » Needs work

The last submitted patch, 4: 3187113-4.patch, failed testing. View results

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new10.74 KB
vikashsoni’s picture

By this patch #6 we can remove use of t() for submitForm

guilhermevp’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new113.08 KB

Patch applies cleanly and works as intended.

RTBC +1

  • catch committed febe06c on 9.2.x
    Issue #3187113 by longwave: Remove uses of t() in submitForm() calls
    
catch’s picture

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

@guilhermevp there's no need to upload a screenshot of the patch applying, since the automated test system tells us whether the patch applies or not already. A better way to show that the patch works would be to check that there are no more t() calls inside ::submitForm() - although the new deprecation notice ensures this.

We should backport this to 9.1.x to keep the tests in sync, but without the hunk adding the new deprecation. Looked at committing without just that hunk, but it needs a reroll for other conflicts too.

longwave’s picture

Not actually sure this was ready to go, the deprecation notice has a fake node ID as I didn't write a change notice. Do we need one? Should we even be deprecating this?

  • catch committed 08cddd8 on 9.2.x
    Revert "Issue #3187113 by longwave: Remove uses of t() in submitForm()...
catch’s picture

Whoops I glazed over the fake node ID.

I think it's fine to deprecate the behaviour formally, but if we do that we'd actually need to type hint on string in Drupal 10, so we'd at least need a follow-up to add that type hint.

alexpott’s picture

PHP 8 now has stringable which would be an ideal typehint for this. Not sure we need to break people's tests for this. Could go both ways.

longwave’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
StatusFileSize
new10.27 KB

Reuploading without the deprecation hunk. The deprecation proved that we have covered all instances, but I don't think we actually need to formally deprecate this - we just want to remove t() from all core tests where possible to set a good example.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll
longwave’s picture

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

Whoops this was for 9.2.x, it was reverted from there and needs to go back in.

  • catch committed 439c314 on 9.2.x
    Issue #3187113 by longwave: Remove uses of t() in submitForm() calls
    
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 439c314 and pushed to 9.2.x. Thanks!

Status: Fixed » Closed (fixed)

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

pbbhoge’s picture

StatusFileSize
new10.27 KB

Hi @longwave,

Due to issue we are facing Error in PHPunit test case having translation enabled .

Can you please re-open this issue and revert the code as per attached patch ( Reverting code from comment #15 ) ?

timmillwood’s picture

We don't need to revert the whole commit, but we are facing issues when running drupal login on non-english sites. #3222549: Adding t() function in UiHelperTrait::drupalLogin() fixes that.