function PathautoTokenTestCase::assertTokens in Pathauto 7
Function copied from TokenTestHelper::assertTokens().
1 call to PathautoTokenTestCase::assertTokens()
File
- ./
pathauto.test, line 946 - Functionality tests for Pathauto.
Class
- PathautoTokenTestCase
- Token functionality tests.
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;
}