function TokenTestHelper::assertPageTokens in Token 6
Same name and namespace in other branches
- 7 token.test \TokenTestHelper::assertPageTokens()
Make a page request and test for token generation.
1 call to TokenTestHelper::assertPageTokens()
File
- ./
token.test, line 45 - Tests for the token module.
Class
- TokenTestHelper
- Helper test class with some added functions for testing.
Code
function assertPageTokens($url, array $tokens, array $data = array(
'global' => NULL,
), array $options = array()) {
if (empty($tokens)) {
return TRUE;
}
$token_page_tokens = array(
'tokens' => $tokens,
'data' => $data,
'options' => $options,
);
variable_set('token_page_tokens', $token_page_tokens);
$options += array(
'url_options' => array(),
);
$this
->drupalGet($url, $options['url_options']);
$this
->refreshVariables();
$result = variable_get('token_page_tokens', array());
if (!isset($result['values']) || !is_array($result['values'])) {
return $this
->fail('Failed to generate tokens.');
}
foreach ($tokens as $token => $expected) {
if (!isset($expected)) {
$this
->assertTrue(!isset($result['values'][$token]) || $result['values'][$token] === $token, t("Token value for @token was not generated.", array(
'@token' => $token,
)));
}
elseif (!isset($result['values'][$token])) {
$this
->fail(t('Failed to generate token @token.', array(
'@token' => $token,
)));
}
else {
$this
->assertIdentical($result['values'][$token], (string) $expected, t("Token value for @token was '@actual', expected value '@expected'.", array(
'@token' => $token,
'@actual' => $result['values'][$token],
'@expected' => $expected,
)));
}
}
}