Problem/Motivation

Use function t() on tests

Proposed resolution

Use $this->t() of StringTranslationTrait on tests

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thalles created an issue. See original summary.

Berdir’s picture

Never heard of that rule?

In most cases, t() in tests can simply be removed.

thalles’s picture

I thought it was strange, but the phpps pointed this out, see:

IFILE: /home/thallesvf/Desktop/lando/d8-contrib/modules/token/src/Tests/TokenMenuTest.php
-------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 20 ERRORS AND 17 WARNINGS AFFECTING 32 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------
   9 | WARNING | [x] Unused use statement
  34 | ERROR   | [x] Visibility must be declared on method "testMenuTokens"
  34 | ERROR   | [x] Missing function doc comment
 102 | WARNING | [ ] Line exceeds 80 characters; contains 107 characters
 102 | WARNING | [x] There must be no blank line following an inline comment
 102 | WARNING | [ ] There must be no blank line following an inline comment
 102 | 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();"
 139 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 156 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 167 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 174 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 176 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 199 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 208 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 232 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 242 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 263 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 290 | ERROR   | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
 292 | ERROR   | [x] Visibility must be declared on method "testMultilingualMenu"
 331 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 341 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 352 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 382 | ERROR   | [x] Array indentation error, expected 6 spaces but found 8
 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 closing indentation error, expected 4 spaces but found 6
 413 | ERROR   | [x] Comment indentation error after - element, expected 5 spaces
 413 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 423 | ERROR   | [x] Array indentation error, expected 6 spaces but found 8
 424 | ERROR   | [x] Array indentation error, expected 6 spaces but found 8
 429 | 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
 436 | 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
-------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 21 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------
thalles’s picture

I thought it was strange, but the phpps pointed this out, see:

IFILE: /home/thallesvf/Desktop/lando/d8-contrib/modules/token/src/Tests/TokenMenuTest.php
-------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 20 ERRORS AND 17 WARNINGS AFFECTING 32 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------
   9 | WARNING | [x] Unused use statement
  34 | ERROR   | [x] Visibility must be declared on method "testMenuTokens"
  34 | ERROR   | [x] Missing function doc comment
 102 | WARNING | [ ] Line exceeds 80 characters; contains 107 characters
 102 | WARNING | [x] There must be no blank line following an inline comment
 102 | WARNING | [ ] There must be no blank line following an inline comment
 102 | 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();"
 139 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 156 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 167 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 174 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 176 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 199 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 208 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 232 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 242 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 263 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 290 | ERROR   | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
 292 | ERROR   | [x] Visibility must be declared on method "testMultilingualMenu"
 331 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 341 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 352 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 382 | ERROR   | [x] Array indentation error, expected 6 spaces but found 8
 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 closing indentation error, expected 4 spaces but found 6
 413 | ERROR   | [x] Comment indentation error after - element, expected 5 spaces
 413 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 423 | ERROR   | [x] Array indentation error, expected 6 spaces but found 8
 424 | ERROR   | [x] Array indentation error, expected 6 spaces but found 8
 429 | 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
 436 | 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
-------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 21 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------
Berdir’s picture

Title: Use $this->t() of StringTranslationTrait on tests » Convert simpletest tests to phpunit/browser tests

Ah, I see, that's because it just does that for all classes, no matter what, and these are old simpletest that live in the src folder. It would like stop doing that if they were in tests/src as phpunit tests, which is the real action that needs to be done.

Plus, in 99% of the cases, t() can just be removed in tests. But better not in the same issue.

Berdir’s picture

Status: Needs work » Needs review
FileSize
11.1 KB

This was a relatively easy one.

Berdir’s picture

Berdir’s picture

Status: Needs review » Fixed

Committed.

  • Berdir committed 1cadac2 on 8.x-1.x
    Issue #3061605 by Berdir: Convert simpletest tests to phpunit/browser...

Status: Fixed » Closed (fixed)

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