Ticket #35090: 35090.diff
| File 35090.diff, 4.6 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/class-wp-comment-query.php
diff --git src/wp-includes/class-wp-comment-query.php src/wp-includes/class-wp-comment-query.php index eb6f094..71cd525 100644
class WP_Comment_Query { 214 214 * Default empty. 215 215 * @type int $post_ID Currently unused. 216 216 * @type int $post_id Limit results to those affiliated with a given post ID. 217 * Default 0.217 * Default null. 218 218 * @type array $post__in Array of post IDs to include affiliated comments for. 219 219 * Default empty. 220 220 * @type array $post__not_in Array of post IDs to exclude affiliated comments for. … … class WP_Comment_Query { 276 276 'post_author__in' => '', 277 277 'post_author__not_in' => '', 278 278 'post_ID' => '', 279 'post_id' => 0,279 'post_id' => null, 280 280 'post__in' => '', 281 281 'post__not_in' => '', 282 282 'post_author' => '', … … class WP_Comment_Query { 645 645 $fields = "$wpdb->comments.comment_ID"; 646 646 } 647 647 648 $post_id = absint( $this->query_vars['post_id'] ); 649 if ( ! empty( $post_id ) ) { 650 $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id ); 648 if ( strlen( $this->query_vars['post_id'] ) ) { 649 $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $this->query_vars['post_id'] ); 651 650 } 652 651 653 652 // Parse comment IDs for an IN clause. -
tests/phpunit/tests/comment/query.php
diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php index 6de468e..92dbcad 100644
class Tests_Comment_Query extends WP_UnitTestCase { 36 36 $this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found ); 37 37 } 38 38 39 public function test_query_post_id_0() { 39 /** 40 * @ticket 35090 41 */ 42 public function test_post_id_0_should_return_comments_with_no_parent() { 40 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' ) ); 41 45 42 46 $q = new WP_Comment_Query(); 43 47 $found = $q->query( array( … … class Tests_Comment_Query extends WP_UnitTestCase { 45 49 'fields' => 'ids', 46 50 ) ); 47 51 48 $this->assertEqualSets( array( $c1 ), $found ); 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 ); 49 117 } 50 118 51 119 /**
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)