1

All Simpletest documentation and examples use the t() function for clickLink() or assertText() for example. However when I read the core issue about testing not working when locale of host session is not English and the patch that got committed (tl;dr it forces English to be the default language) I'm curious if it's really necessary.

MegaChriz has an interesting take on this, as he doesn't t() his string in Feeds tests. Extract from his comment as to why:

In most cases, the "final" text is checked, thus the text for which the translation placeholders have already been replaced. So there is no original translation string to check for. If I remember well, there were also occasions where only a portion of the text was checked. Since tests are always run in English (at least, by my knowledge), this should have no harm.

If the default language is English, can't we simply remove the t() function from testing? Please note that I'm not looking for opinions but for facts.

1 Answer 1

2

I know for a fact (though it is probably not the only reason) that t() allows for replacement arguments:

echo t('my %string', ('%string' => 'Foo'));

Which renders as: 'my Foo' (emphasized text).

If you were to use such placeholders on your site, they will not work unless you wrap them through t() or format_string() (where t() is much much shorter).

Here comes the opinion part; if you only were to use plain text strings it probably wouldn't matter. But if you use t() on the front end with formatting and you would compare that value in the backend with a plain text string, it wouldn't match. And writing all tests to use format_string() instead would be very confusing.

In the end it all depends on your situation and your tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.