1 path_pattern.test PathPatternTokenTestCase::assertTokens($type, array $data, array $tokens, array $options = array())

Function copied from TokenTestHelper::assertTokens().

File

core/modules/path/tests/path_pattern.test, line 1156
Functionality tests for automatic path generation.

Class

PathPatternTokenTestCase
Token functionality tests.

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($values[$token]), format_string("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]), format_string("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, format_string("Token value for @token was '@actual', expected value '@expected'.", array('@type' => $type, '@token' => $token, '@actual' => $replacements[$token], '@expected' => $expected)));
    }
  }

  return $replacements;
}