diff --git a/taxonomy_access.test b/taxonomy_access.test
index b0b67f5..d11515e 100644
--- a/taxonomy_access.test
+++ b/taxonomy_access.test
@@ -1491,3 +1491,86 @@ class TaxonomyAccessWeightTest extends DrupalWebTestCase {
     );
   }
 }
+
+/**
+ * Testcase for the comment pagination.
+ */
+class TaxonomyAccessCommentPagerTestCase extends TaxonomyAccessTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Comment pagination',
+      'description' => 'Test node pages have the right amount of pages.',
+      'group' => 'Taxonomy Access Control',
+    );
+  }
+
+  public function setUp() {
+    module_enable(array('comment'));
+    parent::setUp();
+  }
+
+  /**
+   * Test that the comment count query is working so that the pager has no
+   * superfluous pages.
+   */
+  public function testPageCount() {
+    // Login as the administrator.
+    $this->drupalLogout();
+    $this->drupalLogin($this->users['site_admin']);
+
+    // Create a node.
+    $node = $this->createArticle(array('test_term'));
+    $this->assertTrue($node->status, t('Created published node.'));
+
+    // Create 60 comments.
+    for ($i = 0; $i < 60; $i++) {
+      $comment = new stdClass();
+      $comment->cid = 0;
+      $comment->pid = 0;
+      $comment->nid = $node->nid;
+      $comment->uid = $this->users['site_admin']->uid;
+      $comment->status = COMMENT_PUBLISHED;
+      $comment->subject = $this->randomName();
+      $comment->comment_body[LANGUAGE_NONE][]['value'] = $this->randomName();
+      comment_save($comment);
+    }
+
+    // Create two roles for the test user, both allowing access using
+    // taxonomy access control.
+    $rids = array();
+    $rids[DRUPAL_AUTHENTICATED_RID] = DRUPAL_AUTHENTICATED_RID;
+    for ($i = 0; $i < 2; $i++) {
+      $rid = $this->drupalCreateRole(array('access content', 'access comments'));
+      $rids[$rid] = $rid;
+
+      $this->drupalGet(TAXONOMY_ACCESS_CONFIG . '/role/' . $rid . '/edit');
+      $edit = array();
+      $this->configureFormRow($edit, TAXONOMY_ACCESS_GLOBAL_DEFAULT, TAXONOMY_ACCESS_VOCABULARY_DEFAULT, TAXONOMY_ACCESS_NODE_ALLOW);
+      $this->drupalPost(NULL, $edit, t('Save all'));
+    }
+
+    // Create and login test user.
+    $edit = array();
+    $edit['name'] = $this->randomName();
+    $edit['mail'] = $edit['name'] . '@example.com';
+    $edit['pass'] = user_password();
+    $edit['status'] = 1;
+    $edit['roles'] = $rids;
+    $account = user_save(drupal_anonymous_user(), $edit);
+    $account->pass_raw = $edit['pass'];
+    $this->drupalLogin($account);
+    $this->assertTrue(user_access('access content', $account), t('Has access content permission.'));
+
+    // 50 should be the default, but set it anyway.
+    variable_set('comment_default_per_page_' . $node->type, 50);
+
+    // View the node page. With the default 50 comments per page there should
+    // be two pages (0, 1) but no third (2) page.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertText($node->title, t('Node title found.'));
+    $this->assertText(t('Comments'), t('Has a comments section.'));
+    $this->assertRaw('?page=1', t('Secound page exists.'));
+    $this->assertNoRaw('?page=2', t('No third page exists.'));
+  }
+}
