summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-03-12 14:33:02 +0000
committerDries Buytaert <dries@buytaert.net>2010-03-12 14:33:02 +0000
commitd8e62ff260991b911a05092d285aa6a31cdb8229 (patch)
tree08f0ca9aa575a37ce6ed0c3f622988e757a8b3fb
parent4f0e59e1ccc50ed983c348b3917514d6131cc29e (diff)
downloadbrdo-d8e62ff260991b911a05092d285aa6a31cdb8229.tar.gz
brdo-d8e62ff260991b911a05092d285aa6a31cdb8229.tar.bz2
- Patch #681782 by Dave Reid: 'clean' option in token_replace() does not do anything.
-rw-r--r--includes/token.inc3
-rw-r--r--modules/system/system.test16
2 files changed, 13 insertions, 6 deletions
diff --git a/includes/token.inc b/includes/token.inc
index 3f9a5b5ce..2db6c78c9 100644
--- a/includes/token.inc
+++ b/includes/token.inc
@@ -78,6 +78,9 @@ function token_replace($text, array $data = array(), array $options = array()) {
$replacements = array();
foreach (token_scan($text) as $type => $tokens) {
$replacements += token_generate($type, $tokens, $data, $options);
+ if (!empty($options['clear'])) {
+ $replacements += array_fill_keys($tokens, '');
+ }
}
// Optionally alter the list of replacement values.
diff --git a/modules/system/system.test b/modules/system/system.test
index c5366c541..049502194 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -1449,26 +1449,30 @@ class TokenReplaceTestCase extends DrupalWebTestCase {
$source .= '[node:author:name]'; // Node author's name
$source .= '[node:created:since]'; // Time since the node was created
$source .= '[current-user:name]'; // Current user's name
- $source .= '[user:name]'; // No user passed in, should be untouched
$source .= '[date:short]'; // Short date format of REQUEST_TIME
- $source .= '[bogus:token]'; // Nonexistent token, should be untouched
+ $source .= '[user:name]'; // No user passed in, should be untouched
+ $source .= '[bogus:token]'; // Non-existent token
$target = check_plain($node->title);
$target .= check_plain($account->name);
$target .= format_interval(REQUEST_TIME - $node->created, 2, $language->language);
$target .= check_plain($user->name);
- $target .= '[user:name]';
$target .= format_date(REQUEST_TIME, 'short', '', NULL, $language->language);
- $target .= '[bogus:token]';
+ // Test that the clear parameter cleans out non-existent tokens.
+ $result = token_replace($source, array('node' => $node), array('language' => $language, 'clear' => TRUE));
+ $result = $this->assertFalse(strcmp($target, $result), 'Valid tokens replaced while invalid tokens cleared out.');
+
+ // Test without using the clear parameter (non-existant token untouched).
+ $target .= '[user:name]';
+ $target .= '[bogus:token]';
$result = token_replace($source, array('node' => $node), array('language' => $language));
+ $this->assertFalse(strcmp($target, $result), 'Valid tokens replaced while invalid tokens ignored.');
// Check that the results of token_generate are sanitized properly. This does NOT
// test the cleanliness of every token -- just that the $sanitize flag is being
// passed properly through the call stack and being handled correctly by a 'known'
// token, [node:title].
- $this->assertFalse(strcmp($target, $result), t('Basic placeholder tokens replaced.'));
-
$raw_tokens = array('title' => '[node:title]');
$generated = token_generate('node', $raw_tokens, array('node' => $node));
$this->assertFalse(strcmp($generated['[node:title]'], check_plain($node->title)), t('Token sanitized.'));