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.

Issue fork token-3074364

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thalles created an issue. See original summary.

thalles’s picture

Status: Needs work » Needs review
FileSize
9.81 KB

Follow a patch adding the StringTranstalationTrait and fixing other things.

ngkoutsaik’s picture

Hi,

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.

use Behat\Mink\Element\NodeElement;
<<<<<<< HEAD
=======
use Drupal\Core\StringTranslation\StringTranslationTrait;
>>>>>>> Applying patch from issue 3074364 comment 2
use Drupal\Core\Url;
ngkoutsaik’s picture

Status: Needs review » Needs work
ngkoutsaik’s picture

Status: Needs work » Needs review
FileSize
6.43 KB

As 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.

thalles’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me!

Berdir’s picture

Status: Reviewed & tested by the community » Needs work

This is a test, we should instead just remove t() completely from it.

Matroskeen’s picture

Title: Use $this->t() of StringTranslationTrait » Remove t() calls from functional tests
Assigned: Unassigned » Matroskeen
Issue summary: View changes

#7 makes perfect sense. Let's change the scope here

Matroskeen’s picture

Title: Remove t() calls from functional tests » Remove t() calls from tests
Issue summary: View changes
Status: Needs work » Needs review

MR is open and ready for review.
(please ignore PHP8 test)

Matroskeen’s picture

Assigned: Matroskeen » Unassigned

  • Berdir committed 2b505bd on 8.x-1.x authored by Matroskeen
    Issue #3074364 by Matroskeen, thalles, ngkoutsaik: Remove t() calls from...
Berdir’s picture

Status: Needs review » Fixed

Thanks. Merged.

Status: Fixed » Closed (fixed)

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