summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-11-09 00:59:57 (GMT)
committerAlex Pott2014-11-09 00:59:57 (GMT)
commita36ff8466ed05101224755d17bc8fcbfa63ea65a (patch)
treef3492707b393d839ae4c920697550bdf056c6956
parentfa2be71e4fd287235990b76080cd1fcc55b695b4 (diff)
Issue #920056 by Dave Reid, andypost, quietone, rkjha, Alumei: Fixed [comment:name] duplicates [comment:author], and the latter should use format_username().
-rw-r--r--core/modules/comment/comment.tokens.inc9
-rw-r--r--core/modules/comment/src/Tests/CommentTokenReplaceTest.php11
2 files changed, 10 insertions, 10 deletions
diff --git a/core/modules/comment/comment.tokens.inc b/core/modules/comment/comment.tokens.inc
index 789ede3..8f6d008 100644
--- a/core/modules/comment/comment.tokens.inc
+++ b/core/modules/comment/comment.tokens.inc
@@ -37,10 +37,6 @@ function comment_token_info() {
'name' => t("IP Address"),
'description' => t("The IP address of the computer the comment was posted from."),
);
- $comment['name'] = array(
- 'name' => t("Name"),
- 'description' => t("The name left by the comment author."),
- );
$comment['mail'] = array(
'name' => t("Email address"),
'description' => t("The email address left by the comment author."),
@@ -96,7 +92,7 @@ function comment_token_info() {
);
$comment['author'] = array(
'name' => t("Author"),
- 'description' => t("The author of the comment, if they were logged in."),
+ 'description' => t("The author name of the comment."),
'type' => 'user',
);
@@ -173,9 +169,6 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$replacements[$original] = $comment->url('edit-form', $url_options);
break;
- // @todo Remove 'name' token in favour of 'author'. See
- // https://drupal.org/node/920056.
- case 'name':
case 'author':
$name = $comment->getAuthorName();
$replacements[$original] = $sanitize ? Xss::filter($name) : $name;
diff --git a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php
index c3699ae..462393b 100644
--- a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php
+++ b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php
@@ -51,7 +51,6 @@ class CommentTokenReplaceTest extends CommentTestBase {
$tests = array();
$tests['[comment:cid]'] = $comment->id();
$tests['[comment:hostname]'] = String::checkPlain($comment->getHostname());
- $tests['[comment:name]'] = Xss::filter($comment->getAuthorName());
$tests['[comment:author]'] = Xss::filter($comment->getAuthorName());
$tests['[comment:mail]'] = String::checkPlain($this->admin_user->getEmail());
$tests['[comment:homepage]'] = check_url($comment->getHomepage());
@@ -78,7 +77,6 @@ class CommentTokenReplaceTest extends CommentTestBase {
// Generate and test unsanitized tokens.
$tests['[comment:hostname]'] = $comment->getHostname();
- $tests['[comment:name]'] = $comment->getAuthorName();
$tests['[comment:author]'] = $comment->getAuthorName();
$tests['[comment:mail]'] = $this->admin_user->getEmail();
$tests['[comment:homepage]'] = $comment->getHomepage();
@@ -93,6 +91,15 @@ class CommentTokenReplaceTest extends CommentTestBase {
$this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input)));
}
+ // Test anonymous comment author.
+ $author_name = $this->randomString();
+ $comment->setOwnerId(0)->setAuthorName($author_name);
+ $input = '[comment:author]';
+ $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId()));
+ $this->assertEqual($output, Xss::filter($author_name), format_string('Sanitized comment author token %token replaced.', array('%token' => $input)));
+ $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
+ $this->assertEqual($output, $author_name, format_string('Unsanitized comment author token %token replaced.', array('%token' => $input)));
+
// Load node so comment_count gets computed.
$node = node_load($node->id());