$comment->
setHomepage('http://example.org/'
);
// Add HTML to ensure that sanitation of some fields tested directly.
$comment->
setSubject('<blink>Blinking Comment</blink>'
);
// Generate and test tokens.
$tests =
[];
$tests['[comment:cid]'
] =
$comment->
id();
$tests['[comment:hostname]'
] =
$comment->
getHostname();
$tests['[comment:author]'
] = Html::
escape($comment->
getAuthorName());
$tests['[comment:mail]'
] =
$this->adminUser->
getEmail();
$tests['[comment:homepage]'
] = UrlHelper::
filterBadProtocol($comment->
getHomepage());
$tests['[comment:title]'
] = Html::
escape($comment->
getSubject());
$tests['[comment:body]'
] =
$comment->comment_body->processed;
$tests['[comment:langcode]'
] =
$comment->
language()->
getId();
$tests['[comment:url]'
] =
$comment->
toUrl('canonical',
$url_options +
['fragment' => 'comment-' .
$comment->
id()])->
toString();
$tests['[comment:edit-url]'
] =
$comment->
toUrl('edit-form',
$url_options)->
toString();
$tests['[comment:created]'
] = \Drupal::
service('date.formatter'
)->
format($comment->
getCreatedTime(), 'medium',
['langcode' =>
$language_interface->
getId()]);
$tests['[comment:created:since]'
] = \Drupal::
service('date.formatter'
)->
formatTimeDiffSince($comment->
getCreatedTime(),
['langcode' =>
$language_interface->
getId()]);
$tests['[comment:changed:since]'
] = \Drupal::
service('date.formatter'
)->
formatTimeDiffSince($comment->
getChangedTimeAcrossTranslations(),
['langcode' =>
$language_interface->
getId()]);
$tests['[comment:parent:cid]'
] =
$comment->
hasParentComment() ?
$comment->
getParentComment()->
id() : NULL;
$tests['[comment:parent:title]'
] =
$parent_comment->
getSubject();
$tests['[comment:entity]'
] = Html::
escape($node->
getTitle());