Make WordPress Core


Ignore:
Timestamp:
10/29/2014 02:21:10 AM (12 years ago)
Author:
boonebgorges
Message:

Support multiple 'status' values in WP_Comment_Query.

This change required turning the SQL concatenation into the generation of an
array, for greater flexibility.

Props karpstrucking, ebinnion.
Fixes #29612.

File:
1 edited

Legend:

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

    r30026 r30084  
    7474
    7575                $this->assertEqualSets( array( $c1, $c3 ), $found );
     76        }
     77
     78        public function test_status_default_to_all() {
     79                $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     80                $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => 'foo' ) );
     81                $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
     82
     83                $q = new WP_Comment_Query();
     84                $found = $q->query( array(
     85                        'fields' => 'ids',
     86                ) );
     87
     88                $this->assertEqualSets( array( $c1, $c3 ), $found );
     89        }
     90
     91        /**
     92         * @ticket 29612
     93         */
     94        public function test_status_comma_any() {
     95                $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     96                $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => 'foo' ) );
     97                $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
     98
     99                $q = new WP_Comment_Query();
     100                $found = $q->query( array(
     101                        'status' => 'any',
     102                        'fields' => 'ids',
     103                ) );
     104
     105                $this->assertEqualSets( array( $c1, $c2, $c3 ), $found );
     106        }
     107
     108        /**
     109         * @ticket 29612
     110         */
     111        public function test_status_comma_separated() {
     112                $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     113                $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => 'foo' ) );
     114                $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
     115
     116                $q = new WP_Comment_Query();
     117                $found = $q->query( array(
     118                        'status' => 'approve,foo,bar',
     119                        'fields' => 'ids',
     120                ) );
     121
     122                $this->assertEqualSets( array( $c1, $c2 ), $found );
     123        }
     124
     125        /**
     126         * @ticket 29612
     127         */
     128        public function test_status_array() {
     129                $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     130                $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => 'foo' ) );
     131                $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
     132
     133                $q = new WP_Comment_Query();
     134                $found = $q->query( array(
     135                        'status' => array( 'approve', 'foo', 'bar', ),
     136                        'fields' => 'ids',
     137                ) );
     138
     139                $this->assertEqualSets( array( $c1, $c2 ), $found );
    76140        }
    77141
Note: See TracChangeset for help on using the changeset viewer.