Problem/Motivation
Status
The issue has been open since 2009. It has consensus and the approval of SimpleTest maintainers, and is already part of our documented standard:
http://drupal.org/simpletest-tutorial-drupal7#t
Details
- The
$message
parameter of SimpleTest assertions (e.g., DrupalTestCase::assertTrue()) is a string displayed only in the administrative UI or on the commandline following test runs, and on testbot. - This parameter is never translated, so using
t()
on it is needless overhead. - We have other instances in core where string function parameters should not be wrapped in
t()
, e.g. watchdog(). - When the assertion message is a plain string,
t()
should simply be omitted. - When the assertion message contains placeholders for variables,
format_string()
should be used instead.
Proposed resolution
- Strip
t()
from plain-string assertion messages that are still using it.<?php
$this->assertWhatever($condition, t('My custom message here'));
?>Becomes:
<?php
$this->assertWhatever($condition, 'My custom message here');
?>- Assertion messages that have placeholders or variables will be converted to
format_string()
. This can be done separately if the patch is particularly large. (Mark issues that have already had messages with placeholders converted in the list below.) - Other parameters of assertions (beside the message parameter) are not changed.
- Other uses of t() in automated tests are not changed.
- Discuss other uses of
t()
in tests in a separate issue. - Consider documenting this practice in the parameter documentation for assertions in a followup issue.
Remaining tasks
- Generate patches stripping
t()
from plain-string assertion messages only (issues below). - Review these patch closely to ensure there are no incorrect changes. Applying locally and using
git diff --color-words
works well. - Address assertion messages with placeholders separately if the patch is large.
- Address followup issues separately.
- Post a change notice.
What parts of core are affected?
- Only automated test methods are affected.
- There are approximately 3400 assertion messages that need to be corrected.
- The following modules have tests that will be patched:
Base classes: #1601146: Allow custom assertion messages using predefined placeholders and/or #1803674: Remove t() from default test assertions in TestBase class*
action #1798954: Remove t() from test asserts in Action module [part of system tests in d7]*
aggregator #1741328: Remove t() from asserts messages in tests for aggregator module*
ban #1798960: Remove t() from test asserts in Ban module [system module include in D7]*
block #1741338: Removing t() from asserts in simpletests in block module*
book #1741386: Removing t() from asserts in simpletests in book module*
comment #1742602: Removing t() from asserts in simpletests in comment module*
config #1797228: Remove t() from assertion messages in config module tests*
contact #1742830: Removing t() from asserts in simpletests in contact module*
dblog #1797242: Remove t() from assertion messages in dblog module tests*
field #1797106: Remove t() from asserts messages in tests for the Field module*
field_ui #1797170: Remove t() from assertion messages in tests for field_ui.module*
file #1797252: Remove t() from assertion messages in file module tests*
filter #1797272: Remove t() from asserts messages in tests for the filter module*
forum #1797286: Remove t() from assertion messages in tests for the forum module*
help #1797330: Remove t() from assertion messages in tests for the help module*
image #1797328: Remove t() from assertion messages in tests for the image module*
language #1797360: Remove t() from assertion messages in tests for the language module*
locale #1797364: Remove t() from assertion messages in tests for the locale module*
menu #1797366: Remove t() from assertion messages in tests for the menu module*
node #1797200: Remove t() from assertion messages in node.module tests
openid #1797370: Remove t() from assertion messages in tests for the openid module*
path #1797372: Remove t() from assertion messages in tests for the path module*
php #1797374: Remove t() from assertion messages in tests for the php module*
poll #1797376: Remove t() from assertion messages in tests for the poll module*
rdf #1797506: Remove t() from assertion messages in tests for the rdf module*
search #1797508: Remove t() from assertion messages in tests for the Search module*
shortcut #1797510: Remove t() from assertion messages in tests for the shortcut module*
simpletest #1797514: Remove t() from assertion messages in tests for the simpletest module*
statistics #1797520: Remove t() from assertion messages in tests for the statistics module*
syslog #1797516: Remove t() from assertion messages in tests for the syslog module*
system, including the following sub-systems:
#1797120: Remove t() from asserts for A-C includes system tests*
#1794012: Remove t() from asserts for database system tests*
#1797220: Remove t() from asserts from Entity sub-system tests*
#1797296: Remove t() from asserts from File system tests*
#1797318: Remove t() from asserts from Form sub-system tests*
#1797410: Remove t() from asserts for G-L includes system tests*
#1797452: Remove t() from asserts for M includes system tests*
#1797914: Remove t() from asserts for P-S includes system tests*
#1797926: Remove t() from asserts from System sub-system tests*
#1797920: Remove t() from asserts for T-Z includes system tests*
taxonomy #1195254: Taxonomy test cleanup*
tracker #1798366: Remove t() from test asserts in Tracker mdoule*
translation #1798376: Remove t() from test asserts in Translation module*
update #1798384: Remove t() from test asserts in Update module*
user #1798386: Remove t() from test asserts in User module*
xmlrpc #1798390: Remove t() from test asserts in Xmlrpc module*
views & views_ui #2035087: removing t() from asserts - remaining views and views_ui changes*
the remainder (Drupal 8) #2035077: removing t() from asserts - remaining changes.*
#2059691: Remove t() from assertion messages in tests for the trigger module
#2059689: Remove t() from assertion messages in tests for the profile module
#2059687: Remove t() from assertion messages in tests for the blog module
#2059685: Remove t() from assertion messages in tests for the dashboard module
#2059693: Remove t() from assertion messages in Drupal 7 tests - remaining changes
#2552067: Remove t() from assertion messages in tests
Issues with * already includeformat_string()
replacements.
How will we avoid conflicts with important patches?
- Testing in July shows=ed that only 4 patches out of 900-some NR 8.x issues were affected by this change.
- There is no affect on patches that do not include changes to existing automated tests.
- With no moved files or lines and a simple 1:1 assertion/deletion, the change is straightforward enough that, in most cases, patches and sandboxes can simply be rebased to make them apply on top of the change.
- We will ensure all issues with the Avoid commit conflicts tag have a compatible reroll in the issue before the change is committed. If you have an important outstanding issue that is close to being RTBC, please add this tag to that issue.
- If you have an important sandbox for which we should avoid merge conflicts, please post a comment below. Link the sandbox's project page and identify the relevant branch(es).
Related issues
- #1799326: Clean up $group usage in simpletests
- #983528: support $group and $message parameters in all assert() functions
- #1797940: Fix docs for helper method in language tests
Original report by neochief
Hello.
As one of the active Russian translators, I can state that translation of simpletests asserts' descriptions is totally useless (as it was once before in Schema descriptions). People who run tests are familiar with English.
Maybe we should consider removing those t() from our tests?