public function TokenUnitTestCase::testGetInvalidTokens in Token 6
Same name and namespace in other branches
- 7 token.test \TokenUnitTestCase::testGetInvalidTokens()
Test token_get_invalid_tokens() and token_get_invalid_tokens_by_context().
File
- ./
token.test, line 92 - Tests for the token module.
Class
Code
public function testGetInvalidTokens() {
$tests = array();
$tests[] = array(
'valid tokens' => array(
'[title-raw]',
'[yyyy]',
'[mod-yyyy]',
'[site-name]',
'[site-slogan]',
'[user-id]',
),
'invalid tokens' => array(
'[title-invalid]',
'[invalid]',
'[mod-invalid]',
'[invalid-title]',
'[site-invalid]',
'[uid]',
'[comment-cid]',
),
'types' => array(
'node',
),
);
$tests[] = array(
'valid tokens' => array(
'[title-raw]',
'[yyyy]',
'[mod-yyyy]',
'[site-name]',
'[site-slogan]',
'[user-id]',
'[uid]',
'[comment-cid]',
),
'invalid tokens' => array(
'[title-invalid]',
'[invalid]',
'[mod-invalid]',
'[invalid-title]',
'[site-invalid]',
),
'types' => array(
'all',
),
);
$tests[] = array(
'valid tokens' => array(
'[alpha]',
'[beta-1]',
'[beta-2]',
'[gamma_A]',
'[delta-extra]',
'[epsilon-zeta-A]',
),
'invalid tokens' => array(
'[alpha-plus]',
'[beta]',
'[beta-]',
'[beta_]',
'[beta_1]',
'[beta-A]',
'[gamma]',
'[gamma_]',
'[gamma-A]',
'[delta]',
'[epsilon-zeta-]',
),
'types' => array(
'all',
),
);
foreach ($tests as $test) {
$tokens = array_merge($test['valid tokens'], $test['invalid tokens']);
shuffle($tokens);
$invalid_tokens = token_get_invalid_tokens_by_context(implode(' ', $tokens), $test['types']);
sort($invalid_tokens);
sort($test['invalid tokens']);
$this
->assertEqual($invalid_tokens, $test['invalid tokens'], 'Invalid tokens detected properly: ' . implode(', ', $invalid_tokens));
}
}