1 comment.test | CommentInterfaceTest::assertCommentLinks(array $info) |
Asserts that comment links appear according to the passed environment.
Parameters
$info: An associative array describing the environment to pass to setEnvironment().
File
- core/
modules/ comment/ tests/ comment.test, line 981 - Tests for the Comment module.
Class
Code
function assertCommentLinks(array $info) {
$info = $this->setEnvironment($info);
$nid = $this->node->nid;
foreach (array('', "node/$nid") as $path) {
$this->backdropGet($path);
// User is allowed to view comments.
if ($info['access comments']) {
if ($path == '') {
// In teaser view, a link containing the comment count is always
// expected.
if ($info['comment count']) {
$this->assertLink(t('1 comment'));
// For logged in users, a link containing the amount of new/unread
// comments is expected.
// See important note about comment_num_new() below.
if ($this->loggedInUser && isset($this->comment) && !isset($this->comment->seen)) {
$this->assertLink(t('1 new comment'));
$this->comment->seen = TRUE;
}
}
}
}
else {
$this->assertNoLink(t('1 comment'));
$this->assertNoLink(t('1 new comment'));
}
// comment_num_new() is based on node views, so comments are marked as
// read when a node is viewed, regardless of whether we have access to
// comments.
if ($path == "node/$nid" && $this->loggedInUser && isset($this->comment)) {
$this->comment->seen = TRUE;
}
// User is not allowed to post comments.
if (!$info['post comments']) {
$this->assertNoLink('Add comment');
// Anonymous users should see a note to log in or register in case
// authenticated users are allowed to post comments.
// @see theme_comment_post_forbidden()
if (!$this->loggedInUser) {
if (user_access('post comments', $this->web_user)) {
// The note depends on whether users are actually able to register.
if ($info['user_register'] != USER_REGISTER_ADMINISTRATORS_ONLY) {
$this->assertText('Log in or register to post comments');
}
else {
$this->assertText('Log in to post comments');
}
}
else {
$this->assertNoText('Log in or register to post comments');
$this->assertNoText('Log in to post comments');
}
}
}
// User is allowed to post comments.
else {
$this->assertNoText('Log in or register to post comments');
// "Add comment" is always expected, except when there are no
// comments or if the user cannot see them.
if ($path == "node/$nid" && $info['form'] == COMMENT_FORM_BELOW && (!$info['comment count'] || !$info['access comments'])) {
$this->assertNoLink('Add comment');
}
else {
$this->assertLink('Add comment');
// Verify that the "Add comment" link points to the correct URL
// based on the comment form location configuration.
if ($info['form'] == COMMENT_FORM_SEPARATE_PAGE) {
$this->assertLinkByHref("comment/reply/$nid#comment-form", 0, 'Comment form link destination is on a separate page.');
$this->assertNoLinkByHref("node/$nid#comment-form");
}
else {
$this->assertLinkByHref("node/$nid#comment-form", 0, 'Comment form link destination is on node.');
$this->assertNoLinkByHref("comment/reply/$nid#comment-form");
}
}
// Also verify that the comment form appears according to the configured
// location.
if ($path == "node/$nid") {
$elements = $this->xpath('//form[@id=:id]', array(':id' => 'comment-form'));
if ($info['form'] == COMMENT_FORM_BELOW) {
$this->assertTrue(count($elements), 'Comment form found below.');
}
else {
$this->assertFalse(count($elements), 'Comment form not found below.');
}
}
}
}
}