Commit 0ef890fc authored by Drew Webber's avatar Drew Webber
Browse files

Issue #2828455 by poker10, klausi: User mail token PHP notices for anonymous

parent 74e6ff20
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -2566,6 +2566,25 @@ class UserTokenReplaceTestCase extends DrupalWebTestCase {
      $this->assertEqual($output, $expected, format_string('Unsanitized user token %token replaced.', array('%token' => $input)));
    }
  }

  /**
   * Uses an anonymous user, then tests the tokens generated from it.
   */
  function testAnonymousUserTokenReplacement() {
    global $language;

    // Load anonymous user data.
    $account = drupal_anonymous_user();

    // Generate and test sanitized tokens.
    $tests = array();
    $tests['[user:mail]'] = '';

    foreach ($tests as $input => $expected) {
      $output = token_replace($input, array('user' => $account), array('language' => $language));
      $this->assertEqual($output, $expected, format_string('Sanitized user token %token replaced.', array('%token' => $input)));
    }
  }
}

/**
+6 −1
Original line number Diff line number Diff line
@@ -96,7 +96,12 @@ function user_tokens($type, $tokens, array $data = array(), array $options = arr
          break;

        case 'mail':
          if (empty($account->mail)) {
            $replacements[$original] = '';
          }
          else {
            $replacements[$original] = $sanitize ? check_plain($account->mail) : $account->mail;
          }
          break;

        case 'url':