1 token.test TokenTestHelper::assertPageTokens($url, array $tokens, array $data = array(), array $options = array())

Make a page request and test for token generation.

File

core/modules/simpletest/tests/token.test, line 261
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,
  );

  state_set('page_tokens', $token_page_tokens);

  $options += array('url_options' => array());
  $this->backdropGet($url, $options['url_options']);
  $result = state_get('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)));
    }
  }
}