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 over 2,200 calls to t() in calls to drupalPostForm() 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 drupalPostForm(), except those used by translation-related code (if any).

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#49 interdiff_44-49.txt7.31 KBmondrake
#49 3145005-49-91x.patch1.11 MBmondrake
#48 interdiff_44-48.txt7.29 KBmondrake
#48 3145005-48-92x.patch1.11 MBmondrake
#44 3145005-44-9.2.x.patch1.11 MBlongwave
#44 3145005-44-9.1.x.patch1.11 MBlongwave
#41 3145005-41.patch1.11 MBlongwave
#38 interdiff.3145005.33-38.txt1.05 KBlongwave
#38 3145005-38.patch1.11 MBlongwave
#33 interdiff_31-33.txt1.05 KBraman.b
#33 3145005-33.patch1.11 MBraman.b
#31 3145005-31.patch1.11 MBmondrake
#31 interdiff_29-31.txt2.04 KBmondrake
#29 interdiff.3145005.24-29.txt46.92 KBlongwave
#29 3145005-29.patch1.11 MBlongwave
#24 3145005-24.patch1.07 MBlongwave
#16 3145005-16.patch1.08 MBcburschka
#14 patch_apply_error.png707.16 KBnaresh_bavaskar
#12 3145005-12.patch1.08 MBLal_
#7 3145005-interdiff-5-7.txt2.84 KBcburschka
#7 3145005-7.patch1.08 MBcburschka
#5 3145005-interdiff-3-5.txt978 bytescburschka
#5 3145005-5.patch1.08 MBcburschka
#3 interdiff.3145005.2-3.txt15.96 KBlongwave
#3 3145005-3.patch1.08 MBlongwave
#2 3145005-2.patch1.07 MBlongwave
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs review
FileSize
1.07 MB

Used this script to generate the first patch:

grep -rl drupalPostForm core | xargs sed -E -i "s/(drupalPostForm.* )t\(('[^']+')\)/\1\2/g"

Let's see what testbot comes back with. There are a few more manual fixes that can be made on top of this, but it looks like a good start.

longwave’s picture

FileSize
1.08 MB
15.96 KB

Slightly surprised that that passed with no errors!

Manual fixes done, I can't find any more calls to t() inside drupalPostForm().

Status: Needs review » Needs work

The last submitted patch, 3: 3145005-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

cburschka’s picture

Status: Needs work » Needs review
FileSize
1.08 MB
978 bytes

Small string concatenation issue.

dww’s picture

Status: Needs review » Needs work

Thanks for this! Seems like a great start. Very cursory scan looks really good.

Bot found some CS bugs:

9 coding standards messages
✗ 9 more than branch result

/var/lib/drupalci/workspace/jenkins-drupal_patches-47656/source/core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php ✗ 1 more
line 5	Unused use statement
/var/lib/drupalci/workspace/jenkins-drupal_patches-47656/source/core/modules/views_ui/tests/src/Functional/HandlerTest.php ✗ 8 more
111	Expected 1 space after comma in argument list; 2 found
111	Expected one space after the comma, 2 found
116	Expected 1 space after comma in argument list; 2 found
116	Expected one space after the comma, 2 found
150	Expected 1 space after comma in argument list; 2 found
150	Expected one space after the comma, 2 found
154	Expected 1 space after comma in argument list; 2 found
154	Expected one space after the comma, 2 found

Thanks,
-Derek

cburschka’s picture

Status: Needs work » Needs review
FileSize
1.08 MB
2.84 KB
longwave’s picture

@cburschka Thanks for fixing up my mistakes :)

I cannot RTBC as I wrote the initial patches but I don't have anything else to add, this looks good to me.

dww’s picture

Status: Needs review » Reviewed & tested by the community

Before:

% grep -r drupalPostForm core | egrep 't\(' | wc
    2249   12282  324258

After:

% grep -r drupalPostForm core | egrep 't\(' | wc
    4      29     806

The 4 are false hits from being too permissive with searching for: "t("

./modules/views_ui/tests/src/Functional/DisplayPathTest.php:    $this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_3/path', ['path' => '<script>alert("hello");</script>'], 'Apply');
./modules/views_ui/tests/src/Functional/DisplayPathTest.php:    $this->drupalPostForm('admin/structure/views/nojs/display/test_view/page_4/path', ['path' => '<script>alert("hello I have placeholders %");</script>'], 'Apply');
./modules/system/tests/src/Functional/Form/ConfirmFormTest.php:    $this->drupalPostForm('form-test/confirm-form', NULL, 'ConfirmFormTestForm::getConfirmText().');
./modules/system/tests/src/Functional/Form/ConfirmFormTest.php:    $this->drupalPostForm('form-test/confirm-form', NULL, 'ConfirmFormTestForm::getConfirmText().', ['query' => ['destination' => 'admin/config']]);

Tests all pass. Bot's happy with code style.

I can't handle line-by-line reviewing a 1mb patch of nearly 20K lines. :/ But a spot check looks totally reasonable everywhere I inspected. I can't imagine @longwave nor @cburschka are trying to sneak in anything here. ;)

longwave’s picture

Anyone who wants to double check the patch integrity can run the shell command in #2 and then apply the following three interdiffs. Then you only have to trust the shell command itself and the interdiffs are reviewable :)

Also note that we might have to recreate this patch for other branches using a similar process, if it is to be backported to make cherry-picking other patches easier.

mondrake’s picture

Status: Reviewed & tested by the community » Needs work
Lal_’s picture

re-roll of #7 as it failed to apply

Lal_’s picture

Status: Needs work » Needs review
naresh_bavaskar’s picture

Status: Needs review » Needs work
FileSize
707.16 KB

@lal_ I tried to apply the patch, but getting an error (attached screenshot)
also, it will be good if you provide interdiff as well here

nitesh624’s picture

Assigned: Unassigned » nitesh624
cburschka’s picture

Assigned: nitesh624 » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.08 MB

Merged 9.1.x.

@naresh_bavaskar, attaching screenshots of your CLI does not really help

longwave’s picture

Status: Needs review » Reviewed & tested by the community

I diffed #7 and #16 and only changes are rerolled lines, so back to RTBC.

dww’s picture

Issue summary: View changes

Removing credit and screenshot from #14 that was embedded in the summary.

xjm’s picture

Title: Remove uses of t() in drupalPostForm() calls » [Needs scheduling] Remove uses of t() in drupalPostForm() calls
Status: Reviewed & tested by the community » Postponed
Issue tags: +beta target

Thanks for working on this monster!

Unfortunately, this already does not apply. Typically, with cleanups this large, we schedule them during the beta or RC phase of a release, to avoid disrupting ongoing work.

The beta window for 9.1 is the week of November 2, so we'd want to schedule it for sometime the week of November 9 or following.

Is someone able to regenerate that patch then? I know it's a ways out.

longwave’s picture

Understood. I will put this in my calendar and try to get to it in November!

mondrake’s picture

Issue tags: +Deprecated assertions

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.

Pasqualle’s picture

Version: 9.2.x-dev » 9.1.x-dev
longwave’s picture

Status: Postponed » Needs review
FileSize
1.07 MB

Rerolled.

mondrake’s picture

Title: [Needs scheduling] Remove uses of t() in drupalPostForm() calls » [November 9, 2020] Remove uses of t() in drupalPostForm() calls
Status: Needs review » Reviewed & tested by the community

Wonder if it would make sense to try, in a test issue, to add a temp deprecation trigger like we did in other issues of this kind, to check if any leftover calls remain with an object passed in.

Regardless, this is good cleanup.

longwave’s picture

Re #25 I added a deprecation warning in #3180410: longwave patch testing

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Needs work for the fails in https://www.drupal.org/pift-ci-job/1871376

TBH maybe we should just add the deprecation here, we already have two in this method, adding a third will help everyone migrate away from drupalPostForm more cleanly.

mondrake’s picture

#27 +1 yes, in this case it would be probably better to explicitly cast $subject to string in the likely rare case it happens to be an object.

longwave’s picture

Added a deprecation warning and fixed all remaining cases that were triggered by said warning.

None of the cases need casting - we can always pass plain strings.

Status: Needs review » Needs work

The last submitted patch, 29: 3145005-29.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
FileSize
2.04 KB
1.11 MB

Couple more changes.

mondrake’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

We need a deprecation test for the @trigger_error added in #29.

raman.b’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.11 MB
1.05 KB

Addressing #32

Status: Needs review » Needs work

The last submitted patch, 33: 3145005-33.patch, failed testing. View results

raman.b’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Reviewed & tested by the community

#31 covers the two things I missed and great work in #33, that's a nice clean way of adding an extra test here!

mondrake’s picture

Status: Reviewed & tested by the community » Needs work

There's a code standard failure now,

core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php ✗ 1 more
line 863 Do not pass empty strings to t()

longwave’s picture

Status: Needs work » Needs review
FileSize
1.11 MB
1.05 KB
mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Assuming it turns out green.

mondrake’s picture

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

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
1.11 MB

Rerolled.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Patch no longer applies. We also need a 9.1.x patch without the deprecation or test for it (i.e. just the t() removal).

longwave’s picture

Assigned: Unassigned » longwave
longwave’s picture

Assigned: longwave » Unassigned
Status: Needs work » Needs review
FileSize
1.11 MB
1.11 MB

Lots of conflicts, so I reused the script in #2 to automatically fix up the rejected hunks. This may have missed some, let's see...

The last submitted patch, 44: 3145005-44-9.1.x.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 44: 3145005-44-9.2.x.patch, failed testing. View results

mondrake’s picture

Assigned: Unassigned » mondrake

Fixing the issues.

mondrake’s picture

Status: Needs work » Needs review
FileSize
1.11 MB
7.29 KB

The 9.2.x patch, 9.1.x one next

mondrake’s picture

9.1.x patch, without deprecation and test

Status: Needs review » Needs work

The last submitted patch, 49: 3145005-49-91x.patch, failed testing. View results

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Reviewed & tested by the community

#50 was a random failure.

Back to RTBC since I basically just rerolled.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and 9.1.x, thanks!

longwave’s picture

Status: Fixed » Reviewed & tested by the community

Doesn't look like this was pushed to git?

  • catch committed 783e7eb on 9.2.x
    Issue #3145005 by longwave, mondrake, cburschka, raman.b, Lal_, dww, xjm...

  • catch committed 8d344a4 on 9.1.x
    Issue #3145005 by longwave, mondrake, cburschka, raman.b, Lal_, dww, xjm...
longwave’s picture

Status: Reviewed & tested by the community » Fixed

Ah, there it goes!

Status: Fixed » Closed (fixed)

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