Changeset 36040
- Timestamp:
- 12/21/2015 03:06:41 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r35933 r36040 1314 1314 // If fetching the first page of 'newest', we need a top-level comment count. 1315 1315 $top_level_query = new WP_Comment_Query(); 1316 $top_level_ count = $top_level_query->query(array(1316 $top_level_args = array( 1317 1317 'count' => true, 1318 1318 'orderby' => false, 1319 1319 'post_id' => $post->ID, 1320 1320 'parent' => 0, 1321 ) ); 1321 'status' => 'approve', 1322 ); 1323 1324 if ( isset( $comment_args['include_unapproved'] ) ) { 1325 $top_level_args['include_unapproved'] = $comment_args['include_unapproved']; 1326 } 1327 1328 $top_level_count = $top_level_query->query( $top_level_args ); 1322 1329 1323 1330 $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; -
trunk/tests/phpunit/tests/comment/commentsTemplate.php
r35331 r36040 574 574 } 575 575 } 576 577 /** 578 * @ticket 35068 579 */ 580 public function test_query_offset_should_not_include_unapproved_comments() { 581 $now = time(); 582 $p = self::factory()->post->create(); 583 $comment_1 = self::factory()->comment->create( array( 584 'comment_post_ID' => $p, 585 'comment_content' => '1', 586 'comment_approved' => '0', 587 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ), 588 ) ); 589 $comment_2 = self::factory()->comment->create( array( 590 'comment_post_ID' => $p, 591 'comment_content' => '2', 592 'comment_approved' => '0', 593 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ), 594 ) ); 595 $comment_3 = self::factory()->comment->create( array( 596 'comment_post_ID' => $p, 597 'comment_content' => '3', 598 'comment_approved' => '0', 599 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ), 600 ) ); 601 $comment_4 = self::factory()->comment->create( array( 602 'comment_post_ID' => $p, 603 'comment_content' => '4', 604 'comment_approved' => '1', 605 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ), 606 ) ); 607 608 update_option( 'comment_order', 'asc' ); 609 update_option( 'default_comments_page', 'newest' ); 610 update_option( 'page_comments', 1 ); 611 update_option( 'comments_per_page', 2 ); 612 613 $this->go_to( get_permalink( $p ) ); 614 $found = get_echo( 'comments_template' ); 615 616 // Find the found comments in the markup. 617 preg_match_all( '|id="comment-([0-9]+)|', $found, $matches ); 618 619 $found_cids = array_map( 'intval', $matches[1] ); 620 $this->assertSame( array( $comment_4 ), $found_cids ); 621 } 622 623 /** 624 * @ticket 35068 625 */ 626 public function test_query_offset_should_include_unapproved_comments() { 627 $comment_author_email = 'foo@example.com'; 628 629 $now = time(); 630 $p = self::factory()->post->create(); 631 $comment_1 = self::factory()->comment->create( array( 632 'comment_post_ID' => $p, 633 'comment_content' => '1', 634 'comment_approved' => '0', 635 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ), 636 ) ); 637 $comment_2 = self::factory()->comment->create( array( 638 'comment_post_ID' => $p, 639 'comment_content' => '2', 640 'comment_approved' => '0', 641 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ), 642 ) ); 643 $comment_3 = self::factory()->comment->create( array( 644 'comment_post_ID' => $p, 645 'comment_content' => '3', 646 'comment_approved' => '0', 647 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ), 648 'comment_author_email' => $comment_author_email, 649 ) ); 650 $comment_4 = self::factory()->comment->create( array( 651 'comment_post_ID' => $p, 652 'comment_content' => '4', 653 'comment_approved' => '0', 654 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ), 655 'comment_author_email' => $comment_author_email, 656 ) ); 657 $comment_5 = self::factory()->comment->create( array( 658 'comment_post_ID' => $p, 659 'comment_content' => '5', 660 'comment_approved' => '0', 661 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ), 662 'comment_author_email' => $comment_author_email, 663 ) ); 664 $comment_6 = self::factory()->comment->create( array( 665 'comment_post_ID' => $p, 666 'comment_content' => '6', 667 'comment_approved' => '1', 668 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ), 669 ) ); 670 671 update_option( 'comment_order', 'asc' ); 672 update_option( 'default_comments_page', 'newest' ); 673 update_option( 'page_comments', 1 ); 674 update_option( 'comments_per_page', 2 ); 675 676 add_filter( 'wp_get_current_commenter', array( $this, 'fake_current_commenter' ) ); 677 $this->go_to( get_permalink( $p ) ); 678 $found = get_echo( 'comments_template' ); 679 remove_filter( 'wp_get_current_commenter', array( $this, 'fake_current_commenter' ) ); 680 681 // Find the found comments in the markup. 682 preg_match_all( '|id="comment-([0-9]+)|', $found, $matches ); 683 684 $found_cids = array_map( 'intval', $matches[1] ); 685 $this->assertSame( array( $comment_4, $comment_3 ), $found_cids ); 686 } 687 688 public function fake_current_commenter( $commenter ) { 689 $commenter['comment_author_email'] = 'foo@example.com'; 690 return $commenter; 691 } 576 692 }
Note: See TracChangeset
for help on using the changeset viewer.