Make WordPress Core

Ticket #29612: 29612.diff

File 29612.diff, 3.1 KB (added by ebinnion, 12 years ago)

Updates patch to include unit tests.

  • src/wp-includes/comment.php

     
    303303                        return $cache;
    304304                }
    305305
    306                 $status = $this->query_vars['status'];
    307                 if ( 'hold' == $status ) {
    308                         $approved = "comment_approved = '0'";
    309                 } elseif ( 'approve' == $status ) {
    310                         $approved = "comment_approved = '1'";
    311                 } elseif ( ! empty( $status ) && 'all' != $status ) {
    312                         $approved = $wpdb->prepare( "comment_approved = %s", $status );
    313                 } else {
    314                         $approved = "( comment_approved = '0' OR comment_approved = '1' )";
     306                $status_queries = array();
     307                $statuses       = empty( $this->query_vars['status'] ) ? array( 'all' ) : (array) $this->query_vars['status'];
     308
     309                foreach ( $statuses as $s ) {
     310                        if ( 'hold' == $s || '0' == $s ) {
     311                                        $status_queries['hold'] = "comment_approved = '0'";
     312                        } elseif ( 'approve' == $s  || '1' == $s ) {
     313                                        $status_queries['approve'] = "comment_approved = '1'";
     314                        } elseif ( 'all' == $s ) {
     315                                        $status_queries['hold'] = "comment_approved = '0'";
     316                                        $status_queries['approve'] = "comment_approved = '1'";
     317                        } else  {
     318                                        $status_queries[ $s ] = $wpdb->prepare( "comment_approved = %s", $s );
     319                        }
    315320                }
     321
     322                $approved = "( " . implode( " OR ", $status_queries ) . " )";
     323
    316324                $order = ( 'ASC' == strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC';
    317325
    318326                if ( ! empty( $this->query_vars['orderby'] ) ) {
  • tests/phpunit/tests/comment/query.php

     
    1616        }
    1717
    1818        /**
     19         * @ticket 29612
     20         */
     21        function test_get_comments_by_status_array_3() {
     22                $approved_comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     23                $trashed_comment_id  = $this->factory->comment->create(
     24                        array(
     25                                'comment_post_ID' => $this->post_id,
     26                                'comment_approved' => 'trash'
     27                        )
     28                );
     29                $hold_comment_id = $this->factory->comment->create(
     30                        array(
     31                                'comment_post_ID' => $this->post_id,
     32                                'comment_approved' => 0
     33                        )
     34                );
     35
     36                $comments_by_array = get_comments(
     37                        array(
     38                                'status' => array( 'approve', 'hold', 'trash' )
     39                        )
     40                );
     41
     42                $this->assertEquals( 3, count( $comments_by_array ) );
     43        }
     44
     45        function test_get_comments_by_status_array_2() {
     46                $approved_comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     47                $trashed_comment_id  = $this->factory->comment->create(
     48                        array(
     49                                'comment_post_ID' => $this->post_id,
     50                                'comment_approved' => 'trash'
     51                        )
     52                );
     53                $hold_comment_id = $this->factory->comment->create(
     54                        array(
     55                                'comment_post_ID' => $this->post_id,
     56                                'comment_approved' => 0
     57                        )
     58                );
     59
     60                $comments_by_array = get_comments(
     61                        array(
     62                                'status' => array( 'approve', 'hold' )
     63                        )
     64                );
     65
     66                $this->assertEquals( 2, count( $comments_by_array ) );
     67        }
     68
     69        /**
    1970         * @ticket 21101
    2071         */
    2172        function test_get_comment_comment_approved_0() {