Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We have some calls of t()
function in tests. First of all, it's not necessary. Secondly, it generates some CS issues that were reported originally:
FILE: /Users/thallesvf/Desktop/lando/d8-contrib/modules/token/tests/src/Functional/TokenMenuTest.php
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 20 ERRORS AND 17 WARNINGS AFFECTING 32 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10 | WARNING | [x] Unused use statement
35 | ERROR | [x] Visibility must be declared on method "testMenuTokens"
35 | ERROR | [x] Missing function doc comment
103 | WARNING | [ ] Line exceeds 80 characters; contains 107 characters
103 | WARNING | [x] There must be no blank line following an inline comment
103 | WARNING | [ ] There must be no blank line following an inline comment
103 | ERROR | [x] No space found before comment text; expected "// $this->config('menu.entity.node.' . $node->getType())->set('available_menus', ['main-menu'])->save();" but found "//$this->config('menu.entity.node.' .
| | $node->getType())->set('available_menus', ['main-menu'])->save();"
140 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
157 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
168 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
175 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
177 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
200 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
209 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
233 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
243 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
264 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
291 | ERROR | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
293 | ERROR | [x] Visibility must be declared on method "testMultilingualMenu"
332 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
342 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
353 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
383 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
384 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
385 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
386 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
387 | ERROR | [x] Array closing indentation error, expected 4 spaces but found 6
414 | ERROR | [x] Comment indentation error after - element, expected 5 spaces
414 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
424 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
425 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
430 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
431 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
432 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
437 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
438 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
439 | ERROR | [x] Array indentation error, expected 6 spaces but found 8
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 21 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Proposed resolution
Get rid of t() calls in tests.
Comment | File | Size | Author |
---|---|---|---|
#5 | use_stringTranslationTrait-3074364-5.patch | 6.43 KB | ngkoutsaik |
Issue fork token-3074364
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
thallesFollow a patch adding the StringTranstalationTrait and fixing other things.
Comment #3
ngkoutsaik CreditAttribution: ngkoutsaik at Agiledrop - Your Trusted Drupal Teammates commentedHi,
Thanks for the patch. I reviewed it but could not apply it. I had to reroll the patch. Additionally I had some conflicts to solve.
Comment #4
ngkoutsaik CreditAttribution: ngkoutsaik at Agiledrop - Your Trusted Drupal Teammates commentedComment #5
ngkoutsaik CreditAttribution: ngkoutsaik at Agiledrop - Your Trusted Drupal Teammates commentedAs said above I had conflicts and errors with rolling the patch. SO I went ahead and made new one.
Please let me know if I missed anything.
Comment #6
thallesLooks good to me!
Comment #7
BerdirThis is a test, we should instead just remove t() completely from it.
Comment #8
Matroskeen#7 makes perfect sense. Let's change the scope here
Comment #10
MatroskeenMR is open and ready for review.
(please ignore PHP8 test)
Comment #11
MatroskeenComment #13
BerdirThanks. Merged.