1 comment.test public CommentInterfaceTest::testCommentNewCommentsIndicator()

Tests new comment marker.


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




public function testCommentNewCommentsIndicator() {
  // Test if the right links are displayed when no comment is present for the
  // node.
  $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'comment' => COMMENT_NODE_OPEN));
  $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())),

  // Log in with 'web user' and check comment links.
  $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.');

  // Updates to the history table are done in background processing from the
  // previous request. Wait a short time to make sure the record is written.

  // Test if "new comment" link is correctly removed.
  $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));