assertTokens($type, $object, array($token => $expected), $options); } function assertTokens($type, $object, array $tokens, array $options = array()) { $token_input = drupal_map_assoc(array_keys($tokens)); $values = token_generate($type, $token_input, array($type => $object), $options); foreach ($tokens as $token => $expected) { $this->assertIdentical($values[$token], $expected, t("Token value for [@token] was '!actual', expected value '!expected'.", array('@token' => $token, '!actual' => $values[$token], '!expected' => $expected))); } } } class TokenUnitTestCase extends TokenTestHelper { public static function getInfo() { return array( 'name' => 'Token unit tests', 'description' => 'Test basic, low-level token functions.', 'group' => 'Token', ); } /** * Test token_get_invalid_tokens() and token_get_invalid_tokens_by_context(). */ public function testGetInvalidTokens() { $tests = array(); $tests[] = array( 'valid tokens' => array( '[node:title]', '[node:created:short]', '[node:created:custom:invalid]', '[node:created:custom:mm-YYYY]', '[site:name]', '[site:slogan]', ), 'invalid tokens' => array( '[node:title:invalid]', '[node:created:invalid]', '[node:created:short:invalid]', '[invalid:title]', '[site:invalid]', ), 'types' => array('node'), ); foreach ($tests as $test) { $tokens = array_merge($test['valid tokens'], $test['invalid tokens']); shuffle($tokens); $invalid_tokens = token_get_invalid_tokens_by_context(implode(' ', $tokens), $test['types']); sort($invalid_tokens); sort($test['invalid tokens']); $this->assertEqual($invalid_tokens, $test['invalid tokens'], 'Invalid tokens detected properly.'); } } } class TokenNodeTestCase extends TokenTestHelper { public static function getInfo() { return array( 'name' => 'Node token tests', 'description' => 'Test the node tokens.', 'group' => 'Token', ); } function testSource() { $source_node = $this->drupalCreateNode(); $translated_node = $this->drupalCreateNode(array('tnid' => $source_node->nid)); $this->assertToken('node', $translated_node, 'source', $source_node->title); $this->assertToken('node', $translated_node, 'source:nid', $source_node->nid); //$this->assertToken('node', $source_node, 'source', '', array('clear' => TRUE)); } }