Make WordPress Core


Ignore:
Timestamp:
02/05/2016 06:49:46 PM (10 years ago)
Author:
boonebgorges
Message:

Comments: Restore the ability to bypass post_id filter using 0 or '0'.

The changes introduced in [36381], while logical and clearly awesome, introduce
the potential for much breakage. Those who want to query for comments with a
null comment_post_ID should use 'post_in' => array( 0 ) instead.

Reverts [36381], [36387].
See #35090.

File:
1 edited

Legend:

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

    r36479 r36480  
    3737    }
    3838
    39     /**
    40      * @ticket 35090
    41      */
    42     public function test_post_id_0_should_return_comments_with_no_parent() {
    43         $c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
    44         $c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
     39    public function test_query_post_id_0() {
     40        $c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
    4541
    4642        $q = new WP_Comment_Query();
     
    5046        ) );
    5147
    52         $this->assertEqualSets( array( $c2 ), $found );
    53     }
    54 
    55     /**
    56      * @ticket 35090
    57      */
    58     public function test_post_id_string_0_should_return_comments_with_no_parent() {
    59         $c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
    60         $c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
    61 
    62         $q = new WP_Comment_Query();
    63         $found = $q->query( array(
    64             'post_id' => '0',
    65             'fields' => 'ids',
    66         ) );
    67 
    68         $this->assertEqualSets( array( $c2 ), $found );
    69     }
    70 
    71     /**
    72      * @ticket 35090
    73      */
    74     public function test_post_id_null_should_be_ignored() {
    75         $c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
    76         $c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
    77 
    78         $q = new WP_Comment_Query();
    79         $found = $q->query( array(
    80             'post_id' => null,
    81             'fields' => 'ids',
    82         ) );
    83 
    84         $this->assertEqualSets( array( $c1, $c2 ), $found );
    85     }
    86 
    87     /**
    88      * @ticket 35090
    89      */
    90     public function test_post_id_false_should_be_ignored() {
    91         $c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
    92         $c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
    93 
    94         $q = new WP_Comment_Query();
    95         $found = $q->query( array(
    96             'post_id' => false,
    97             'fields' => 'ids',
    98         ) );
    99 
    100         $this->assertEqualSets( array( $c1, $c2 ), $found );
    101     }
    102 
    103     /**
    104      * @ticket 35090
    105      */
    106     public function test_post_id_empty_string_should_be_ignored() {
    107         $c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
    108         $c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
    109 
    110         $q = new WP_Comment_Query();
    111         $found = $q->query( array(
    112             'post_id' => '',
    113             'fields' => 'ids',
    114         ) );
    115 
    116         $this->assertEqualSets( array( $c1, $c2 ), $found );
     48        $this->assertEqualSets( array( $c1 ), $found );
    11749    }
    11850
Note: See TracChangeset for help on using the changeset viewer.