public function AuthcacheForumTest::testForumTopicList in Authenticated User Page Caching (Authcache) 7.2
Markup substitution on forum topic list.
Covers authcache_forum_preprocess_forum_topic_list, authcache_forum_preprocess_forum_icon.
File
- modules/
authcache_forum/ authcache_forum.test, line 329 - Test cases for the Authcache Forum module.
Class
- AuthcacheForumTest
- Tests for markup substitution.
Code
public function testForumTopicList() {
$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 topic list. Normally a link '1 new' will be shown next
// to the topic. However Authcache Forum 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('forum/' . $this->forum['tid']);
$this
->assertNoText('1 new');
$default_icons = $this
->xpath('//div[contains(@class, :class)]', array(
':class' => 'topic-status-default',
));
$this
->assertTrue($default_icons, 'Icons with default status present');
$new_icons = $this
->xpath('//div[contains(@class, :class)]', array(
':class' => 'topic-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-nid=:nid]', array(
':class' => 'authcache-forum-topic-num-new',
':nid' => $this->topic->nid,
))), 'Replace "1 new" link with placeholder markup');
// M1: Access it again but with lower hot-threshold in order to ensure that
// icon class still does not change.
variable_set('forum_hot_topic', 0);
$setting_markup = $this
->randomName(8);
$setting_stub = HookStub::on('theme_authcache_p13n_setting__authcache_p13n_test', $setting_markup);
$this
->drupalGet('forum/' . $this->forum['tid']);
$this
->assertNoText('1 new');
$default_icons = $this
->xpath('//div[contains(@class, :class)]', array(
':class' => 'topic-status-hot',
));
$this
->assertTrue($default_icons, 'Icons with hot status present');
$new_icons = $this
->xpath('//div[contains(@class, :class)]', array(
':class' => 'topic-status-hot-new',
));
$this
->assertFalse($new_icons, 'No icons with hot-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-nid=:nid]', array(
':class' => 'authcache-forum-topic-num-new',
':nid' => $this->topic->nid,
))), 'Replace "1 new" link with placeholder markup');
variable_del('forum_hot_topic');
// 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
// 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('forum/' . $this->forum['tid']);
$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-forum-topic-num-new',
':nid' => $this->topic->nid,
))), 'Generate placeholder markup even though there is no new comment');
}