Make WordPress Core


Ignore:
Timestamp:
09/26/2015 02:24:17 AM (9 years ago)
Author:
wonderboymusic
Message:

Comments: in WP_Comment::get_children(), accept an array so that the values for format, status, hierarchical, and orderby can be passed, instead of just format. The defaults for get_comments() include status = 'all' and orderby = '' - which is no bueno.

For threaded comments, we need comments to be retrieved within bounds, so logged-out users don't see unmoderated comments on the front end, etc.

Updates unit tests.

See #8071.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/query.php

    r34550 r34569  
    20242024        ) );
    20252025
    2026         $q = new WP_Comment_Query( array(
    2027             'post_id' => $this->post_id,
     2026        $args = array(
    20282027            'hierarchical' => 'threaded',
    20292028            'orderby' => 'comment_ID',
    20302029            'order' => 'ASC',
    2031         ) );
     2030        );
     2031
     2032        $query_args = array_merge( $args, array(
     2033            'post_id' => $this->post_id,
     2034        ) );
     2035
     2036        $q = new WP_Comment_Query( $query_args );
    20322037
    20332038        // Top-level comments.
     
    20352040
    20362041        // Direct descendants of $c1.
    2037         $this->assertEqualSets( array( $c2, $c4 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_children(), 'comment_ID' ) ) );
     2042        $this->assertEqualSets( array( $c2, $c4 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_children( $args ), 'comment_ID' ) ) );
    20382043
    20392044        // Direct descendants of $c2.
    2040         $this->assertEqualSets( array( $c3 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_child( $c2 )->get_children(), 'comment_ID' ) ) );
     2045        $this->assertEqualSets( array( $c3 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_child( $c2 )->get_children( $args ), 'comment_ID' ) ) );
    20412046
    20422047        // Direct descendants of $c5.
    2043         $this->assertEqualSets( array( $c6 ), array_values( wp_list_pluck( $q->comments[ $c5 ]->get_children(), 'comment_ID' ) ) );
     2048        $this->assertEqualSets( array( $c6 ), array_values( wp_list_pluck( $q->comments[ $c5 ]->get_children( $args ), 'comment_ID' ) ) );
     2049    }
     2050
     2051    /**
     2052     * @ticket 8071
     2053     */
     2054    public function test_hierarchical_threaded_approved() {
     2055        $c1 = $this->factory->comment->create( array(
     2056            'comment_post_ID' => $this->post_id,
     2057            'comment_approved' => '1',
     2058        ) );
     2059
     2060        $c2 = $this->factory->comment->create( array(
     2061            'comment_post_ID' => $this->post_id,
     2062            'comment_approved' => '1',
     2063            'comment_parent' => $c1,
     2064        ) );
     2065
     2066        $c3 = $this->factory->comment->create( array(
     2067            'comment_post_ID' => $this->post_id,
     2068            'comment_approved' => '0',
     2069            'comment_parent' => $c2,
     2070        ) );
     2071
     2072        $c4 = $this->factory->comment->create( array(
     2073            'comment_post_ID' => $this->post_id,
     2074            'comment_approved' => '1',
     2075            'comment_parent' => $c1,
     2076        ) );
     2077
     2078        $c5 = $this->factory->comment->create( array(
     2079            'comment_post_ID' => $this->post_id,
     2080            'comment_approved' => '1',
     2081        ) );
     2082
     2083        $this->factory->comment->create( array(
     2084            'comment_post_ID' => $this->post_id,
     2085            'comment_approved' => '1',
     2086            'comment_parent' => $c5,
     2087        ) );
     2088
     2089        $args = array(
     2090            'hierarchical' => 'threaded',
     2091            'status' => 'approve',
     2092            'orderby' => 'comment_ID',
     2093            'order' => 'ASC',
     2094        );
     2095
     2096        $query_args = array_merge( $args, array(
     2097            'post_id' => $this->post_id,
     2098        ) );
     2099
     2100        $q = new WP_Comment_Query( $query_args );
     2101
     2102        // Top-level comments.
     2103        $this->assertEqualSets( array( $c1, $c5 ), array_values( wp_list_pluck( $q->comments, 'comment_ID' ) ) );
     2104
     2105        // Direct descendants of $c1.
     2106        $this->assertEqualSets( array( $c2, $c4 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_children( $args ), 'comment_ID' ) ) );
     2107
     2108        // Direct descendants of $c2.
     2109        $this->assertEqualSets( array(), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_child( $c2 )->get_children( $args ), 'comment_ID' ) ) );
    20442110    }
    20452111}
Note: See TracChangeset for help on using the changeset viewer.