function TokenTestHelper::assertTokens in Token 7
Same name and namespace in other branches
- 6 token.test \TokenTestHelper::assertTokens()
14 calls to TokenTestHelper::assertTokens()
- TokenArrayTestCase::testArrayTokens in ./
token.test - TokenCommentTestCase::testCommentTokens in ./
token.test - TokenDateTestCase::testDateTokens in ./
token.test - TokenEntityTestCase::testEntityOriginal in ./
token.test - Test the [entity:original:*] tokens.
- TokenFileTestCase::testFileTokens in ./
token.test
File
- ./
token.test, line 27 - Test integration for the token module.
Class
- TokenTestHelper
- Helper test class with some added functions for testing.
Code
function assertTokens($type, array $data, array $tokens, array $options = array()) {
$input = $this
->mapTokenNames($type, array_keys($tokens));
$replacements = token_generate($type, $input, $data, $options);
foreach ($tokens as $name => $expected) {
$token = $input[$name];
if (!isset($expected)) {
$this
->assertTrue(!isset($values[$token]), t("Token value for @token was not generated.", array(
'@type' => $type,
'@token' => $token,
)));
}
elseif (!isset($replacements[$token])) {
$this
->fail(t("Token value for @token was not generated.", array(
'@type' => $type,
'@token' => $token,
)));
}
elseif (!empty($options['regex'])) {
$this
->assertTrue(preg_match('/^' . $expected . '$/', $replacements[$token]), t("Token value for @token was '@actual', matching regular expression pattern '@expected'.", array(
'@type' => $type,
'@token' => $token,
'@actual' => $replacements[$token],
'@expected' => $expected,
)));
}
else {
$this
->assertIdentical($replacements[$token], $expected, t("Token value for @token was '@actual', expected value '@expected'.", array(
'@type' => $type,
'@token' => $token,
'@actual' => $replacements[$token],
'@expected' => $expected,
)));
}
}
return $replacements;
}