Make WordPress Core


Ignore:
Timestamp:
05/08/2015 07:44:06 PM (11 years ago)
Author:
boonebgorges
Message:

Use table prefix for comment__in and comment__not_in SQL clauses of WP_Comment_Query.

The prefix prevents ambiguity when joining against other tables.

Props willgladstone.
Fixes #32081.

File:
1 edited

Legend:

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

    r31793 r32461  
    723723        }
    724724
     725        /**
     726         * @group 32081
     727         */
     728        public function test_meta_query_should_work_with_comment__in() {
     729                $comments = $this->factory->comment->create_many( 3 );
     730
     731                add_comment_meta( $comments[0], 'foo', 'jjj' );
     732                add_comment_meta( $comments[1], 'foo', 'zzz' );
     733                add_comment_meta( $comments[2], 'foo', 'jjj' );
     734
     735                $q = new WP_Comment_Query( array(
     736                        'comment__in' => array( $comments[1], $comments[2] ),
     737                        'meta_query' => array(
     738                                array(
     739                                        'key' => 'foo',
     740                                        'value' => 'jjj',
     741                                ),
     742                        ),
     743                        'fields' => 'ids',
     744                ) );
     745
     746                $this->assertEquals( array( $comments[2] ), $q->get_comments() );
     747        }
     748
     749        /**
     750         * @group 32081
     751         */
     752        public function test_meta_query_should_work_with_comment__not_in() {
     753                $comments = $this->factory->comment->create_many( 3 );
     754
     755                add_comment_meta( $comments[0], 'foo', 'jjj' );
     756                add_comment_meta( $comments[1], 'foo', 'zzz' );
     757                add_comment_meta( $comments[2], 'foo', 'jjj' );
     758
     759                $q = new WP_Comment_Query( array(
     760                        'comment__not_in' => array( $comments[1], $comments[2] ),
     761                        'meta_query' => array(
     762                                array(
     763                                        'key' => 'foo',
     764                                        'value' => 'jjj',
     765                                ),
     766                        ),
     767                        'fields' => 'ids',
     768                ) );
     769
     770                $this->assertEquals( array( $comments[0] ), $q->get_comments() );
     771        }
    725772
    726773        /**
Note: See TracChangeset for help on using the changeset viewer.