summaryrefslogtreecommitdiff
path: root/modules/user
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/user
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/user')
-rw-r--r--modules/user/user.test64
-rw-r--r--modules/user/user.tokens.inc1
2 files changed, 64 insertions, 1 deletions
diff --git a/modules/user/user.test b/modules/user/user.test
index 5287e18f9..33d90ec1a 100644
--- a/modules/user/user.test
+++ b/modules/user/user.test
@@ -1521,3 +1521,67 @@ class UserRoleAdminTestCase extends DrupalWebTestCase {
}
}
+/**
+ * Test user token replacement in strings.
+ */
+class UserTokenReplaceTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'User token replacement',
+ 'description' => 'Generates text using placeholders for dummy content to check user token replacement.',
+ 'group' => 'User',
+ );
+ }
+
+ /**
+ * Creates a user, then tests the tokens generated from it.
+ */
+ function testUserTokenReplacement() {
+ global $language;
+ $url_options = array(
+ 'absolute' => TRUE,
+ 'language' => $language,
+ );
+
+ // Create two users and log them in one after another.
+ $user1 = $this->drupalCreateUser(array());
+ $user2 = $this->drupalCreateUser(array());
+ $this->drupalLogin($user1);
+ $this->drupalLogout();
+ $this->drupalLogin($user2);
+
+ $account = user_load($user1->uid);
+ global $user;
+
+ // Generate and test sanitized tokens.
+ $tests = array();
+ $tests['[user:uid]'] = $account->uid;
+ $tests['[user:name]'] = filter_xss($account->name);
+ $tests['[user:mail]'] = check_plain($account->mail);
+ $tests['[user:url]'] = url("user/$account->uid", $url_options);
+ $tests['[user:edit-url]'] = url("user/$account->uid/edit", $url_options);
+ $tests['[user:last-login]'] = format_date($account->login, 'medium', '', NULL, $language->language);
+ $tests['[user:last-login:short]'] = format_date($account->login, 'short', '', NULL, $language->language);
+ $tests['[user:created]'] = format_date($account->created, 'medium', '', NULL, $language->language);
+ $tests['[user:created:short]'] = format_date($account->created, 'short', '', NULL, $language->language);
+ $tests['[current-user:name]'] = check_plain($user->name);
+
+ // 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('user' => $account), array('language' => $language));
+ $this->assertFalse(strcmp($output, $expected), t('Sanitized user token %token replaced.', array('%token' => $input)));
+ }
+
+ // Generate and test unsanitized tokens.
+ $tests['[user:name]'] = $account->name;
+ $tests['[user:mail]'] = $account->mail;
+ $tests['[current-user:name]'] = $user->name;
+
+ foreach ($tests as $input => $expected) {
+ $output = token_replace($input, array('user' => $account), array('language' => $language, 'sanitize' => FALSE));
+ $this->assertFalse(strcmp($output, $expected), t('Unsanitized user token %token replaced.', array('%token' => $input)));
+ }
+ }
+}
diff --git a/modules/user/user.tokens.inc b/modules/user/user.tokens.inc
index d6fe22d37..70d4914d5 100644
--- a/modules/user/user.tokens.inc
+++ b/modules/user/user.tokens.inc
@@ -63,7 +63,6 @@ function user_token_info() {
* Implements hook_tokens().
*/
function user_tokens($type, $tokens, array $data = array(), array $options = array()) {
- global $user;
$url_options = array('absolute' => TRUE);
if (isset($options['language'])) {
$url_options['language'] = $options['language'];