1 token.test TokenTestHelper::assertTokens($type, array $data, array $tokens, array $options = array())

File

core/modules/simpletest/tests/token.test, line 204
Test integration for the token module.

Class

TokenTestHelper
Helper test class with some added functions for testing.

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($replacements[$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;
}