You are here

public function AuthcacheCommentTest::testNumberOfNewCommentsFragment in Authenticated User Page Caching (Authcache) 7.2

Ensure that the number of new comments is reported accurately.

Covers AuthcacheCommentNumNewFragment

File

modules/authcache_comment/authcache_comment.test, line 449
Test cases for the Authcache Comment module.

Class

AuthcacheCommentTest
Tests for markup substitution.

Code

public function testNumberOfNewCommentsFragment() {

  // M1: Login and retrieve num-new setting for front-page.
  $this
    ->drupalLogin($this->member1);
  $url = authcache_p13n_request_get_callback('setting/comment-num-new', array(
    'cn' => array(
      $this->node->nid,
    ),
  ));
  $this
    ->assertTrue($url);
  $result = $this
    ->drupalGetAJAX($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $expect = array(
    'authcacheCommentNumNew' => array(),
  );
  $this
    ->assertEqual($expect, $result, 'Should not report any new comments if there are none');

  // Simulate M1 visiting the node a minute ago.
  db_merge('history')
    ->key(array(
    'uid' => $this->member1->uid,
    'nid' => $this->node->nid,
  ))
    ->fields(array(
    'timestamp' => time() - 60,
  ))
    ->execute();

  // M2: Post a comment.
  $this
    ->drupalLogin($this->member2);
  $comment = $this
    ->postComment($this->node, $this
    ->randomName(8));
  $this
    ->drupalLogout();

  // M1: Login again and verify that num-new reports a comment count of 1 now.
  $this
    ->drupalLogin($this->member1);
  $result = $this
    ->drupalGetAJAX($GLOBALS['base_root'] . $url['path'], $url['options'], array(
    'X-Authcache: 1',
  ));
  $expect = array(
    'authcacheCommentNumNew' => array(
      $this->node->nid => 1,
    ),
  );
  $this
    ->assertEqual($expect, $result, 'Should report one new comment for member one now');
}