Discuss t() in tests

Created on 22 February 2025, 14 days ago

Problem/Motivation

Following up from various core issues about the usage of t(). It was decided that, for core, t() in tests should only be used for testing translations. Should this be a standard and enforced?

One of the issues resulted in When to use t() in browser tests being updated with what core does.

Benefits

If we adopted this change, the Drupal Project would benefit by ...

Three supporters required

  1. https://www.drupal.org/u/ {userid} (yyyy-mm-dd they added support)
  2. https://www.drupal.org/u/ {userid} (yyyy-mm-dd they added support)
  3. https://www.drupal.org/u/ {userid} (yyyy-mm-dd they added support)

Proposed changes

Provide all proposed changes to the Drupal Coding standards . Give a link to each section that will be changed, and show the current text and proposed text as in the following layout:

1. {link to the documentation heading that is to change}

Add current text in blockquotes

Add proposed text in blockquotes

2. Repeat the above for each page or sub-page that needs to be changed.

Remaining tasks

  1. Add supporters
  2. Create a Change Record
  3. Review by the Coding Standards Committee
  4. Coding Standards Committee takes action as required
  5. Discussed by the Core Committer Committee, if it impacts Drupal Core
  6. Final review by Coding Standards Committee
  7. Documentation updates
    1. Edit all pages
    2. Publish change record
    3. Remove 'Needs documentation edits' tag
  8. If applicable, create follow-up issues for PHPCS rules/sniffs changes

For a full explanation of these steps see the Coding Standards project page

📌 Task
Status

Active

Component

Coding Standards

Created by

🇳🇿New Zealand quietone

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @quietone
  • 🇦🇹Austria drunken monkey Vienna, Austria

    I think this decision makes sense and it should also be enforced. I guess this means that it should be a standard.
    However, the only page we have about testing standards is called Drupal SimpleTest coding standards and mainly lists things relevant for Drupal 6 and 7, so I think we might have more to do here than add a line about not using t().

  • 🇳🇿New Zealand quietone

    How will the sniff know that the test is actually testing translations?

    I updated the IS with proposed text.

    As for removing the Drupal 6/7 outdated material from the standards docs, I think we can discuss that at a meeting.

  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    How will the sniff know that the test is actually testing translations?

    Since removing t function calls from tests is a performance improvement it might make sense to try figuring that out though. Maybe we should allow it only when in *TranslationTest.php?

Production build 0.71.5 2024