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 commentedComment #4
hardik_patel_12 commentedComment #5
guptahemant commentedComment #6
guptahemant commentedComment #7
guptahemant commentedHere is an updated patch.
Comment #8
guptahemant commentedComment #9
meena.bisht commentedComment #10
avpadernoComment #11
siddhant.bhosale commentedHi, I found changes left in files. eg.
core/modules/comment/tests/src/Functional/CommentLinksAlterTest.phphas the t() used.$this->assertSession()->linkExists(t('Report'));. Marking this to needs works.Comment #12
siddhant.bhosale commentedHi, I have made the changes. Adding the patch and interdiff as well.
Comment #13
siddhant.bhosale commentedComment #14
mondrakeComment #15
quietone commentedApplied the patch. Then ran
grep -r '\->\(linkExists\|linkNotExists\)(t(' core | nland 11 more instances were found.Comment #16
ridhimaabrol24 commentedRemoving the remaining t() calls. Please review.
Comment #18
ridhimaabrol24 commentedFixing failed test cases.
Comment #19
samiullah commented@ridhimaabrol24 some bit of code still has t() after applying ur patch
Comment #20
samiullah commentedComment #21
siddhant.bhosale commentedComment #22
ridhimaabrol24 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 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 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 commentedLooks good now @catch