Ticket #40293: 40293.2.diff
File 40293.2.diff, 2.3 KB (added by , 7 years ago) |
---|
-
src/wp-includes/comment-template.php
diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php index e2bdaf6..c41b298 100644
function comments_template( $file = '/comments.php', $separate_comments = false 1379 1379 1380 1380 $top_level_count = $top_level_query->query( $top_level_args ); 1381 1381 1382 $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; 1382 if ( $top_level_count && $per_page ) { 1383 $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; 1384 } else { 1385 $comment_args['offset'] = 0; 1386 } 1383 1387 } 1384 1388 } 1385 1389 -
tests/phpunit/tests/comment/commentsTemplate.php
diff --git tests/phpunit/tests/comment/commentsTemplate.php tests/phpunit/tests/comment/commentsTemplate.php index c26a88b..34ad0e1 100644
class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { 128 128 } 129 129 130 130 /** 131 * @ticket 40293 132 */ 133 public function test_should_handle_zero_comments_per_page_with_comments_broken_into_pages_and_last_page_displayed_by_default() { 134 $now = time(); 135 $p = self::factory()->post->create(); 136 137 $comment_1 = self::factory()->comment->create( array( 138 'comment_post_ID' => $p, 139 'comment_content' => '1', 140 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ), 141 ) ); 142 $comment_2 = self::factory()->comment->create( array( 143 'comment_post_ID' => $p, 144 'comment_content' => '2', 145 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ), 146 ) ); 147 148 update_option( 'comment_order', 'desc' ); 149 update_option( 'default_comments_page', 'newest' ); // last (newest) page displayed by default 150 update_option( 'comments_per_page', '0' ); // top level comments per page 151 update_option( 'page_comments', '1' ); // break comments into pages 152 153 $this->go_to( get_permalink( $p ) ); 154 $found = get_echo( 'comments_template' ); 155 156 preg_match_all( '/id="comment-([0-9]+)"/', $found, $matches ); 157 158 $found_cids = array_map( 'intval', $matches[1] ); 159 $this->assertSame( array( $comment_2, $comment_1 ), $found_cids ); 160 } 161 162 /** 131 163 * @ticket 8071 132 164 */ 133 165 public function test_should_respect_comment_order_asc_when_default_comments_page_is_newest_on_subsequent_pages() {