Make WordPress Core


Ignore:
Timestamp:
10/17/2014 01:57:18 AM (10 years ago)
Author:
boonebgorges
Message:

Comment/post author in/not_in for WP_Comment_Query.

Props nofearinc, chriscct7.
Fixes #29885.

File:
1 edited

Legend:

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

    r29808 r29935  
    271271        $this->assertEqualSets( array( $c3 ), $comment_ids );
    272272    }
     273
     274    /**
     275     * @ticket 29885
     276     */
     277    function test_fields_post_author__in() {
     278        $author_id1 = 105;
     279        $author_id2 = 106;
     280
     281        $p1 = $this->factory->post->create( array( 'post_author' => $author_id1 ) );
     282        $p2 = $this->factory->post->create( array( 'post_author' => $author_id1 ) );
     283        $p3 = $this->factory->post->create( array( 'post_author' => $author_id2 ) );
     284
     285        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 1, 'comment_approved' => '1' ) );
     286        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 1, 'comment_approved' => '1' ) );
     287        $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $p3, 'user_id' => 1, 'comment_approved' => '1' ) );
     288
     289        $comment_ids = get_comments( array(
     290            'fields' => 'ids',
     291            'post_author__in' => array( $author_id1 ),
     292        ) );
     293
     294        $this->assertEqualSets( array( $c1, $c2 ), $comment_ids );
     295    }
     296
     297    /**
     298     * @ticket 29885
     299     */
     300    function test_fields_post_author__not_in() {
     301        $author_id1 = 111;
     302        $author_id2 = 112;
     303
     304        $p1 = $this->factory->post->create( array( 'post_author' => $author_id1 ) );
     305        $p2 = $this->factory->post->create( array( 'post_author' => $author_id1 ) );
     306        $p3 = $this->factory->post->create( array( 'post_author' => $author_id2 ) );
     307
     308        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 1, 'comment_approved' => '1' ) );
     309        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 1, 'comment_approved' => '1' ) );
     310        $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $p3, 'user_id' => 1, 'comment_approved' => '1' ) );
     311
     312        $comment_ids = get_comments( array(
     313            'fields' => 'ids',
     314            'post_author__not_in' => array( $author_id1 ),
     315        ) );
     316
     317        $this->assertEqualSets( array( $c3 ), $comment_ids );
     318    }
     319
     320        /**
     321         * @ticket 29885
     322         */
     323    function test_fields_author__in() {
     324        $p1 = $this->factory->post->create();
     325        $p2 = $this->factory->post->create();
     326        $p3 = $this->factory->post->create();
     327        $p4 = $this->factory->post->create();
     328
     329        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 1, 'comment_approved' => '1' ) );
     330        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 2, 'comment_approved' => '1' ) );
     331        $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 3, 'comment_approved' => '1' ) );
     332        $c4 = $this->factory->comment->create( array( 'comment_post_ID' => $p4, 'user_id' => 4, 'comment_approved' => '1' ) );
     333
     334        $comment_ids = get_comments( array(
     335            'fields' => 'ids',
     336            'author__in' => array( 1, 3 ),
     337        ) );
     338
     339        $this->assertEqualSets( array( $c1, $c3 ), $comment_ids );
     340    }
     341
     342        /**
     343         * @ticket 29885
     344         */
     345    function test_fields_author__not_in() {
     346        $p1 = $this->factory->post->create();
     347        $p2 = $this->factory->post->create();
     348        $p3 = $this->factory->post->create();
     349        $p4 = $this->factory->post->create();
     350
     351        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 1, 'comment_approved' => '1' ) );
     352        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 2, 'comment_approved' => '1' ) );
     353        $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 3, 'comment_approved' => '1' ) );
     354        $c4 = $this->factory->comment->create( array( 'comment_post_ID' => $p4, 'user_id' => 4, 'comment_approved' => '1' ) );
     355
     356        $comment_ids = get_comments( array(
     357            'fields' => 'ids',
     358            'author__not_in' => array( 1, 2 ),
     359        ) );
     360
     361        $this->assertEqualSets( array( $c3, $c4 ), $comment_ids );
     362    }
    273363}
Note: See TracChangeset for help on using the changeset viewer.