public function AuthcacheForumTest::testForumList in Authenticated User Page Caching (Authcache) 7.2
Markup substitution forum overview page.
Cover authcache_forum_preprocess_forum_list().
See also
AuthcacheCommentTest::testNumberOfNewComments()
File
- modules/
authcache_forum/ authcache_forum.test, line 258 - Test cases for the Authcache Forum module.
Class
- AuthcacheForumTest
- Tests for markup substitution.
Code
public function testForumList() {
$this->stubmod
->hook('authcache_p13n_client', array(
'authcache_p13n_test' => array(
'title' => t('Test Client'),
'enabled' => TRUE,
),
));
// M2: Post a comment on the topic.
$this
->drupalLogin($this->member2);
$comment = $this
->postComment($this->topic, $this
->randomName(8));
$this
->drupalLogout();
// Simulate M1 visiting the node a minute ago.
db_merge('history')
->key(array(
'uid' => $this->member1->uid,
'nid' => $this->topic->nid,
))
->fields(array(
'timestamp' => time() - 60,
))
->execute();
// M1: Accesses the forum list. Normally a link '1 new' will be shown next
// to the forum. However Authcache Forum will substitute the
// number-of-topics-with-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('forum');
$this
->assertNoText('1 new');
$default_icons = $this
->xpath('//div[contains(@class, :icon) and contains(@class, :status)]', array(
':icon' => 'icon',
':status' => 'forum-status-default',
));
$this
->assertTrue($default_icons, 'Icons with default status present');
$new_icons = $this
->xpath('//div[contains(@class, :icon) and contains(@class, :status)]', array(
':icon' => 'icon',
':status' => 'forum-status-new',
));
$this
->assertFalse($new_icons, 'No icons with new-status present');
$this
->assertText($setting_markup, 'Replace "1 new" link with a setting');
$this
->assertStub($setting_stub, HookStub::once());
$this
->assertIdentical(1, count($this
->xpath('//span[@class=:class and @data-p13n-tid=:tid]', array(
':class' => 'authcache-forum-num-new',
':tid' => $this->forum['tid'],
))), 'Replace "1 new" link with placeholder markup');
// M1: Visit the topic in order to clear the new-comments marker.
$this
->drupalGet('node/' . $this->topic->nid);
// M1: Repeat the test on the forum-list. Even though there are no new
// topics, 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('forum');
$this
->assertText($setting_markup, 'Render setting even though there is no new topic');
$this
->assertStub($setting_stub, HookStub::once());
$this
->assertIdentical(1, count($this
->xpath('//span[@class=:class and @data-p13n-tid=:tid]', array(
':class' => 'authcache-forum-num-new',
':tid' => $this->forum['tid'],
))), 'Generate placeholder markup even though there is no new topic');
}