While working on #554088: Move user_mail_tokens() and emails to token system I ran into problems with undefined variables when using token_replace
From user.tokens.inc:
function user_tokens($type, $tokens, array $data = array(), array $options = array()) {
global $user;
$url_options = array('absolute' => TRUE);
if (isset($options['language'])) {
$url_options['language'] = $language;
$language_code = $language->language;
}
else {
$language_code = NULL;
}
When token_replace is called with 'language' defined in the $options-array, this will result in a PHP notice: undefined variable language.
The same approach is used for comment_tokens and node_tokens.
Comments
Comment #1
sunAwesome.
Comment #2
dries commentedWe should probably improve our token tests in ./modules/system/system.test?
Comment #3
sunuhm.
ok, I understand that we don't have any tests for tokens at all yet.
But with a request for language dependent tests you're even screwing up me. :P
For that... let me brainstorm...
We'd need a system object that's available in two languages. Menus and system variables don't count, as Drupal core doesn't support translation/localization for them. (which still is totally wonky)
Leaving us with nodes, comments, and users. Well, comments and users are hard to translate as well.
Leaving us with nodes.
Hence, a test that installs Translation module, creates a node, translates that into another language, and uses the node title to check whether tokens are generated properly.
Ugh.
Comment #4
dries commentedSorry, I assumed that we did have some tests in ./modules/system/system.test and that it would be relatively easy to add a test for this. If that is a false assumption, I'm happy to proceed without tests for now.
Comment #5
sunSomehow, my grep for "token" didn't find "TokenReplaceTestCase".
So this patch should fail.
Comment #7
sunAlright. And merging both patches should pass. :)
Comment #8
dries commentedCommitted. Thanks.