summaryrefslogtreecommitdiff
path: root/modules/node/node.test
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-04-20 09:48:06 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-04-20 09:48:06 +0000
commit7bb6753e9fc8d89472ecc2b6d5ab670dde27b935 (patch)
tree79eae1caf8b93351560fa36202d46913ac06e1ef /modules/node/node.test
parent8e94b5d6d400d33c0f840a7ae97ff8a715272a79 (diff)
downloadbrdo-7bb6753e9fc8d89472ecc2b6d5ab670dde27b935.tar.gz
brdo-7bb6753e9fc8d89472ecc2b6d5ab670dde27b935.tar.bz2
#701818 by mcarbone: Test coverage of every core token, and bug fixes to make them work. AWESOME! :D
Diffstat (limited to 'modules/node/node.test')
-rw-r--r--modules/node/node.test76
1 files changed, 76 insertions, 0 deletions
diff --git a/modules/node/node.test b/modules/node/node.test
index 053a5968c..5f215d321 100644
--- a/modules/node/node.test
+++ b/modules/node/node.test
@@ -1666,3 +1666,79 @@ class NodeQueryAlter extends DrupalWebTestCase {
}
}
}
+
+/**
+ * Test node token replacement in strings.
+ */
+class NodeTokenReplaceTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Node token replacement',
+ 'description' => 'Generates text using placeholders for dummy content to check node token replacement.',
+ 'group' => 'Node',
+ );
+ }
+
+ /**
+ * Creates a node, then tests the tokens generated from it.
+ */
+ function testNodeTokenReplacement() {
+ global $language;
+ $url_options = array(
+ 'absolute' => TRUE,
+ 'language' => $language,
+ );
+
+ // Create a user and a node.
+ $account = $this->drupalCreateUser();
+ $settings = array(
+ 'type' => 'article',
+ 'uid' => $account->uid,
+ 'title' => '<blink>Blinking Text</blink>',
+ 'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(32), 'summary' => $this->randomName(16)))),
+ );
+ $node = $this->drupalCreateNode($settings);
+
+ // Load node so that the body and summary fields are structured properly.
+ $node = node_load($node->nid);
+ $instance = field_info_instance('node', 'body', $node->type);
+
+ // Generate and test sanitized tokens.
+ $tests = array();
+ $tests['[node:nid]'] = $node->nid;
+ $tests['[node:vid]'] = $node->vid;
+ $tests['[node:tnid]'] = $node->tnid;
+ $tests['[node:uid]'] = $node->uid;
+ $tests['[node:type]'] = 'article';
+ $tests['[node:type-name]'] = 'Article';
+ $tests['[node:title]'] = check_plain($node->title);
+ $tests['[node:body]'] = _text_sanitize($instance, $node->language, $node->body[$node->language][0], 'value');
+ $tests['[node:summary]'] = _text_sanitize($instance, $node->language, $node->body[$node->language][0], 'summary');
+ $tests['[node:language]'] = check_plain($node->language);
+ $tests['[node:url]'] = url('node/' . $node->nid, $url_options);
+ $tests['[node:edit-url]'] = url('node/' . $node->nid . '/edit', $url_options);
+ $tests['[node:author:name]'] = check_plain($account->name);
+ $tests['[node:created:since]'] = format_interval(REQUEST_TIME - $node->created, 2, $language->language);
+ $tests['[node:changed:since]'] = format_interval(REQUEST_TIME - $node->changed, 2, $language->language);
+
+ // Test to make sure that we generated something for each token.
+ $this->assertFalse(in_array(0, array_map('strlen', $tests)), t('No empty tokens generated.'));
+
+ foreach ($tests as $input => $expected) {
+ $output = token_replace($input, array('node' => $node), array('language' => $language));
+ $this->assertFalse(strcmp($output, $expected), t('Sanitized node token %token replaced.', array('%token' => $input)));
+ }
+
+ // Generate and test unsanitized tokens.
+ $tests['[node:title]'] = $node->title;
+ $tests['[node:body]'] = $node->body[$node->language][0]['value'];
+ $tests['[node:summary]'] = $node->body[$node->language][0]['summary'];
+ $tests['[node:language]'] = $node->language;
+ $tests['[node:author:name]'] = $account->name;
+
+ foreach ($tests as $input => $expected) {
+ $output = token_replace($input, array('node' => $node), array('language' => $language, 'sanitize' => FALSE));
+ $this->assertFalse(strcmp($output, $expected), t('Unsanitized node token %token replaced.', array('%token' => $input)));
+ }
+ }
+}