You are here

function WorkbenchAccessTokenTestCase::assertTokens in Workbench Access 7

Function copied from TokenTestHelper::assertTokens().

1 call to WorkbenchAccessTokenTestCase::assertTokens()
WorkbenchAccessTokenTestCase::testTaxonomyTokens in tests/workbench_access.test

File

tests/workbench_access.test, line 974
Test file for Workbench Access.

Class

WorkbenchAccessTokenTestCase

Code

function assertTokens($type, array $data, array $tokens, array $options = array()) {
  $token_input = drupal_map_assoc(array_keys($tokens));
  $values = token_generate($type, $token_input, $data, $options);
  foreach ($tokens as $token => $expected) {
    if (!isset($expected)) {
      $this
        ->assertTrue(!isset($values[$token]), t("Token value for [@type:@token] was not generated.", array(
        '@type' => $type,
        '@token' => $token,
      )));
    }
    elseif (!isset($values[$token])) {
      $this
        ->fail(t("Token value for [@type:@token] was not generated.", array(
        '@type' => $type,
        '@token' => $token,
      )));
    }
    elseif (!empty($options['regex'])) {
      $this
        ->assertTrue(preg_match('/^' . $expected . '$/', $values[$token]), t("Token value for [@type:@token] was '@actual', matching regular expression pattern '@expected'.", array(
        '@type' => $type,
        '@token' => $token,
        '@actual' => $values[$token],
        '@expected' => $expected,
      )));
    }
    else {
      $this
        ->assertIdentical($values[$token], $expected, t("Token value for [@type:@token] was '@actual', expected value '@expected'.", array(
        '@type' => $type,
        '@token' => $token,
        '@actual' => $values[$token],
        '@expected' => $expected,
      )));
    }
  }
  return $values;
}