diff --git a/modules/authcache_comment/authcache_comment.test b/modules/authcache_comment/authcache_comment.test index 8b49304..57bf9c5 100644 --- a/modules/authcache_comment/authcache_comment.test +++ b/modules/authcache_comment/authcache_comment.test @@ -182,6 +182,10 @@ class AuthcacheCommentTest extends DrupalWebTestCase { $this->assertText($setting_markup); $this->assertStub($setting_stub, HookStub::once()); + $this->assertIdentical(1, count($this->xpath('//span[@class=:class and @data-p13n-user-prop=:prop]', array( + ':class' => 'authcache-user', + ':prop' => 'name', + ))), 'Generate placeholder markup for user property'); } /** @@ -230,8 +234,12 @@ class AuthcacheCommentTest extends DrupalWebTestCase { $this->drupalGet('node'); $this->assertNoText('1 new comment'); - $this->assertText($setting_markup, 'Should replace "1 new comment" link with a setting'); + $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); @@ -243,8 +251,12 @@ class AuthcacheCommentTest extends DrupalWebTestCase { $this->drupalGet('node'); - $this->assertText($setting_markup, 'Should replace "1 new comment" link with a setting'); + $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'); } /** diff --git a/modules/authcache_forum/authcache_forum.js b/modules/authcache_forum/authcache_forum.js index 3dbf593..a98216e 100644 --- a/modules/authcache_forum/authcache_forum.js +++ b/modules/authcache_forum/authcache_forum.js @@ -1,37 +1,29 @@ (function ($) { + function updateCount(elem, count) { + if (count) { + $(elem).html(Drupal.t('@count new', {'@count': count})); + + // Update icon. + var icon = $(elem).closest('tr').find('td > div').get(0); + if (icon) { + icon.className = icon.className.replace('status-default', 'status-new').replace('status-hot', 'status-hot-new'); + } + } + } + Drupal.behaviors.authcacheForum = { attach: function (context, settings) { if (settings.authcacheCommentNumNew) { $('.authcache-forum-topic-num-new', context).once('authcache-forum-topic-num-new', function() { - var elem = $(this); var nid = $(this).data('p13n-nid'); - - if (settings.authcacheCommentNumNew[nid]) { - elem.html(Drupal.t('@count new', {'@count': settings.authcacheCommentNumNew[nid]})); - - // Update icon. - var icon = elem.closest('tr').find('td > div').get(0); - if (icon) { - icon.className = icon.className.replace('status-default', 'status-new').replace('status-hot', 'status-hot-new'); - } - } + updateCount(this, settings.authcacheCommentNumNew[nid]); }); } if (settings.authcacheForumNumNew) { $('.authcache-forum-num-new', context).once('authcache-forum-num-new', function() { - var elem = $(this); var tid = $(this).data('p13n-tid'); - - if (settings.authcacheForumNumNew[tid]) { - elem.html(Drupal.t('@count new', {'@count': settings.authcacheForumNumNew[tid]})); - - // Update icon. - var icon = elem.closest('tr').find('td > div').get(0); - if (icon) { - icon.className = icon.className.replace('status-default', 'status-new').replace('status-hot', 'status-hot-new'); - } - } + updateCount(this, settings.authcacheForumNumNew[tid]); }); } } diff --git a/modules/authcache_forum/authcache_forum.test b/modules/authcache_forum/authcache_forum.test index 78e33ad..04b27c8 100644 --- a/modules/authcache_forum/authcache_forum.test +++ b/modules/authcache_forum/authcache_forum.test @@ -289,27 +289,35 @@ class AuthcacheForumTest extends DrupalWebTestCase { ':icon' => 'icon', ':status' => 'forum-status-default', )); - $this->assertTrue($default_icons, 'Should display icons with default status'); + $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, 'Should not display icons with new-status'); - $this->assertText($setting_markup, 'Should replace "1 new" link with placeholder markup'); + $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 - // comments, the markup substitution must still take place. + // 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, 'Should replace "1 new" link with placeholder markup'); + $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'); } /** @@ -351,13 +359,17 @@ class AuthcacheForumTest extends DrupalWebTestCase { $default_icons = $this->xpath('//div[contains(@class, :class)]', array( ':class' => 'topic-status-default', )); - $this->assertTrue($default_icons, 'Should display icons with default status'); + $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, 'Should not display icons with new-status'); - $this->assertText($setting_markup, 'Should replace "1 new" link with placeholder markup'); + $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. @@ -371,13 +383,17 @@ class AuthcacheForumTest extends DrupalWebTestCase { $default_icons = $this->xpath('//div[contains(@class, :class)]', array( ':class' => 'topic-status-hot', )); - $this->assertTrue($default_icons, 'Should display icons with hot status'); + $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, 'Should not display icons with hot-new-status'); - $this->assertText($setting_markup, 'Should replace "1 new" link with placeholder markup'); + $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. @@ -390,8 +406,12 @@ class AuthcacheForumTest extends DrupalWebTestCase { $this->drupalGet('forum/' . $this->forum['tid']); - $this->assertText($setting_markup, 'Should replace "1 new" link with placeholder markup'); + $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'); } /**