You are here

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

Test that the number of new comments is replaced by a placeholder.

Covers authcache_comment_node_view_alter()

File

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

Class

AuthcacheCommentTest
Tests for markup substitution.

Code

public function testNumberOfNewComments() {
  $this->stubmod
    ->hook('authcache_p13n_client', array(
    'authcache_p13n_test' => array(
      'title' => t('Test Client'),
      'enabled' => TRUE,
    ),
  ));
  $this
    ->drupalLogin($this->member1);

  // M1: Visit the front page populated with one node having no comments.
  // Because there is no point in trying to figure out whether a node has new
  // comments, markup substitution for the new-comments fragment should not
  // take place when there are no comments in the first place.
  $setting_markup = $this
    ->randomName(8);
  $setting_stub = HookStub::on('theme_authcache_p13n_setting__authcache_p13n_test', $setting_markup);
  $this
    ->drupalGet('node');
  $this
    ->assertStub($setting_stub, HookStub::never());

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

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

  // M1: Returns to the home page. Normally a link '1 new comment' will be
  // shown on a node posted to the front page. However Authcache Comment will
  // substitute the number-of-new-comments link with a placeholder.
  $this
    ->drupalLogin($this->member1);
  $setting_markup = $this
    ->randomName(8);
  $setting_stub = HookStub::on('theme_authcache_p13n_setting__authcache_p13n_test', $setting_markup);
  $this
    ->drupalGet('node');
  $this
    ->assertNoText('1 new comment');
  $this
    ->assertText($setting_markup, 'Replace "1 new comment" link with a setting');
  $this
    ->assertStub($setting_stub, HookStub::once());
  $this
    ->assertIdentical(1, count($this
    ->xpath('//span[@class=:class and @data-p13n-nid=:nid]', array(
    ':class' => 'authcache-comment-num-new',
    ':nid' => $this->node->nid,
  ))), 'Replace "1 new comment" link with placeholder markup');

  // M1: Visit the node in order to clear the new-comments marker.
  $this
    ->drupalGet('node/' . $this->node->nid);

  // M1: Repeat the test on the front-page. Even though there are no new
  // comments, the markup substitution must still take place.
  $setting_markup = $this
    ->randomName(8);
  $setting_stub = HookStub::on('theme_authcache_p13n_setting__authcache_p13n_test', $setting_markup);
  $this
    ->drupalGet('node');
  $this
    ->assertText($setting_markup, 'Render setting even though there is no new comment');
  $this
    ->assertStub($setting_stub, HookStub::once());
  $this
    ->assertIdentical(1, count($this
    ->xpath('//span[@class=:class and @data-p13n-nid=:nid]', array(
    ':class' => 'authcache-comment-num-new',
    ':nid' => $this->node->nid,
  ))), 'Generate placeholder markup even though there is no new comment');
}