1 comment.test public CommentInterfaceTest::testCommentNewCommentsIndicator()

Tests new comment marker.

File

core/modules/comment/tests/comment.test, line 484
Tests for the Comment module.

Class

CommentInterfaceTest

Code

public function testCommentNewCommentsIndicator() {
  // Test if the right links are displayed when no comment is present for the
  // node.
  $this->backdropLogin($this->admin_user);
  $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
  $this->backdropGet('node');
  $this->assertNoLink(t('@count comments', array('@count' => 0)));
  $this->assertNoLink(t('@count new comments', array('@count' => 0)));
  $this->assertLink(t('Read more'));
  $count = $this->xpath('//article[@id=:id]//ul/li', array(':id' => 'node-' . $this->node->nid));
  $this->assertTrue(count($count) == 2, 'Two node links found ("Read more" and "Add comment")');

  // Create a new comment. This helper function may be run with different
  // comment settings so use comment_save() to avoid complex setup.
  $comment = entity_create('comment', array(
    'cid' => NULL,
    'nid' => $this->node->nid,
    'node_type' => $this->node->type,
    'pid' => 0,
    'uid' => $this->loggedInUser->uid,
    'status' => COMMENT_PUBLISHED,
    'subject' => $this->randomName(),
    'hostname' => ip_address(),
    'langcode' => LANGUAGE_NONE,
    'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
  ));
  comment_save($comment);
  $this->backdropLogout();

  // Log in with 'web user' and check comment links.
  $this->backdropLogin($this->web_user);
  $this->backdropGet('node');
  $this->assertLink(t('1 new comment'));
  $this->clickLink(t('1 new comment'));
  $this->assertRaw('<a id="new"></a>', 'Found "new" marker.');
  $this->assertTrue($this->xpath('//a[@id=:new]/following-sibling::a[1][@id=:comment_id]', array(':new' => 'new', ':comment_id' => 'comment-1')), 'The "new" anchor is positioned at the right comment.');

  // Test if "new comment" link is correctly removed.
  $this->backdropGet('node');
  $this->assertLink(t('1 comment'));
  $this->assertLink(t('Read more'));
  $this->assertNoLink(t('1 new comment'));
  $this->assertNoLink(t('@count new comments', array('@count' => 0)));
  $count = $this->xpath('//article[@id=:id]//ul/li', array(':id' => 'node-' . $this->node->nid));
  $this->assertTrue(count($count) == 3, print_r($count, TRUE));
}