function FileEntityTokenTestCase::assertTokens in File Entity (fieldable files) 7.3
Same name and namespace in other branches
- 7 tests/file_entity.test \FileEntityTokenTestCase::assertTokens()
- 7.2 file_entity.test \FileEntityTokenTestCase::assertTokens()
1 call to FileEntityTokenTestCase::assertTokens()
File
- ./
file_entity.test, line 1140 - Test integration for the file_entity module.
Class
- FileEntityTokenTestCase
- Tests file entity tokens.
Code
function assertTokens($type, array $data, array $tokens, array $options = array()) {
$token_input = drupal_map_assoc(array_keys($tokens));
$values = token_generate($type, $token_input, $data, $options);
foreach ($tokens as $token => $expected) {
if (!isset($expected)) {
$this
->assertTrue(!isset($values[$token]), t("Token value for [@type:@token] was not generated.", array(
'@type' => $type,
'@token' => $token,
)));
}
elseif (!isset($values[$token])) {
$this
->fail(t("Token value for [@type:@token] was not generated.", array(
'@type' => $type,
'@token' => $token,
)));
}
elseif (!empty($options['regex'])) {
$this
->assertTrue(preg_match('/^' . $expected . '$/', $values[$token]), t("Token value for [@type:@token] was '@actual', matching regular expression pattern '@expected'.", array(
'@type' => $type,
'@token' => $token,
'@actual' => $values[$token],
'@expected' => $expected,
)));
}
else {
$this
->assertIdentical($values[$token], $expected, t("Token value for [@type:@token] was '@actual', expected value '@expected'.", array(
'@type' => $type,
'@token' => $token,
'@actual' => $values[$token],
'@expected' => $expected,
)));
}
}
return $values;
}