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 severals of calls to t() in calls to linkExists() and linkNotExists() 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 linkExists() and linkNotExists(), except those used by translation-related code (if any).
Create a list of Test files using t()
by find core -type f -iname '*Test.php' | xargs grep '[^a-zA-Z]t(' > remove_t_list.txt
, then search that list for linkExists
and linkNotExists
.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#25 | 3153143-25.patch | 40.06 KB | Hardik_Patel_12 |
#18 | interdiff_16-18.txt | 2.41 KB | ridhimaabrol24 |
#18 | 3153143-18.patch | 40.03 KB | ridhimaabrol24 |
#16 | interdiff_12-16.txt | 5.32 KB | ridhimaabrol24 |
#16 | 3153143-16.patch | 40.15 KB | ridhimaabrol24 |
Comments
Comment #2
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 for Drupal India Association commentedComment #4
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 for Drupal India Association commentedComment #5
guptahemant CreditAttribution: guptahemant as a volunteer and at QED42 for Drupal India Association commentedComment #6
guptahemant CreditAttribution: guptahemant as a volunteer and at QED42 for Drupal India Association commentedComment #7
guptahemant CreditAttribution: guptahemant as a volunteer and at QED42 for Drupal India Association commentedHere is an updated patch.
Comment #8
guptahemant CreditAttribution: guptahemant as a volunteer and at QED42 for Drupal India Association commentedComment #9
meena.bisht CreditAttribution: meena.bisht at QED42 for Drupal India Association commentedComment #10
apadernoComment #11
siddhant.bhosale CreditAttribution: siddhant.bhosale as a volunteer and at QED42 commentedHi, I found changes left in files. eg.
core/modules/comment/tests/src/Functional/CommentLinksAlterTest.php
has the t() used.$this->assertSession()->linkExists(t('Report'));
. Marking this to needs works.Comment #12
siddhant.bhosale CreditAttribution: siddhant.bhosale as a volunteer and at QED42 commentedHi, I have made the changes. Adding the patch and interdiff as well.
Comment #13
siddhant.bhosale CreditAttribution: siddhant.bhosale as a volunteer and at QED42 commentedComment #14
mondrakeComment #15
quietone CreditAttribution: quietone commentedApplied the patch. Then ran
grep -r '\->\(linkExists\|linkNotExists\)(t(' core | nl
and 11 more instances were found.Comment #16
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedRemoving the remaining t() calls. Please review.
Comment #18
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedFixing failed test cases.
Comment #19
samiullah CreditAttribution: samiullah at Salsa Digital commented@ridhimaabrol24 some bit of code still has t() after applying ur patch
Comment #20
samiullah CreditAttribution: samiullah at Salsa Digital commentedComment #21
siddhant.bhosale CreditAttribution: siddhant.bhosale as a volunteer and at QED42 commentedComment #22
ridhimaabrol24 CreditAttribution: ridhimaabrol24 at Srijan | A Material+ Company for Drupal India Association commentedHi @samiullah
By applying patch #18 there are no instances left of linkExists(t( and linkNotExists(t(
Please recheck the same.
Also the code you are referring to in #19 is already present in the patch.
Let me know if you still find issues.
Thanks
Comment #23
quietone CreditAttribution: quietone as a volunteer commentedI applied that patch and found no usages of t() in lines using linkNotExists or linkExists.
However, all of these are in tests related to translations. Are we sure the t() should be removed in all these cases? I don't know and I haven't looked at the tests myself.
Comment #24
paulocsPatch needs re-roll.
Comment #25
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 for Drupal India Association commentedRe-rolling for 9.1.x , kindly review.
Comment #26
paulocsHello @all,
Patch #25 looks good. I did not find any linkExists() and linkNotExists() with a t() inside.
About comment #23, is okay to remove it because it is testing if the link with the specified label exists or not. So it makes no sense to remove it.
See https://www.drupal.org/docs/automated-testing/phpunit-in-drupal/phpunit-browser-test-tutorial#t
Set to RTBC.
Cheers, Paulo.
Comment #28
longwaveRandom fail, back to RTBC.
Comment #30
catchCommitted 4a7c205 and pushed to 9.1.x. Thanks!
Comment #31
samiullah CreditAttribution: samiullah at Salsa Digital commentedLooks good now @catch