t('[26966] Comments per page, links don\'t go to correct page - comment block, comment admin'), 'desc' => t('When you, as admin, set the default number of comments per page, the links to those comments are not updated as they should be. For example, all links to individual comments still go to /node/x/#comment-x but comment no. x may not be on that page if x is bigger than the number of comments per page. Hence the link is wrong. This includes links from the \'recent comments\' block and also very importantly after someone has submitted a new comment, they should be taken to their comment but if their new comment isn\'t on the first page then they have the same problem. This is a *big* problem if you have discussion/comment threads of more than about 100 posts (some threads on my site are over 300 posts) and hence you can\'t sensibly include them all on one page.'), 'group' => t('Drupal 7 Tests'), ); } function testIssue() { // set Default comments per page to 10 (less time) $comment_default_per_page_story = 10; // number of pages to fill $pages = 2; $this->drupalVariableSet('comment_default_per_page_story', $comment_default_per_page_story); $this->drupalVariableSet('comment_story', COMMENT_NODE_READ_WRITE); // create a user who will post $web_user = $this->drupalCreateUserRolePerm(array('administer comments', 'post comments', 'post comments without approval', 'edit own story content', 'create story content')); $this->drupalLoginUser($web_user); // create a story $edit = array( 'title' => '!SimpleTest! test title' . $this->randomName(20), 'body' => '!SimpleTest! test body' . $this->randomName(10) . ' ' . $this->randomName(20) . ' ' . $this->randomName(30), ); $this->drupalPost('node/add/story', $edit, 'Save'); $node = node_load(array('title' => $edit['title'])); $this->assertNotNull($node, 'Node found in database'); // links to comments $links_array = array(); // create comments (for $pages pages) for ($i = 0; $i <= $comment_default_per_page_story * $pages - 1; $i++) { $edit = array( 'author' => $web_user->name, 'subject' => $this->randomName(10), 'comment' => $this->randomName(20), 'format' => 1, 'nid' => $node->nid, 'uid' => $web_user->uid, 'date' => 'now', 'timestamp' => time(), 'name' => $web_user->name, 'cid' => 0, 'pid' => 0, ); $links_array[$edit['subject']] = ''; comment_save($edit); }; // Collect links to comments from all pages for ($page = 0; $page <= $pages - 1; $page++) { $url = "node/{$node->nid}"; $query = ''; if (!empty($page)) { $query = array('page' => $page); } $this->drupalGet($url, array('query' => $query)); $content = $this->drupalGetContent(); foreach ($links_array as $subject => $link) { $regexp = '|\s*?' . $subject . '\s*?|'; if (preg_match($regexp, $content, $matches)) { $links_array[$subject] = $matches[1]; }; } } // Now $links_array consists of all links to comments. // If we follow the link we can see the comment. // Check presence of the comment in the page followed by the link (via 'subject' of comment). foreach ($links_array as $subject => $link) { list($url, $fragment) = explode('#', $link); $this->drupalGet($url, array('fragment' => $fragment)); $this->assertWantedRaw($subject, 'Check comment: ' . $subject); } } }