| | 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 | * @group bbg |
| | 626 | */ |
| | 627 | public function test_query_offset_should_include_unapproved_comments() { |
| | 628 | $comment_author_email = 'foo@example.com'; |
| | 629 | |
| | 630 | $now = time(); |
| | 631 | $p = self::factory()->post->create(); |
| | 632 | $comment_1 = self::factory()->comment->create( array( |
| | 633 | 'comment_post_ID' => $p, |
| | 634 | 'comment_content' => '1', |
| | 635 | 'comment_approved' => '0', |
| | 636 | 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ), |
| | 637 | ) ); |
| | 638 | $comment_2 = self::factory()->comment->create( array( |
| | 639 | 'comment_post_ID' => $p, |
| | 640 | 'comment_content' => '2', |
| | 641 | 'comment_approved' => '0', |
| | 642 | 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ), |
| | 643 | ) ); |
| | 644 | $comment_3 = self::factory()->comment->create( array( |
| | 645 | 'comment_post_ID' => $p, |
| | 646 | 'comment_content' => '3', |
| | 647 | 'comment_approved' => '0', |
| | 648 | 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 100 ), |
| | 649 | 'comment_author_email' => $comment_author_email, |
| | 650 | ) ); |
| | 651 | $comment_4 = self::factory()->comment->create( array( |
| | 652 | 'comment_post_ID' => $p, |
| | 653 | 'comment_content' => '4', |
| | 654 | 'comment_approved' => '0', |
| | 655 | 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 200 ), |
| | 656 | 'comment_author_email' => $comment_author_email, |
| | 657 | ) ); |
| | 658 | $comment_5 = self::factory()->comment->create( array( |
| | 659 | 'comment_post_ID' => $p, |
| | 660 | 'comment_content' => '5', |
| | 661 | 'comment_approved' => '0', |
| | 662 | 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 300 ), |
| | 663 | 'comment_author_email' => $comment_author_email, |
| | 664 | ) ); |
| | 665 | $comment_6 = self::factory()->comment->create( array( |
| | 666 | 'comment_post_ID' => $p, |
| | 667 | 'comment_content' => '6', |
| | 668 | 'comment_approved' => '1', |
| | 669 | 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 400 ), |
| | 670 | ) ); |
| | 671 | var_dump( $comment_1, $comment_2, $comment_3, $comment_4, $comment_5, $comment_6 ); |
| | 672 | |
| | 673 | update_option( 'comment_order', 'asc' ); |
| | 674 | update_option( 'default_comments_page', 'newest' ); |
| | 675 | update_option( 'page_comments', 1 ); |
| | 676 | update_option( 'comments_per_page', 2 ); |
| | 677 | |
| | 678 | add_filter( 'wp_get_current_commenter', array( $this, 'fake_current_commenter' ) ); |
| | 679 | $this->go_to( get_permalink( $p ) ); |
| | 680 | $found = get_echo( 'comments_template' ); |
| | 681 | remove_filter( 'wp_get_current_commenter', array( $this, 'fake_current_commenter' ) ); |
| | 682 | |
| | 683 | // Find the found comments in the markup. |
| | 684 | preg_match_all( '|id="comment-([0-9]+)|', $found, $matches ); |
| | 685 | |
| | 686 | $found_cids = array_map( 'intval', $matches[1] ); |
| | 687 | $this->assertSame( array( $comment_4, $comment_3 ), $found_cids ); |
| | 688 | } |
| | 689 | |
| | 690 | public function fake_current_commenter( $commenter ) { |
| | 691 | $commenter['comment_author_email'] = 'foo@example.com'; |
| | 692 | return $commenter; |
| | 693 | } |