You are here

function TokenTestHelper::assertPageTokens in Token 7

Same name and namespace in other branches
  1. 6 token.test \TokenTestHelper::assertPageTokens()

Make a page request and test for token generation.

1 call to TokenTestHelper::assertPageTokens()
TokenCurrentPageTestCase::testCurrentPageTokens in ./token.test

File

./token.test, line 85
Test integration for the token module.

Class

TokenTestHelper
Helper test class with some added functions for testing.

Code

function assertPageTokens($url, array $tokens, array $data = array(), 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,
      )));
    }
  }
}