WordPress.org

Make WordPress Core

Changeset 34805


Ignore:
Timestamp:
10/03/2015 07:15:55 PM (4 years ago)
Author:
boonebgorges
Message:

Only count top-level comments when calculating threaded pagination.

The change in [34535] did not properly account for threading.

See #13939, #11334.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-functions.php

    r34799 r34805  
    882882        'count'      => true,
    883883        'status'     => 'approve',
     884        'parent'     => 0,
    884885        'date_query' => array(
    885886            array(
  • trunk/tests/phpunit/tests/comment/getPageOfComment.php

    r34660 r34805  
    192192        $this->assertEquals( 2, $found_1 );
    193193    }
     194
     195    /**
     196     * @ticket 13939
     197     */
     198    public function test_only_top_level_comments_should_be_included_in_older_count() {
     199        $post = $this->factory->post->create();
     200
     201        $now = time();
     202        $comment_parents = $comment_children = array();
     203        for ( $i = 0; $i < 5; $i++ ) {
     204            $parent = $this->factory->comment->create( array( 'comment_post_ID' => $post, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) );
     205            $comment_parents[ $i ] = $parent;
     206
     207            $child = $this->factory->comment->create( array( 'comment_post_ID' => $post, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 59 ) ), 'comment_parent' => $parent ) );
     208            $comment_children[ $i ] = $child;
     209        }
     210
     211        $page_1_indicies = array( 2, 3, 4 );
     212        $page_2_indicies = array( 0, 1 );
     213
     214        $args = array(
     215            'per_page' => 3,
     216            'max_depth' => 2,
     217        );
     218
     219        foreach ( $page_1_indicies as $p1i ) {
     220            $this->assertSame( 1, (int) get_page_of_comment( $comment_parents[ $p1i ], $args ) );
     221            $this->assertSame( 1, (int) get_page_of_comment( $comment_children[ $p1i ], $args ) );
     222        }
     223
     224        foreach ( $page_2_indicies as $p2i ) {
     225            $this->assertSame( 2, (int) get_page_of_comment( $comment_parents[ $p2i ], $args ) );
     226            $this->assertSame( 2, (int) get_page_of_comment( $comment_children[ $p2i ], $args ) );
     227        }
     228    }
    194229}
Note: See TracChangeset for help on using the changeset viewer.