$this->
assertNotContains(0,
array_map('strlen',
$tests), 'No empty tokens generated.'
);
foreach ($tests as $input =>
$expected) { $bubbleable_metadata =
new BubbleableMetadata();
$output =
$token_service->
replace($input,
['comment' =>
$comment],
['langcode' =>
$language_interface->
getId()],
$bubbleable_metadata);
$this->
assertSame((string) $expected,
(string) $output, "Failed test case: {
$input}"
);
$this->
assertEquals($metadata_tests[$input],
$bubbleable_metadata);
} // Test anonymous comment author.
$author_name = 'This is a random & " > string';
$comment->
setOwnerId(0
)->
setAuthorName($author_name);
$input = '[comment:author]';
$output =
$token_service->
replace($input,
['comment' =>
$comment],
['langcode' =>
$language_interface->
getId()]);
$this->
assertSame((string) Html::
escape($author_name),
(string) $output);
// Add comment field to user and term entities.
$this->
addDefaultCommentField('user', 'user', 'comment', CommentItemInterface::OPEN, 'comment_user'
);
$this->
addDefaultCommentField('taxonomy_term', 'tags', 'comment', CommentItemInterface::OPEN, 'comment_term'
);
// Create a user and a comment.
$user = User::
create(['name' => 'alice'
]);
$user->
activate();
$user->
save();