1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// Test the output of Comment Querying functions |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @group comment |
7
|
|
|
*/ |
8
|
|
|
class Tests_Comment_Query extends WP_UnitTestCase { |
9
|
|
|
protected static $post_id; |
10
|
|
|
protected $comment_id; |
11
|
|
|
|
12
|
|
|
public static function wpSetUpBeforeClass( $factory ) { |
13
|
|
|
self::$post_id = $factory->post->create(); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
function setUp() { |
17
|
|
|
parent::setUp(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function test_query() { |
21
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
22
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
23
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
24
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
25
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
26
|
|
|
|
27
|
|
|
$q = new WP_Comment_Query(); |
28
|
|
|
$found = $q->query( array( |
29
|
|
|
'fields' => 'ids', |
30
|
|
|
) ); |
31
|
|
|
|
32
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function test_query_post_id_0() { |
36
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
37
|
|
|
|
38
|
|
|
$q = new WP_Comment_Query(); |
39
|
|
|
$found = $q->query( array( |
40
|
|
|
'post_id' => 0, |
41
|
|
|
'fields' => 'ids', |
42
|
|
|
) ); |
43
|
|
|
|
44
|
|
|
$this->assertEqualSets( array( $c1 ), $found ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @ticket 12668 |
49
|
|
|
*/ |
50
|
|
|
public function test_query_type_empty_string() { |
51
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
52
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
53
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
54
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
55
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
56
|
|
|
|
57
|
|
|
$q = new WP_Comment_Query(); |
58
|
|
|
$found = $q->query( array( |
59
|
|
|
'type' => '', |
60
|
|
|
'fields' => 'ids', |
61
|
|
|
) ); |
62
|
|
|
|
63
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @ticket 12668 |
68
|
|
|
*/ |
69
|
|
|
public function test_query_type_comment() { |
70
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
71
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
|
|
|
|
72
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
|
|
|
|
73
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
|
|
|
|
74
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
|
|
|
|
75
|
|
|
|
76
|
|
|
$q = new WP_Comment_Query(); |
77
|
|
|
$found = $q->query( array( |
78
|
|
|
'type' => 'comment', |
79
|
|
|
'fields' => 'ids', |
80
|
|
|
) ); |
81
|
|
|
|
82
|
|
|
$this->assertEqualSets( array( $c1 ), $found ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function test_query_type_pingback() { |
86
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
87
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
88
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
89
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
|
|
|
|
90
|
|
|
|
91
|
|
|
$q = new WP_Comment_Query(); |
92
|
|
|
$found = $q->query( array( |
93
|
|
|
'type' => 'pingback', |
94
|
|
|
'fields' => 'ids', |
95
|
|
|
) ); |
96
|
|
|
|
97
|
|
|
$this->assertEqualSets( array( $c2, $c3 ), $found ); |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function test_query_type_trackback() { |
102
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
103
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
104
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
105
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
|
|
|
|
106
|
|
|
|
107
|
|
|
$q = new WP_Comment_Query(); |
108
|
|
|
$found = $q->query( array( |
109
|
|
|
'type' => 'trackback', |
110
|
|
|
'fields' => 'ids', |
111
|
|
|
) ); |
112
|
|
|
|
113
|
|
|
$this->assertEqualSets( array( $c2, $c3 ), $found ); |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* 'pings' is an alias for 'trackback' + 'pingback'. |
119
|
|
|
*/ |
120
|
|
|
public function test_query_type_pings() { |
121
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
122
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
123
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
124
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
|
|
|
|
125
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
|
|
|
|
126
|
|
|
|
127
|
|
|
$q = new WP_Comment_Query(); |
128
|
|
|
$found = $q->query( array( |
129
|
|
|
'type' => 'pings', |
130
|
|
|
'fields' => 'ids', |
131
|
|
|
) ); |
132
|
|
|
|
133
|
|
|
$this->assertEqualSets( array( $c2, $c3 ), $found ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Comments and custom |
138
|
|
|
* @ticket 12668 |
139
|
|
|
*/ |
140
|
|
|
public function test_type_array_comments_and_custom() { |
141
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
142
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
|
|
|
|
143
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
|
|
|
|
144
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
145
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
|
|
|
|
146
|
|
|
$c6 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
147
|
|
|
|
148
|
|
|
$q = new WP_Comment_Query(); |
149
|
|
|
$found = $q->query( array( |
150
|
|
|
'type' => array( 'comments', 'mario' ), |
151
|
|
|
'fields' => 'ids', |
152
|
|
|
) ); |
153
|
|
|
|
154
|
|
|
$this->assertEqualSets( array( $c1, $c4, $c6 ), $found ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @ticket 12668 |
159
|
|
|
*/ |
160
|
|
|
public function test_type_not__in_array_custom() { |
161
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
162
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
163
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
164
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
165
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
|
|
|
|
166
|
|
|
$c6 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
167
|
|
|
|
168
|
|
|
$q = new WP_Comment_Query(); |
169
|
|
|
$found = $q->query( array( |
170
|
|
|
'type__not_in' => array( 'luigi' ), |
171
|
|
|
'fields' => 'ids', |
172
|
|
|
) ); |
173
|
|
|
|
174
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c6 ), $found ); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @ticket 12668 |
179
|
|
|
*/ |
180
|
|
|
public function test_type__in_array_and_not_type_array_custom() { |
181
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
182
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
|
|
|
|
183
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
|
|
|
|
184
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
|
|
|
|
185
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
|
|
|
|
186
|
|
|
$c6 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
|
|
|
|
187
|
|
|
|
188
|
|
|
$q = new WP_Comment_Query(); |
189
|
|
|
$found = $q->query( array( |
190
|
|
|
'type__in' => array( 'comments' ), |
191
|
|
|
'type__not_in' => array( 'luigi' ), |
192
|
|
|
'fields' => 'ids', |
193
|
|
|
) ); |
194
|
|
|
|
195
|
|
|
$this->assertEqualSets( array( $c1 ), $found ); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @ticket 12668 |
200
|
|
|
*/ |
201
|
|
|
public function test_type_array_and_type__not_in_array_custom() { |
202
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
203
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
204
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
205
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
|
|
|
|
206
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
|
|
|
|
207
|
|
|
$c6 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
|
|
|
|
208
|
|
|
|
209
|
|
|
$q = new WP_Comment_Query(); |
210
|
|
|
$found = $q->query( array( |
211
|
|
|
'type' => array( 'pings' ), |
212
|
|
|
'type__not_in' => array( 'mario' ), |
213
|
|
|
'fields' => 'ids', |
214
|
|
|
) ); |
215
|
|
|
|
216
|
|
|
$this->assertEqualSets( array( $c2, $c3 ), $found ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @ticket 12668 |
221
|
|
|
*/ |
222
|
|
|
public function test_type__not_in_custom() { |
223
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
224
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
225
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
226
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
227
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
|
|
|
|
228
|
|
|
$c6 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
229
|
|
|
|
230
|
|
|
$q = new WP_Comment_Query(); |
231
|
|
|
$found = $q->query( array( |
232
|
|
|
'type__not_in' => 'luigi', |
233
|
|
|
'fields' => 'ids', |
234
|
|
|
) ); |
235
|
|
|
|
236
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c6 ), $found ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @ticket 12668 |
241
|
|
|
*/ |
242
|
|
|
public function test_type_array_comments_and_pings() { |
243
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
244
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
245
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
246
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) ); |
|
|
|
|
247
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) ); |
|
|
|
|
248
|
|
|
|
249
|
|
|
$q = new WP_Comment_Query(); |
250
|
|
|
$found = $q->query( array( |
251
|
|
|
'type' => array( 'comments', 'pings' ), |
252
|
|
|
'fields' => 'ids', |
253
|
|
|
) ); |
254
|
|
|
|
255
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3 ), $found ); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @ticket 12668 |
260
|
|
|
*/ |
261
|
|
|
public function test_type_array_comment_pings() { |
262
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
263
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
264
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
265
|
|
|
|
266
|
|
|
$q = new WP_Comment_Query(); |
267
|
|
|
$found = $q->query( array( |
268
|
|
|
'type' => array( 'comment', 'pings' ), |
269
|
|
|
'fields' => 'ids', |
270
|
|
|
) ); |
271
|
|
|
|
272
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3 ), $found ); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @ticket 12668 |
277
|
|
|
*/ |
278
|
|
|
public function test_type_array_pingback() { |
279
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
280
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
281
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
|
|
|
|
282
|
|
|
|
283
|
|
|
$q = new WP_Comment_Query(); |
284
|
|
|
$found = $q->query( array( |
285
|
|
|
'type' => array( 'pingback' ), |
286
|
|
|
'fields' => 'ids', |
287
|
|
|
) ); |
288
|
|
|
|
289
|
|
|
$this->assertEquals( array( $c2 ), $found ); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @ticket 12668 |
294
|
|
|
*/ |
295
|
|
|
public function test_type_array_custom_pingpack() { |
296
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
297
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
298
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
|
|
|
|
299
|
|
|
|
300
|
|
|
$q = new WP_Comment_Query(); |
301
|
|
|
$found = $q->query( array( |
302
|
|
|
'type' => array( 'peach', 'pingback' ), |
303
|
|
|
'fields' => 'ids', |
304
|
|
|
) ); |
305
|
|
|
|
306
|
|
|
$this->assertEquals( array( $c2 ), $found ); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @ticket 12668 |
311
|
|
|
*/ |
312
|
|
|
public function test_type_array_pings() { |
313
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
314
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
315
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
316
|
|
|
|
317
|
|
|
$q = new WP_Comment_Query(); |
318
|
|
|
$found = $q->query( array( |
319
|
|
|
'type' => array( 'pings' ), |
320
|
|
|
'fields' => 'ids', |
321
|
|
|
) ); |
322
|
|
|
|
323
|
|
|
$this->assertEqualSets( array( $c2, $c3 ), $found ); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @ticket 12668 |
328
|
|
|
*/ |
329
|
|
|
public function test_type_status_approved_array_comment_pings() { |
330
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
331
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
332
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
333
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0', 'comment_type' => 'pingback' ) ); |
|
|
|
|
334
|
|
|
|
335
|
|
|
$q = new WP_Comment_Query(); |
336
|
|
|
$found = $q->query( array( |
337
|
|
|
'status' => 'approve', |
338
|
|
|
'type' => array( 'pings' ), |
339
|
|
|
'fields' => 'ids', |
340
|
|
|
) ); |
341
|
|
|
|
342
|
|
|
$this->assertEqualSets( array( $c3, $c2 ), $found ); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* @ticket 12668 |
347
|
|
|
*/ |
348
|
|
|
public function test_type_array_trackback() { |
349
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
350
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
351
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
|
|
|
|
352
|
|
|
|
353
|
|
|
$q = new WP_Comment_Query(); |
354
|
|
|
$found = $q->query( array( |
355
|
|
|
'type' => array( 'trackback' ), |
356
|
|
|
'fields' => 'ids', |
357
|
|
|
) ); |
358
|
|
|
|
359
|
|
|
$this->assertEquals( array( $c2 ), $found ); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @ticket 12668 |
364
|
|
|
*/ |
365
|
|
|
public function test_type_array_custom_trackback() { |
366
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
367
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
368
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) ); |
|
|
|
|
369
|
|
|
|
370
|
|
|
$q = new WP_Comment_Query(); |
371
|
|
|
$found = $q->query( array( |
372
|
|
|
'type' => array( 'toad', 'trackback' ), |
373
|
|
|
'fields' => 'ids', |
374
|
|
|
) ); |
375
|
|
|
|
376
|
|
|
$this->assertEquals( array( $c2 ), $found ); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* @ticket 12668 |
381
|
|
|
*/ |
382
|
|
|
public function test_type_array_pings_approved() { |
383
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
384
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
385
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) ); |
386
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0', 'comment_type' => 'trackback' ) ); |
|
|
|
|
387
|
|
|
|
388
|
|
|
$q = new WP_Comment_Query(); |
389
|
|
|
$found = $q->query( array( |
390
|
|
|
'status' => 'approve', |
391
|
|
|
'type' => array( 'pings' ), |
392
|
|
|
'fields' => 'ids', |
393
|
|
|
) ); |
394
|
|
|
|
395
|
|
|
$this->assertEqualSets( array( $c3, $c2 ), $found ); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* @ticket 29612 |
400
|
|
|
*/ |
401
|
|
|
public function test_status_empty_string() { |
402
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
403
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0' ) ); |
404
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => 'spam' ) ); |
|
|
|
|
405
|
|
|
|
406
|
|
|
$q = new WP_Comment_Query(); |
407
|
|
|
$found = $q->query( array( |
408
|
|
|
'status' => '', |
409
|
|
|
'fields' => 'ids', |
410
|
|
|
) ); |
411
|
|
|
|
412
|
|
|
$this->assertEqualSets( array( $c1, $c2 ), $found ); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* @ticket 21101 |
417
|
|
|
*/ |
418
|
|
|
public function test_status_hold() { |
419
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
420
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0' ) ); |
421
|
|
|
|
422
|
|
|
$q = new WP_Comment_Query(); |
423
|
|
|
$found = $q->query( array( |
424
|
|
|
'status' => 'hold', |
425
|
|
|
'fields' => 'ids', |
426
|
|
|
) ); |
427
|
|
|
|
428
|
|
|
$this->assertEquals( array( $c2 ), $found ); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* @ticket 21101 |
433
|
|
|
*/ |
434
|
|
|
public function test_status_approve() { |
435
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
436
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0' ) ); |
|
|
|
|
437
|
|
|
|
438
|
|
|
$q = new WP_Comment_Query(); |
439
|
|
|
$found = $q->query( array( |
440
|
|
|
'status' => 'approve', |
441
|
|
|
'fields' => 'ids', |
442
|
|
|
) ); |
443
|
|
|
|
444
|
|
|
$this->assertEquals( array( $c1 ), $found ); |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
public function test_status_custom() { |
448
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
449
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => 'foo' ) ); |
450
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => 'foo1' ) ); |
|
|
|
|
451
|
|
|
|
452
|
|
|
$q = new WP_Comment_Query(); |
453
|
|
|
$found = $q->query( array( |
454
|
|
|
'status' => 'foo', |
455
|
|
|
'fields' => 'ids', |
456
|
|
|
) ); |
457
|
|
|
|
458
|
|
|
$this->assertEquals( array( $c2 ), $found ); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
public function test_status_all() { |
462
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
463
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => 'foo' ) ); |
|
|
|
|
464
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0' ) ); |
465
|
|
|
|
466
|
|
|
$q = new WP_Comment_Query(); |
467
|
|
|
$found = $q->query( array( |
468
|
|
|
'status' => 'all', |
469
|
|
|
'fields' => 'ids', |
470
|
|
|
) ); |
471
|
|
|
|
472
|
|
|
$this->assertEqualSets( array( $c1, $c3 ), $found ); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
public function test_status_default_to_all() { |
476
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
477
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => 'foo' ) ); |
|
|
|
|
478
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0' ) ); |
479
|
|
|
|
480
|
|
|
$q = new WP_Comment_Query(); |
481
|
|
|
$found = $q->query( array( |
482
|
|
|
'fields' => 'ids', |
483
|
|
|
) ); |
484
|
|
|
|
485
|
|
|
$this->assertEqualSets( array( $c1, $c3 ), $found ); |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
/** |
489
|
|
|
* @ticket 29612 |
490
|
|
|
*/ |
491
|
|
|
public function test_status_comma_any() { |
492
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
493
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => 'foo' ) ); |
494
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0' ) ); |
495
|
|
|
|
496
|
|
|
$q = new WP_Comment_Query(); |
497
|
|
|
$found = $q->query( array( |
498
|
|
|
'status' => 'any', |
499
|
|
|
'fields' => 'ids', |
500
|
|
|
) ); |
501
|
|
|
|
502
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3 ), $found ); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* @ticket 29612 |
507
|
|
|
*/ |
508
|
|
|
public function test_status_comma_separated() { |
509
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
510
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => 'foo' ) ); |
511
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0' ) ); |
|
|
|
|
512
|
|
|
|
513
|
|
|
$q = new WP_Comment_Query(); |
514
|
|
|
$found = $q->query( array( |
515
|
|
|
'status' => 'approve,foo,bar', |
516
|
|
|
'fields' => 'ids', |
517
|
|
|
) ); |
518
|
|
|
|
519
|
|
|
$this->assertEqualSets( array( $c1, $c2 ), $found ); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
/** |
523
|
|
|
* @ticket 29612 |
524
|
|
|
*/ |
525
|
|
|
public function test_status_array() { |
526
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
527
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => 'foo' ) ); |
528
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '0' ) ); |
|
|
|
|
529
|
|
|
|
530
|
|
|
$q = new WP_Comment_Query(); |
531
|
|
|
$found = $q->query( array( |
532
|
|
|
'status' => array( 'approve', 'foo', 'bar', ), |
533
|
|
|
'fields' => 'ids', |
534
|
|
|
) ); |
535
|
|
|
|
536
|
|
|
$this->assertEqualSets( array( $c1, $c2 ), $found ); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
/** |
540
|
|
|
* @ticket 35478 |
541
|
|
|
*/ |
542
|
|
|
public function test_multiple_post_fields_should_all_be_respected() { |
543
|
|
|
$posts = array(); |
544
|
|
|
|
545
|
|
|
$posts[] = self::factory()->post->create( array( |
546
|
|
|
'post_status' => 'publish', |
547
|
|
|
'post_author' => 3, |
548
|
|
|
) ); |
549
|
|
|
|
550
|
|
|
$posts[] = self::factory()->post->create( array( |
551
|
|
|
'post_status' => 'draft', |
552
|
|
|
'post_author' => 4, |
553
|
|
|
) ); |
554
|
|
|
|
555
|
|
|
$posts[] = self::factory()->post->create( array( |
556
|
|
|
'post_status' => 'draft', |
557
|
|
|
'post_author' => 3, |
558
|
|
|
) ); |
559
|
|
|
|
560
|
|
|
$comments = array(); |
561
|
|
|
foreach ( $posts as $post ) { |
562
|
|
|
$comments[] = self::factory()->comment->create( array( |
563
|
|
|
'comment_post_ID' => $post, |
564
|
|
|
) ); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
$q = new WP_Comment_Query( array( |
568
|
|
|
'post_status' => 'draft', |
569
|
|
|
'post_author' => 3, |
570
|
|
|
'fields' => 'ids', |
571
|
|
|
) ); |
572
|
|
|
|
573
|
|
|
$this->assertSame( array( $comments[2] ), $q->comments ); |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
function test_get_comments_for_post() { |
577
|
|
|
$limit = 5; |
578
|
|
|
|
579
|
|
|
$post_id = self::factory()->post->create(); |
580
|
|
|
self::factory()->comment->create_post_comments( $post_id, $limit ); |
581
|
|
|
$comments = get_comments( array( 'post_id' => $post_id ) ); |
582
|
|
|
$this->assertEquals( $limit, count( $comments ) ); |
583
|
|
|
foreach ( $comments as $comment ) { |
|
|
|
|
584
|
|
|
$this->assertEquals( $post_id, $comment->comment_post_ID ); |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
$post_id2 = self::factory()->post->create(); |
588
|
|
|
self::factory()->comment->create_post_comments( $post_id2, $limit ); |
589
|
|
|
$comments = get_comments( array( 'post_id' => $post_id2 ) ); |
590
|
|
|
$this->assertEquals( $limit, count( $comments ) ); |
591
|
|
|
foreach ( $comments as $comment ) { |
|
|
|
|
592
|
|
|
$this->assertEquals( $post_id2, $comment->comment_post_ID ); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
$post_id3 = self::factory()->post->create(); |
596
|
|
|
self::factory()->comment->create_post_comments( $post_id3, $limit, array( 'comment_approved' => '0' ) ); |
597
|
|
|
$comments = get_comments( array( 'post_id' => $post_id3 ) ); |
598
|
|
|
$this->assertEquals( $limit, count( $comments ) ); |
599
|
|
|
foreach ( $comments as $comment ) { |
|
|
|
|
600
|
|
|
$this->assertEquals( $post_id3, $comment->comment_post_ID ); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
$comments = get_comments( array( 'post_id' => $post_id3, 'status' => 'hold' ) ); |
604
|
|
|
$this->assertEquals( $limit, count( $comments ) ); |
605
|
|
|
foreach ( $comments as $comment ) { |
|
|
|
|
606
|
|
|
$this->assertEquals( $post_id3, $comment->comment_post_ID ); |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
$comments = get_comments( array( 'post_id' => $post_id3, 'status' => 'approve' ) ); |
610
|
|
|
$this->assertEquals( 0, count( $comments ) ); |
611
|
|
|
|
612
|
|
|
self::factory()->comment->create_post_comments( $post_id3, $limit, array( 'comment_approved' => '1' ) ); |
613
|
|
|
$comments = get_comments( array( 'post_id' => $post_id3 ) ); |
614
|
|
|
$this->assertEquals( $limit * 2, count( $comments ) ); |
615
|
|
|
foreach ( $comments as $comment ) { |
|
|
|
|
616
|
|
|
$this->assertEquals( $post_id3, $comment->comment_post_ID ); |
617
|
|
|
} |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
/** |
621
|
|
|
* @ticket 21003 |
622
|
|
|
*/ |
623
|
|
|
function test_orderby_meta() { |
624
|
|
|
$comment_id = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id ) ); |
625
|
|
|
$comment_id2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id ) ); |
626
|
|
|
$comment_id3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id ) ); |
627
|
|
|
|
628
|
|
|
add_comment_meta( $comment_id, 'key', 'value1', true ); |
629
|
|
|
add_comment_meta( $comment_id, 'key1', 'value1', true ); |
630
|
|
|
add_comment_meta( $comment_id, 'key3', 'value3', true ); |
631
|
|
|
add_comment_meta( $comment_id2, 'key', 'value2', true ); |
632
|
|
|
add_comment_meta( $comment_id2, 'key2', 'value2', true ); |
633
|
|
|
add_comment_meta( $comment_id3, 'key3', 'value3', true ); |
634
|
|
|
|
635
|
|
|
$comments = get_comments( array( 'meta_key' => 'key', 'orderby' => array( 'key' ) ) ); |
636
|
|
|
$this->assertEquals( 2, count( $comments ) ); |
637
|
|
|
$this->assertEquals( $comment_id2, $comments[0]->comment_ID ); |
638
|
|
|
$this->assertEquals( $comment_id, $comments[1]->comment_ID ); |
639
|
|
|
|
640
|
|
|
$comments = get_comments( array( 'meta_key' => 'key', 'orderby' => array( 'meta_value' ) ) ); |
641
|
|
|
$this->assertEquals( 2, count( $comments ) ); |
642
|
|
|
$this->assertEquals( $comment_id2, $comments[0]->comment_ID ); |
643
|
|
|
$this->assertEquals( $comment_id, $comments[1]->comment_ID ); |
644
|
|
|
|
645
|
|
|
$comments = get_comments( array( 'meta_key' => 'key', 'orderby' => array( 'key' ), 'order' => 'ASC' ) ); |
646
|
|
|
$this->assertEquals( 2, count( $comments ) ); |
647
|
|
|
$this->assertEquals( $comment_id, $comments[0]->comment_ID ); |
648
|
|
|
$this->assertEquals( $comment_id2, $comments[1]->comment_ID ); |
649
|
|
|
|
650
|
|
|
$comments = get_comments( array( 'meta_key' => 'key', 'orderby' => array( 'meta_value' ), 'order' => 'ASC' ) ); |
651
|
|
|
$this->assertEquals( 2, count( $comments ) ); |
652
|
|
|
$this->assertEquals( $comment_id, $comments[0]->comment_ID ); |
653
|
|
|
$this->assertEquals( $comment_id2, $comments[1]->comment_ID ); |
654
|
|
|
|
655
|
|
|
$comments = get_comments( array( 'meta_value' => 'value3', 'orderby' => array( 'key' ) ) ); |
656
|
|
|
$this->assertEquals( array( $comment_id3, $comment_id ), wp_list_pluck( $comments, 'comment_ID' ) ); |
657
|
|
|
|
658
|
|
|
$comments = get_comments( array( 'meta_value' => 'value3', 'orderby' => array( 'meta_value' ) ) ); |
659
|
|
|
$this->assertEquals( array( $comment_id3, $comment_id ), wp_list_pluck( $comments, 'comment_ID' ) ); |
660
|
|
|
|
661
|
|
|
// value1 is present on two different keys for $comment_id yet we should get only one instance |
662
|
|
|
// of that comment in the results |
663
|
|
|
$comments = get_comments( array( 'meta_value' => 'value1', 'orderby' => array( 'key' ) ) ); |
664
|
|
|
$this->assertEquals( 1, count( $comments ) ); |
665
|
|
|
|
666
|
|
|
$comments = get_comments( array( 'meta_value' => 'value1', 'orderby' => array( 'meta_value' ) ) ); |
667
|
|
|
$this->assertEquals( 1, count( $comments ) ); |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* @ticket 30478 |
672
|
|
|
*/ |
673
|
|
|
public function test_orderby_clause_key() { |
674
|
|
|
$comments = self::factory()->comment->create_many( 3 ); |
675
|
|
|
add_comment_meta( $comments[0], 'foo', 'aaa' ); |
676
|
|
|
add_comment_meta( $comments[1], 'foo', 'zzz' ); |
677
|
|
|
add_comment_meta( $comments[2], 'foo', 'jjj' ); |
678
|
|
|
|
679
|
|
|
$q = new WP_Comment_Query(); |
680
|
|
|
$found = $q->query( array( |
681
|
|
|
'fields' => 'ids', |
682
|
|
|
'meta_query' => array( |
683
|
|
|
'foo_key' => array( |
684
|
|
|
'key' => 'foo', |
685
|
|
|
'compare' => 'EXISTS', |
686
|
|
|
), |
687
|
|
|
), |
688
|
|
|
'orderby' => 'foo_key', |
689
|
|
|
'order' => 'DESC', |
690
|
|
|
) ); |
691
|
|
|
|
692
|
|
|
$this->assertEquals( array( $comments[1], $comments[2], $comments[0] ), $found ); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
/** |
696
|
|
|
* @ticket 30478 |
697
|
|
|
*/ |
698
|
|
|
public function test_orderby_clause_key_as_secondary_sort() { |
699
|
|
|
$c1 = self::factory()->comment->create( array( |
700
|
|
|
'comment_date' => '2015-01-28 03:00:00', |
701
|
|
|
) ); |
702
|
|
|
$c2 = self::factory()->comment->create( array( |
703
|
|
|
'comment_date' => '2015-01-28 05:00:00', |
704
|
|
|
) ); |
705
|
|
|
$c3 = self::factory()->comment->create( array( |
706
|
|
|
'comment_date' => '2015-01-28 03:00:00', |
707
|
|
|
) ); |
708
|
|
|
|
709
|
|
|
add_comment_meta( $c1, 'foo', 'jjj' ); |
710
|
|
|
add_comment_meta( $c2, 'foo', 'zzz' ); |
711
|
|
|
add_comment_meta( $c3, 'foo', 'aaa' ); |
712
|
|
|
|
713
|
|
|
$q = new WP_Comment_Query(); |
714
|
|
|
$found = $q->query( array( |
715
|
|
|
'fields' => 'ids', |
716
|
|
|
'meta_query' => array( |
717
|
|
|
'foo_key' => array( |
718
|
|
|
'key' => 'foo', |
719
|
|
|
'compare' => 'EXISTS', |
720
|
|
|
), |
721
|
|
|
), |
722
|
|
|
'orderby' => array( |
723
|
|
|
'comment_date' => 'asc', |
724
|
|
|
'foo_key' => 'asc', |
725
|
|
|
), |
726
|
|
|
) ); |
727
|
|
|
|
728
|
|
|
$this->assertEquals( array( $c3, $c1, $c2 ), $found ); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* @ticket 30478 |
733
|
|
|
*/ |
734
|
|
|
public function test_orderby_more_than_one_clause_key() { |
735
|
|
|
$comments = self::factory()->comment->create_many( 3 ); |
736
|
|
|
|
737
|
|
|
add_comment_meta( $comments[0], 'foo', 'jjj' ); |
738
|
|
|
add_comment_meta( $comments[1], 'foo', 'zzz' ); |
739
|
|
|
add_comment_meta( $comments[2], 'foo', 'jjj' ); |
740
|
|
|
add_comment_meta( $comments[0], 'bar', 'aaa' ); |
741
|
|
|
add_comment_meta( $comments[1], 'bar', 'ccc' ); |
742
|
|
|
add_comment_meta( $comments[2], 'bar', 'bbb' ); |
743
|
|
|
|
744
|
|
|
$q = new WP_Comment_Query(); |
745
|
|
|
$found = $q->query( array( |
746
|
|
|
'fields' => 'ids', |
747
|
|
|
'meta_query' => array( |
748
|
|
|
'foo_key' => array( |
749
|
|
|
'key' => 'foo', |
750
|
|
|
'compare' => 'EXISTS', |
751
|
|
|
), |
752
|
|
|
'bar_key' => array( |
753
|
|
|
'key' => 'bar', |
754
|
|
|
'compare' => 'EXISTS', |
755
|
|
|
), |
756
|
|
|
), |
757
|
|
|
'orderby' => array( |
758
|
|
|
'foo_key' => 'asc', |
759
|
|
|
'bar_key' => 'desc', |
760
|
|
|
), |
761
|
|
|
) ); |
762
|
|
|
|
763
|
|
|
$this->assertEquals( array( $comments[2], $comments[0], $comments[1] ), $found ); |
764
|
|
|
} |
765
|
|
|
|
766
|
|
|
/** |
767
|
|
|
* @ticket 32081 |
768
|
|
|
*/ |
769
|
|
|
public function test_meta_query_should_work_with_comment__in() { |
770
|
|
|
$comments = self::factory()->comment->create_many( 3 ); |
771
|
|
|
|
772
|
|
|
add_comment_meta( $comments[0], 'foo', 'jjj' ); |
773
|
|
|
add_comment_meta( $comments[1], 'foo', 'zzz' ); |
774
|
|
|
add_comment_meta( $comments[2], 'foo', 'jjj' ); |
775
|
|
|
|
776
|
|
|
$q = new WP_Comment_Query( array( |
777
|
|
|
'comment__in' => array( $comments[1], $comments[2] ), |
778
|
|
|
'meta_query' => array( |
779
|
|
|
array( |
780
|
|
|
'key' => 'foo', |
781
|
|
|
'value' => 'jjj', |
782
|
|
|
), |
783
|
|
|
), |
784
|
|
|
'fields' => 'ids', |
785
|
|
|
) ); |
786
|
|
|
|
787
|
|
|
$this->assertEquals( array( $comments[2] ), $q->get_comments() ); |
788
|
|
|
} |
789
|
|
|
|
790
|
|
|
/** |
791
|
|
|
* @ticket 32081 |
792
|
|
|
*/ |
793
|
|
|
public function test_meta_query_should_work_with_comment__not_in() { |
794
|
|
|
$comments = self::factory()->comment->create_many( 3 ); |
795
|
|
|
|
796
|
|
|
add_comment_meta( $comments[0], 'foo', 'jjj' ); |
797
|
|
|
add_comment_meta( $comments[1], 'foo', 'zzz' ); |
798
|
|
|
add_comment_meta( $comments[2], 'foo', 'jjj' ); |
799
|
|
|
|
800
|
|
|
$q = new WP_Comment_Query( array( |
801
|
|
|
'comment__not_in' => array( $comments[1], $comments[2] ), |
802
|
|
|
'meta_query' => array( |
803
|
|
|
array( |
804
|
|
|
'key' => 'foo', |
805
|
|
|
'value' => 'jjj', |
806
|
|
|
), |
807
|
|
|
), |
808
|
|
|
'fields' => 'ids', |
809
|
|
|
) ); |
810
|
|
|
|
811
|
|
|
$this->assertEquals( array( $comments[0] ), $q->get_comments() ); |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
/** |
815
|
|
|
* @ticket 27064 |
816
|
|
|
*/ |
817
|
|
|
function test_get_comments_by_user() { |
818
|
|
|
$users = self::factory()->user->create_many( 2 ); |
819
|
|
|
self::factory()->comment->create( array( 'user_id' => $users[0], 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
820
|
|
|
self::factory()->comment->create( array( 'user_id' => $users[0], 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
821
|
|
|
self::factory()->comment->create( array( 'user_id' => $users[1], 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
822
|
|
|
|
823
|
|
|
$comments = get_comments( array( |
824
|
|
|
'user_id' => $users[0], |
825
|
|
|
'orderby' => 'comment_ID', |
826
|
|
|
'order' => 'ASC', |
827
|
|
|
) ); |
828
|
|
|
|
829
|
|
|
$this->assertCount( 2, $comments ); |
830
|
|
|
$this->assertEquals( $users[0], $comments[0]->user_id ); |
831
|
|
|
$this->assertEquals( $users[0], $comments[1]->user_id ); |
832
|
|
|
|
833
|
|
|
$comments = get_comments( array( |
834
|
|
|
'user_id' => $users, |
835
|
|
|
'orderby' => 'comment_ID', |
836
|
|
|
'order' => 'ASC', |
837
|
|
|
) ); |
838
|
|
|
|
839
|
|
|
$this->assertCount( 3, $comments ); |
840
|
|
|
$this->assertEquals( $users[0], $comments[0]->user_id ); |
841
|
|
|
$this->assertEquals( $users[0], $comments[1]->user_id ); |
842
|
|
|
$this->assertEquals( $users[1], $comments[2]->user_id ); |
843
|
|
|
|
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
/** |
847
|
|
|
* @ticket 35377 |
848
|
|
|
*/ |
849
|
|
|
public function test_get_comments_by_author_url() { |
850
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_author' => 'bar', 'comment_author_email' => '[email protected]', 'comment_author_url' => 'http://foo.bar' ) ); |
851
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_author' => 'bar', 'comment_author_email' => '[email protected]', 'comment_author_url' => 'http://foo.bar' ) ); |
852
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_author' => 'bar', 'comment_author_email' => '[email protected]', 'comment_author_url' => 'http://foo.bar/baz' ) ); |
|
|
|
|
853
|
|
|
|
854
|
|
|
$comments = get_comments( array( |
855
|
|
|
'author_url' => 'http://foo.bar', |
856
|
|
|
'fields' => 'ids', |
857
|
|
|
) ); |
858
|
|
|
|
859
|
|
|
$this->assertEqualSets( array( $c1, $c2 ), $comments ); |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
/** |
863
|
|
|
* @ticket 28434 |
864
|
|
|
*/ |
865
|
|
|
function test_fields_ids_query() { |
866
|
|
|
$comment_1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
867
|
|
|
$comment_2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
868
|
|
|
$comment_3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
869
|
|
|
|
870
|
|
|
// Ensure we are dealing with integers, and not objects. |
871
|
|
|
$this->assertInternalType( 'integer', $comment_1 ); |
872
|
|
|
$this->assertInternalType( 'integer', $comment_2 ); |
873
|
|
|
$this->assertInternalType( 'integer', $comment_3 ); |
874
|
|
|
|
875
|
|
|
$comment_ids = get_comments( array( 'fields' => 'ids' ) ); |
876
|
|
|
$this->assertCount( 3, $comment_ids ); |
877
|
|
|
$this->assertEqualSets( array( $comment_1, $comment_2, $comment_3 ), $comment_ids ); |
878
|
|
|
} |
879
|
|
|
|
880
|
|
|
/** |
881
|
|
|
* @ticket 29189 |
882
|
|
|
*/ |
883
|
|
|
function test_fields_comment__in() { |
884
|
|
|
$comment_1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
885
|
|
|
$comment_2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
|
|
|
|
886
|
|
|
$comment_3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
887
|
|
|
|
888
|
|
|
$comment_ids = get_comments( array( |
889
|
|
|
'fields' => 'ids', |
890
|
|
|
'comment__in' => array( $comment_1, $comment_3 ), |
891
|
|
|
) ); |
892
|
|
|
|
893
|
|
|
$this->assertEqualSets( array( $comment_1, $comment_3 ), $comment_ids ); |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
/** |
897
|
|
|
* @ticket 29189 |
898
|
|
|
*/ |
899
|
|
|
function test_fields_comment__not_in() { |
900
|
|
|
$comment_1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
901
|
|
|
$comment_2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
902
|
|
|
$comment_3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
903
|
|
|
|
904
|
|
|
$comment_ids = get_comments( array( |
905
|
|
|
'fields' => 'ids', |
906
|
|
|
'comment__not_in' => array( $comment_2, $comment_3 ), |
907
|
|
|
) ); |
908
|
|
|
|
909
|
|
|
$this->assertEqualSets( array( $comment_1 ), $comment_ids ); |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
/** |
913
|
|
|
* @ticket 29189 |
914
|
|
|
*/ |
915
|
|
|
function test_fields_post__in() { |
916
|
|
|
$p1 = self::factory()->post->create(); |
917
|
|
|
$p2 = self::factory()->post->create(); |
918
|
|
|
$p3 = self::factory()->post->create(); |
919
|
|
|
|
920
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 7, 'comment_approved' => '1' ) ); |
921
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 1, 'comment_approved' => '1' ) ); |
922
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p3, 'user_id' => 1, 'comment_approved' => '1' ) ); |
|
|
|
|
923
|
|
|
|
924
|
|
|
$comment_ids = get_comments( array( |
925
|
|
|
'fields' => 'ids', |
926
|
|
|
'post__in' => array( $p1, $p2 ), |
927
|
|
|
) ); |
928
|
|
|
|
929
|
|
|
$this->assertEqualSets( array( $c1, $c2 ), $comment_ids ); |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
/** |
933
|
|
|
* @ticket 29189 |
934
|
|
|
*/ |
935
|
|
|
function test_fields_post__not_in() { |
936
|
|
|
$p1 = self::factory()->post->create(); |
937
|
|
|
$p2 = self::factory()->post->create(); |
938
|
|
|
$p3 = self::factory()->post->create(); |
939
|
|
|
|
940
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 7, 'comment_approved' => '1' ) ); |
|
|
|
|
941
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 1, 'comment_approved' => '1' ) ); |
|
|
|
|
942
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p3, 'user_id' => 1, 'comment_approved' => '1' ) ); |
943
|
|
|
|
944
|
|
|
$comment_ids = get_comments( array( |
945
|
|
|
'fields' => 'ids', |
946
|
|
|
'post__not_in' => array( $p1, $p2 ), |
947
|
|
|
) ); |
948
|
|
|
|
949
|
|
|
$this->assertEqualSets( array( $c3 ), $comment_ids ); |
950
|
|
|
} |
951
|
|
|
|
952
|
|
|
/** |
953
|
|
|
* @ticket 29885 |
954
|
|
|
*/ |
955
|
|
|
function test_fields_post_author__in() { |
956
|
|
|
$author_id1 = 105; |
957
|
|
|
$author_id2 = 106; |
958
|
|
|
|
959
|
|
|
$p1 = self::factory()->post->create( array( 'post_author' => $author_id1 ) ); |
960
|
|
|
$p2 = self::factory()->post->create( array( 'post_author' => $author_id1 ) ); |
961
|
|
|
$p3 = self::factory()->post->create( array( 'post_author' => $author_id2 ) ); |
962
|
|
|
|
963
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 1, 'comment_approved' => '1' ) ); |
964
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 1, 'comment_approved' => '1' ) ); |
965
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p3, 'user_id' => 1, 'comment_approved' => '1' ) ); |
|
|
|
|
966
|
|
|
|
967
|
|
|
$comment_ids = get_comments( array( |
968
|
|
|
'fields' => 'ids', |
969
|
|
|
'post_author__in' => array( $author_id1 ), |
970
|
|
|
) ); |
971
|
|
|
|
972
|
|
|
$this->assertEqualSets( array( $c1, $c2 ), $comment_ids ); |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
/** |
976
|
|
|
* @ticket 29885 |
977
|
|
|
*/ |
978
|
|
|
function test_fields_post_author__not_in() { |
979
|
|
|
$author_id1 = 111; |
980
|
|
|
$author_id2 = 112; |
981
|
|
|
|
982
|
|
|
$p1 = self::factory()->post->create( array( 'post_author' => $author_id1 ) ); |
983
|
|
|
$p2 = self::factory()->post->create( array( 'post_author' => $author_id1 ) ); |
984
|
|
|
$p3 = self::factory()->post->create( array( 'post_author' => $author_id2 ) ); |
985
|
|
|
|
986
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 1, 'comment_approved' => '1' ) ); |
|
|
|
|
987
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 1, 'comment_approved' => '1' ) ); |
|
|
|
|
988
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p3, 'user_id' => 1, 'comment_approved' => '1' ) ); |
989
|
|
|
|
990
|
|
|
$comment_ids = get_comments( array( |
991
|
|
|
'fields' => 'ids', |
992
|
|
|
'post_author__not_in' => array( $author_id1 ), |
993
|
|
|
) ); |
994
|
|
|
|
995
|
|
|
$this->assertEqualSets( array( $c3 ), $comment_ids ); |
996
|
|
|
} |
997
|
|
|
|
998
|
|
|
/** |
999
|
|
|
* @ticket 29885 |
1000
|
|
|
*/ |
1001
|
|
|
function test_fields_author__in() { |
1002
|
|
|
$p1 = self::factory()->post->create(); |
1003
|
|
|
$p2 = self::factory()->post->create(); |
1004
|
|
|
$p3 = self::factory()->post->create(); |
|
|
|
|
1005
|
|
|
$p4 = self::factory()->post->create(); |
1006
|
|
|
|
1007
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 1, 'comment_approved' => '1' ) ); |
1008
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 2, 'comment_approved' => '1' ) ); |
|
|
|
|
1009
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 3, 'comment_approved' => '1' ) ); |
1010
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => $p4, 'user_id' => 4, 'comment_approved' => '1' ) ); |
|
|
|
|
1011
|
|
|
|
1012
|
|
|
$comment_ids = get_comments( array( |
1013
|
|
|
'fields' => 'ids', |
1014
|
|
|
'author__in' => array( 1, 3 ), |
1015
|
|
|
) ); |
1016
|
|
|
|
1017
|
|
|
$this->assertEqualSets( array( $c1, $c3 ), $comment_ids ); |
1018
|
|
|
} |
1019
|
|
|
|
1020
|
|
|
/** |
1021
|
|
|
* @ticket 29885 |
1022
|
|
|
*/ |
1023
|
|
|
function test_fields_author__not_in() { |
1024
|
|
|
$p1 = self::factory()->post->create(); |
1025
|
|
|
$p2 = self::factory()->post->create(); |
1026
|
|
|
$p3 = self::factory()->post->create(); |
|
|
|
|
1027
|
|
|
$p4 = self::factory()->post->create(); |
1028
|
|
|
|
1029
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 1, 'comment_approved' => '1' ) ); |
|
|
|
|
1030
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p1, 'user_id' => 2, 'comment_approved' => '1' ) ); |
|
|
|
|
1031
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p2, 'user_id' => 3, 'comment_approved' => '1' ) ); |
1032
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => $p4, 'user_id' => 4, 'comment_approved' => '1' ) ); |
1033
|
|
|
|
1034
|
|
|
$comment_ids = get_comments( array( |
1035
|
|
|
'fields' => 'ids', |
1036
|
|
|
'author__not_in' => array( 1, 2 ), |
1037
|
|
|
) ); |
1038
|
|
|
|
1039
|
|
|
$this->assertEqualSets( array( $c3, $c4 ), $comment_ids ); |
1040
|
|
|
} |
1041
|
|
|
|
1042
|
|
|
/** |
1043
|
|
|
* @ticket 19623 |
1044
|
|
|
*/ |
1045
|
|
|
public function test_get_comments_with_status_all() { |
1046
|
|
|
$comment_1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
1047
|
|
|
$comment_2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
1048
|
|
|
$comment_3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '0' ) ); |
1049
|
|
|
$comments_approved_1 = get_comments( array( 'status' => 'all' ) ); |
|
|
|
|
1050
|
|
|
|
1051
|
|
|
$comment_ids = get_comments( array( 'fields' => 'ids' ) ); |
1052
|
|
|
$this->assertEqualSets( array( $comment_1, $comment_2, $comment_3 ), $comment_ids ); |
1053
|
|
|
} |
1054
|
|
|
|
1055
|
|
|
/** |
1056
|
|
|
* @ticket 19623 |
1057
|
|
|
*/ |
1058
|
|
|
public function test_get_comments_with_include_unapproved_user_id() { |
1059
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
1060
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
1061
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '0' ) ); |
1062
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 6, 'comment_approved' => '0' ) ); |
|
|
|
|
1063
|
|
|
|
1064
|
|
|
$found = get_comments( array( |
1065
|
|
|
'fields' => 'ids', |
1066
|
|
|
'include_unapproved' => 1, |
1067
|
|
|
'status' => 'approve', |
1068
|
|
|
) ); |
1069
|
|
|
|
1070
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3 ), $found ); |
1071
|
|
|
} |
1072
|
|
|
|
1073
|
|
|
/** |
1074
|
|
|
* @ticket 19623 |
1075
|
|
|
*/ |
1076
|
|
|
public function test_get_comments_with_include_unapproved_user_id_array() { |
1077
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
1078
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
1079
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '0' ) ); |
1080
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 6, 'comment_approved' => '0' ) ); |
|
|
|
|
1081
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 8, 'comment_approved' => '0' ) ); |
1082
|
|
|
|
1083
|
|
|
$found = get_comments( array( |
1084
|
|
|
'fields' => 'ids', |
1085
|
|
|
'include_unapproved' => array( 1, 8 ), |
1086
|
|
|
'status' => 'approve', |
1087
|
|
|
) ); |
1088
|
|
|
|
1089
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found ); |
1090
|
|
|
} |
1091
|
|
|
|
1092
|
|
|
/** |
1093
|
|
|
* @ticket 19623 |
1094
|
|
|
*/ |
1095
|
|
|
public function test_get_comments_with_include_unapproved_user_id_comma_separated() { |
1096
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
1097
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '1' ) ); |
1098
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 1, 'comment_approved' => '0' ) ); |
1099
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 6, 'comment_approved' => '0' ) ); |
|
|
|
|
1100
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 8, 'comment_approved' => '0' ) ); |
1101
|
|
|
|
1102
|
|
|
$found = get_comments( array( |
1103
|
|
|
'fields' => 'ids', |
1104
|
|
|
'include_unapproved' => '1,8', |
1105
|
|
|
'status' => 'approve', |
1106
|
|
|
) ); |
1107
|
|
|
|
1108
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found ); |
1109
|
|
|
} |
1110
|
|
|
|
1111
|
|
|
/** |
1112
|
|
|
* @ticket 19623 |
1113
|
|
|
*/ |
1114
|
|
|
public function test_get_comments_with_include_unapproved_author_email() { |
1115
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
1116
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 0, 'comment_approved' => '1', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
1117
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 0, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
1118
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 0, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
|
|
|
|
1119
|
|
|
|
1120
|
|
|
$found = get_comments( array( |
1121
|
|
|
'fields' => 'ids', |
1122
|
|
|
'include_unapproved' => '[email protected]', |
1123
|
|
|
'status' => 'approve', |
1124
|
|
|
) ); |
1125
|
|
|
|
1126
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3 ), $found ); |
1127
|
|
|
} |
1128
|
|
|
|
1129
|
|
|
/** |
1130
|
|
|
* @ticket 19623 |
1131
|
|
|
*/ |
1132
|
|
|
public function test_get_comments_with_include_unapproved_mixed_array() { |
1133
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
1134
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 0, 'comment_approved' => '1', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
1135
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 0, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
1136
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 0, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
|
|
|
|
1137
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
1138
|
|
|
|
1139
|
|
|
$found = get_comments( array( |
1140
|
|
|
'fields' => 'ids', |
1141
|
|
|
'include_unapproved' => array( '[email protected]', 4 ), |
1142
|
|
|
'status' => 'approve', |
1143
|
|
|
) ); |
1144
|
|
|
|
1145
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found ); |
1146
|
|
|
} |
1147
|
|
|
|
1148
|
|
|
/** |
1149
|
|
|
* @ticket 19623 |
1150
|
|
|
*/ |
1151
|
|
|
public function test_get_comments_with_include_unapproved_mixed_comma_separated() { |
1152
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7, 'comment_approved' => '1' ) ); |
1153
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 0, 'comment_approved' => '1', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
1154
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 0, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
1155
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 0, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
|
|
|
|
1156
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
1157
|
|
|
|
1158
|
|
|
$found = get_comments( array( |
1159
|
|
|
'fields' => 'ids', |
1160
|
|
|
'include_unapproved' => '[email protected], 4', |
1161
|
|
|
'status' => 'approve', |
1162
|
|
|
) ); |
1163
|
|
|
|
1164
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3, $c5 ), $found ); |
1165
|
|
|
} |
1166
|
|
|
|
1167
|
|
|
public function test_search() { |
1168
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'foo', 'comment_author_email' => '[email protected]' ) ); |
1169
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'bar', 'comment_author_email' => '[email protected]' ) ); |
1170
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'bar', 'comment_author_email' => '[email protected]', 'comment_author_url' => 'http://foo.bar' ) ); |
1171
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'bar', 'comment_author_email' => '[email protected]', 'comment_author_url' => 'http://example.com', 'comment_author_IP' => 'foo.bar' ) ); |
1172
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'bar', 'comment_author_email' => '[email protected]', 'comment_author_url' => 'http://example.com', 'comment_content' => 'Nice foo comment' ) ); |
1173
|
|
|
$c6 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 4, 'comment_approved' => '0', 'comment_author' => 'bar', 'comment_author_email' => '[email protected]', 'comment_author_url' => 'http://example.com' ) ); |
|
|
|
|
1174
|
|
|
|
1175
|
|
|
$q = new WP_Comment_Query(); |
1176
|
|
|
$found = $q->query( array( |
1177
|
|
|
'search' => 'foo', |
1178
|
|
|
'fields' => 'ids', |
1179
|
|
|
) ); |
1180
|
|
|
|
1181
|
|
|
$this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found ); |
1182
|
|
|
} |
1183
|
|
|
|
1184
|
|
|
/** |
1185
|
|
|
* @ticket 35513 |
1186
|
|
|
*/ |
1187
|
|
|
public function test_search_false_should_be_ignored() { |
1188
|
|
|
$q = new WP_Comment_Query(); |
1189
|
|
|
$q->query( array( |
1190
|
|
|
'search' => false, |
1191
|
|
|
) ); |
1192
|
|
|
$this->assertNotContains( "comment_author LIKE", $q->request ); |
1193
|
|
|
} |
1194
|
|
|
|
1195
|
|
|
/** |
1196
|
|
|
* @ticket 35513 |
1197
|
|
|
*/ |
1198
|
|
|
public function test_search_null_should_be_ignored() { |
1199
|
|
|
$q = new WP_Comment_Query(); |
1200
|
|
|
$q->query( array( |
1201
|
|
|
'search' => null, |
1202
|
|
|
) ); |
1203
|
|
|
$this->assertNotContains( "comment_author LIKE", $q->request ); |
1204
|
|
|
} |
1205
|
|
|
|
1206
|
|
|
/** |
1207
|
|
|
* @ticket 35513 |
1208
|
|
|
*/ |
1209
|
|
|
public function test_search_empty_string_should_be_ignored() { |
1210
|
|
|
$q = new WP_Comment_Query(); |
1211
|
|
|
$q->query( array( |
1212
|
|
|
'search' => false, |
1213
|
|
|
) ); |
1214
|
|
|
$this->assertNotContains( "comment_author LIKE", $q->request ); |
1215
|
|
|
} |
1216
|
|
|
|
1217
|
|
|
/** |
1218
|
|
|
* @ticket 35513 |
1219
|
|
|
*/ |
1220
|
|
|
public function test_search_int_0_should_not_be_ignored() { |
1221
|
|
|
$q = new WP_Comment_Query(); |
1222
|
|
|
$q->query( array( |
1223
|
|
|
'search' => 0, |
1224
|
|
|
) ); |
1225
|
|
|
$this->assertContains( "comment_author LIKE '%0%'", $q->request ); |
1226
|
|
|
} |
1227
|
|
|
|
1228
|
|
|
/** |
1229
|
|
|
* @ticket 35513 |
1230
|
|
|
*/ |
1231
|
|
|
public function test_search_string_0_should_not_be_ignored() { |
1232
|
|
|
$q = new WP_Comment_Query(); |
1233
|
|
|
$q->query( array( |
1234
|
|
|
'search' => '0', |
1235
|
|
|
) ); |
1236
|
|
|
$this->assertContains( "comment_author LIKE '%0%'", $q->request ); |
1237
|
|
|
} |
1238
|
|
|
|
1239
|
|
|
public function test_orderby_default() { |
1240
|
|
|
global $wpdb; |
1241
|
|
|
|
1242
|
|
|
$q = new WP_Comment_Query(); |
1243
|
|
|
$q->query( array() ); |
1244
|
|
|
|
1245
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request ); |
1246
|
|
|
} |
1247
|
|
|
|
1248
|
|
|
public function test_orderby_single() { |
1249
|
|
|
global $wpdb; |
1250
|
|
|
|
1251
|
|
|
$q = new WP_Comment_Query(); |
1252
|
|
|
$q->query( array( |
1253
|
|
|
'orderby' => 'comment_agent', |
1254
|
|
|
) ); |
1255
|
|
|
|
1256
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent", $q->request ); |
1257
|
|
|
} |
1258
|
|
|
|
1259
|
|
|
public function test_orderby_single_invalid() { |
1260
|
|
|
global $wpdb; |
1261
|
|
|
|
1262
|
|
|
$q = new WP_Comment_Query(); |
1263
|
|
|
$q->query( array( |
1264
|
|
|
'orderby' => 'foo', |
1265
|
|
|
) ); |
1266
|
|
|
|
1267
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request ); |
1268
|
|
|
} |
1269
|
|
|
|
1270
|
|
|
public function test_orderby_space_separated() { |
1271
|
|
|
global $wpdb; |
1272
|
|
|
|
1273
|
|
|
$q = new WP_Comment_Query(); |
1274
|
|
|
$q->query( array( |
1275
|
|
|
'orderby' => 'comment_agent comment_approved', |
1276
|
|
|
) ); |
1277
|
|
|
|
1278
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request ); |
1279
|
|
|
} |
1280
|
|
|
|
1281
|
|
|
public function test_orderby_comma_separated() { |
1282
|
|
|
global $wpdb; |
1283
|
|
|
|
1284
|
|
|
$q = new WP_Comment_Query(); |
1285
|
|
|
$q->query( array( |
1286
|
|
|
'orderby' => 'comment_agent, comment_approved', |
1287
|
|
|
) ); |
1288
|
|
|
|
1289
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request ); |
1290
|
|
|
} |
1291
|
|
|
|
1292
|
|
|
public function test_orderby_flat_array() { |
1293
|
|
|
global $wpdb; |
1294
|
|
|
|
1295
|
|
|
$q = new WP_Comment_Query(); |
1296
|
|
|
$q->query( array( |
1297
|
|
|
'orderby' => array( 'comment_agent', 'comment_approved' ), |
1298
|
|
|
) ); |
1299
|
|
|
|
1300
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request ); |
1301
|
|
|
} |
1302
|
|
|
|
1303
|
|
|
public function test_orderby_array_contains_invalid_item() { |
1304
|
|
|
global $wpdb; |
1305
|
|
|
|
1306
|
|
|
$q = new WP_Comment_Query(); |
1307
|
|
|
$q->query( array( |
1308
|
|
|
'orderby' => array( 'comment_agent', 'foo', 'comment_approved' ), |
1309
|
|
|
) ); |
1310
|
|
|
|
1311
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request ); |
1312
|
|
|
} |
1313
|
|
|
|
1314
|
|
|
public function test_orderby_array_contains_all_invalid_items() { |
1315
|
|
|
global $wpdb; |
1316
|
|
|
|
1317
|
|
|
$q = new WP_Comment_Query(); |
1318
|
|
|
$q->query( array( |
1319
|
|
|
'orderby' => array( 'foo', 'bar', 'baz' ), |
1320
|
|
|
) ); |
1321
|
|
|
|
1322
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request ); |
1323
|
|
|
} |
1324
|
|
|
|
1325
|
|
|
/** |
1326
|
|
|
* @ticket 29902 |
1327
|
|
|
*/ |
1328
|
|
|
public function test_orderby_none() { |
1329
|
|
|
$q = new WP_Comment_Query(); |
1330
|
|
|
$q->query( array( |
1331
|
|
|
'orderby' => 'none', |
1332
|
|
|
) ); |
1333
|
|
|
|
1334
|
|
|
$this->assertNotContains( 'ORDER BY', $q->request ); |
1335
|
|
|
} |
1336
|
|
|
|
1337
|
|
|
/** |
1338
|
|
|
* @ticket 29902 |
1339
|
|
|
*/ |
1340
|
|
|
public function test_orderby_empty_array() { |
1341
|
|
|
$q = new WP_Comment_Query(); |
1342
|
|
|
$q->query( array( |
1343
|
|
|
'orderby' => array(), |
1344
|
|
|
) ); |
1345
|
|
|
|
1346
|
|
|
$this->assertNotContains( 'ORDER BY', $q->request ); |
1347
|
|
|
} |
1348
|
|
|
|
1349
|
|
|
/** |
1350
|
|
|
* @ticket 29902 |
1351
|
|
|
*/ |
1352
|
|
|
public function test_orderby_false() { |
1353
|
|
|
$q = new WP_Comment_Query(); |
1354
|
|
|
$q->query( array( |
1355
|
|
|
'orderby' => false, |
1356
|
|
|
) ); |
1357
|
|
|
|
1358
|
|
|
$this->assertNotContains( 'ORDER BY', $q->request ); |
1359
|
|
|
} |
1360
|
|
|
|
1361
|
|
|
/** |
1362
|
|
|
* @ticket 30478 |
1363
|
|
|
*/ |
1364
|
|
|
public function test_orderby_array() { |
1365
|
|
|
global $wpdb; |
1366
|
|
|
|
1367
|
|
|
$q = new WP_Comment_Query(); |
1368
|
|
|
$found = $q->query( array( |
|
|
|
|
1369
|
|
|
'fields' => 'ids', |
1370
|
|
|
'orderby' => array( |
1371
|
|
|
'comment_agent' => 'DESC', |
1372
|
|
|
'comment_date_gmt' => 'ASC', |
1373
|
|
|
'comment_ID' => 'DESC', |
1374
|
|
|
), |
1375
|
|
|
) ); |
1376
|
|
|
|
1377
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID DESC", $q->request ); |
1378
|
|
|
} |
1379
|
|
|
|
1380
|
|
|
/** |
1381
|
|
|
* @ticket 30478 |
1382
|
|
|
*/ |
1383
|
|
|
public function test_orderby_array_should_discard_invalid_columns() { |
1384
|
|
|
global $wpdb; |
1385
|
|
|
|
1386
|
|
|
$q = new WP_Comment_Query(); |
1387
|
|
|
$found = $q->query( array( |
|
|
|
|
1388
|
|
|
'fields' => 'ids', |
1389
|
|
|
'orderby' => array( |
1390
|
|
|
'comment_agent' => 'DESC', |
1391
|
|
|
'foo' => 'ASC', |
1392
|
|
|
'comment_ID' => 'DESC', |
1393
|
|
|
), |
1394
|
|
|
) ); |
1395
|
|
|
|
1396
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_ID DESC", $q->request ); |
1397
|
|
|
} |
1398
|
|
|
|
1399
|
|
|
/** |
1400
|
|
|
* @ticket 30478 |
1401
|
|
|
*/ |
1402
|
|
|
public function test_orderby_array_should_convert_invalid_order_to_DESC() { |
1403
|
|
|
global $wpdb; |
1404
|
|
|
|
1405
|
|
|
$q = new WP_Comment_Query(); |
1406
|
|
|
$found = $q->query( array( |
|
|
|
|
1407
|
|
|
'fields' => 'ids', |
1408
|
|
|
'orderby' => array( |
1409
|
|
|
'comment_agent' => 'DESC', |
1410
|
|
|
'comment_date_gmt' => 'foo', |
1411
|
|
|
'comment_ID' => 'DESC', |
1412
|
|
|
), |
1413
|
|
|
) ); |
1414
|
|
|
|
1415
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt DESC, $wpdb->comments.comment_ID DESC", $q->request ); |
1416
|
|
|
} |
1417
|
|
|
|
1418
|
|
|
/** |
1419
|
|
|
* @ticket 30478 |
1420
|
|
|
*/ |
1421
|
|
|
public function test_orderby_array_should_sort_by_comment_ID_as_fallback_and_should_inherit_order_from_comment_date_gmt() { |
1422
|
|
|
global $wpdb; |
1423
|
|
|
|
1424
|
|
|
$q = new WP_Comment_Query(); |
1425
|
|
|
$found = $q->query( array( |
|
|
|
|
1426
|
|
|
'fields' => 'ids', |
1427
|
|
|
'orderby' => array( |
1428
|
|
|
'comment_agent' => 'DESC', |
1429
|
|
|
'comment_date_gmt' => 'ASC', |
1430
|
|
|
), |
1431
|
|
|
) ); |
1432
|
|
|
|
1433
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID ASC", $q->request ); |
1434
|
|
|
} |
1435
|
|
|
|
1436
|
|
|
/** |
1437
|
|
|
* @ticket 30478 |
1438
|
|
|
*/ |
1439
|
|
|
public function test_orderby_array_should_sort_by_comment_ID_as_fallback_and_should_inherit_order_from_comment_date() { |
1440
|
|
|
global $wpdb; |
1441
|
|
|
|
1442
|
|
|
$q = new WP_Comment_Query(); |
1443
|
|
|
$found = $q->query( array( |
|
|
|
|
1444
|
|
|
'fields' => 'ids', |
1445
|
|
|
'orderby' => array( |
1446
|
|
|
'comment_agent' => 'DESC', |
1447
|
|
|
'comment_date' => 'ASC', |
1448
|
|
|
), |
1449
|
|
|
) ); |
1450
|
|
|
|
1451
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date ASC, $wpdb->comments.comment_ID ASC", $q->request ); |
1452
|
|
|
} |
1453
|
|
|
|
1454
|
|
|
/** |
1455
|
|
|
* @ticket 30478 |
1456
|
|
|
*/ |
1457
|
|
|
public function test_orderby_array_should_sort_by_comment_ID_DESC_as_fallback_when_not_sorted_by_date() { |
1458
|
|
|
global $wpdb; |
1459
|
|
|
|
1460
|
|
|
$q = new WP_Comment_Query(); |
1461
|
|
|
$found = $q->query( array( |
|
|
|
|
1462
|
|
|
'fields' => 'ids', |
1463
|
|
|
'orderby' => array( |
1464
|
|
|
'comment_agent' => 'ASC', |
1465
|
|
|
), |
1466
|
|
|
) ); |
1467
|
|
|
|
1468
|
|
|
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent ASC, $wpdb->comments.comment_ID DESC", $q->request ); |
1469
|
|
|
} |
1470
|
|
|
|
1471
|
|
|
/** |
1472
|
|
|
* @ticket 30478 |
1473
|
|
|
*/ |
1474
|
|
|
public function test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_ASC() { |
1475
|
|
|
$now = current_time( 'mysql', 1 ); |
1476
|
|
|
$comments = self::factory()->comment->create_many( 5, array( |
1477
|
|
|
'comment_post_ID' => self::$post_id, |
1478
|
|
|
'comment_date_gmt' => $now, |
1479
|
|
|
) ); |
1480
|
|
|
|
1481
|
|
|
$q = new WP_Comment_Query(); |
1482
|
|
|
$found = $q->query( array( |
1483
|
|
|
'orderby' => 'comment_date_gmt', |
1484
|
|
|
'order' => 'ASC', |
1485
|
|
|
) ); |
1486
|
|
|
|
1487
|
|
|
// $comments is ASC by default. |
1488
|
|
|
$this->assertEquals( $comments, wp_list_pluck( $found, 'comment_ID' ) ); |
1489
|
|
|
} |
1490
|
|
|
|
1491
|
|
|
/** |
1492
|
|
|
* @ticket 30478 |
1493
|
|
|
*/ |
1494
|
|
|
public function test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_DESC() { |
1495
|
|
|
$now = current_time( 'mysql', 1 ); |
1496
|
|
|
$comments = self::factory()->comment->create_many( 5, array( |
1497
|
|
|
'comment_post_ID' => self::$post_id, |
1498
|
|
|
'comment_date_gmt' => $now, |
1499
|
|
|
) ); |
1500
|
|
|
|
1501
|
|
|
$q = new WP_Comment_Query(); |
1502
|
|
|
$found = $q->query( array( |
1503
|
|
|
'orderby' => 'comment_date_gmt', |
1504
|
|
|
'order' => 'DESC', |
1505
|
|
|
) ); |
1506
|
|
|
|
1507
|
|
|
// $comments is ASC by default. |
1508
|
|
|
rsort( $comments ); |
1509
|
|
|
|
1510
|
|
|
$this->assertEquals( $comments, wp_list_pluck( $found, 'comment_ID' ) ); |
1511
|
|
|
} |
1512
|
|
|
|
1513
|
|
|
public function test_meta_vars_should_be_converted_to_meta_query() { |
1514
|
|
|
$q = new WP_Comment_Query(); |
1515
|
|
|
$q->query( array( |
1516
|
|
|
'meta_key' => 'foo', |
1517
|
|
|
'meta_value' => '5', |
1518
|
|
|
'meta_compare' => '>', |
1519
|
|
|
'meta_type' => 'SIGNED', |
1520
|
|
|
) ); |
1521
|
|
|
|
1522
|
|
|
$this->assertSame( 'foo', $q->meta_query->queries[0]['key'] ); |
1523
|
|
|
$this->assertSame( '5', $q->meta_query->queries[0]['value'] ); |
1524
|
|
|
$this->assertSame( '>', $q->meta_query->queries[0]['compare'] ); |
1525
|
|
|
$this->assertSame( 'SIGNED', $q->meta_query->queries[0]['type'] ); |
1526
|
|
|
} |
1527
|
|
|
|
1528
|
|
|
public function test_count() { |
1529
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7 ) ); |
|
|
|
|
1530
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7 ) ); |
|
|
|
|
1531
|
|
|
|
1532
|
|
|
$q = new WP_Comment_Query(); |
1533
|
|
|
$found = $q->query( array( |
1534
|
|
|
'count' => true, |
1535
|
|
|
) ); |
1536
|
|
|
|
1537
|
|
|
$this->assertEquals( 2, $found ); |
1538
|
|
|
} |
1539
|
|
|
|
1540
|
|
|
/** |
1541
|
|
|
* @ticket 23369 |
1542
|
|
|
*/ |
1543
|
|
|
public function test_count_with_meta_query() { |
1544
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7 ) ); |
1545
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7 ) ); |
|
|
|
|
1546
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'user_id' => 7 ) ); |
1547
|
|
|
add_comment_meta( $c1, 'foo', 'bar' ); |
1548
|
|
|
add_comment_meta( $c3, 'foo', 'bar' ); |
1549
|
|
|
|
1550
|
|
|
$q = new WP_Comment_Query(); |
1551
|
|
|
$found = $q->query( array( |
1552
|
|
|
'count' => true, |
1553
|
|
|
'meta_query' => array( |
1554
|
|
|
array( |
1555
|
|
|
'key' => 'foo', |
1556
|
|
|
'value' => 'bar', |
1557
|
|
|
), |
1558
|
|
|
), |
1559
|
|
|
) ); |
1560
|
|
|
|
1561
|
|
|
$this->assertEquals( 2, $found ); |
1562
|
|
|
} |
1563
|
|
|
|
1564
|
|
|
public function test_post_type_single_value() { |
1565
|
|
|
register_post_type( 'post-type-1' ); |
1566
|
|
|
register_post_type( 'post-type-2' ); |
1567
|
|
|
|
1568
|
|
|
$p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) ); |
1569
|
|
|
$p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) ); |
1570
|
|
|
|
1571
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
|
|
|
|
1572
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1573
|
|
|
|
1574
|
|
|
$q = new WP_Comment_Query(); |
1575
|
|
|
$found = $q->query( array( |
1576
|
|
|
'fields' => 'ids', |
1577
|
|
|
'post_type' => 'post-type-2', |
1578
|
|
|
) ); |
1579
|
|
|
|
1580
|
|
|
$this->assertEqualSets( $c2, $found ); |
1581
|
|
|
|
1582
|
|
|
_unregister_post_type( 'post-type-1' ); |
1583
|
|
|
_unregister_post_type( 'post-type-2' ); |
1584
|
|
|
} |
1585
|
|
|
|
1586
|
|
|
/** |
1587
|
|
|
* @ticket 20006 |
1588
|
|
|
*/ |
1589
|
|
|
public function test_post_type_singleton_array() { |
1590
|
|
|
register_post_type( 'post-type-1' ); |
1591
|
|
|
register_post_type( 'post-type-2' ); |
1592
|
|
|
|
1593
|
|
|
$p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) ); |
1594
|
|
|
$p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) ); |
1595
|
|
|
|
1596
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
|
|
|
|
1597
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1598
|
|
|
|
1599
|
|
|
$q = new WP_Comment_Query(); |
1600
|
|
|
$found = $q->query( array( |
1601
|
|
|
'fields' => 'ids', |
1602
|
|
|
'post_type' => array( 'post-type-2' ), |
1603
|
|
|
) ); |
1604
|
|
|
|
1605
|
|
|
$this->assertEqualSets( $c2, $found ); |
1606
|
|
|
|
1607
|
|
|
_unregister_post_type( 'post-type-1' ); |
1608
|
|
|
_unregister_post_type( 'post-type-2' ); |
1609
|
|
|
} |
1610
|
|
|
|
1611
|
|
|
/** |
1612
|
|
|
* @ticket 20006 |
1613
|
|
|
*/ |
1614
|
|
|
public function test_post_type_array() { |
1615
|
|
|
register_post_type( 'post-type-1' ); |
1616
|
|
|
register_post_type( 'post-type-2' ); |
1617
|
|
|
register_post_type( 'post-type-3' ); |
1618
|
|
|
|
1619
|
|
|
$p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) ); |
1620
|
|
|
$p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) ); |
1621
|
|
|
$p3 = self::factory()->post->create( array( 'post_type' => 'post-type-3' ) ); |
1622
|
|
|
|
1623
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
1624
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
|
|
|
|
1625
|
|
|
$c3 = self::factory()->comment->create_post_comments( $p3, 1 ); |
1626
|
|
|
|
1627
|
|
|
$q = new WP_Comment_Query(); |
1628
|
|
|
$found = $q->query( array( |
1629
|
|
|
'fields' => 'ids', |
1630
|
|
|
'post_type' => array( 'post-type-1', 'post-type-3' ), |
1631
|
|
|
) ); |
1632
|
|
|
|
1633
|
|
|
$this->assertEqualSets( array_merge( $c1, $c3 ), $found ); |
1634
|
|
|
} |
1635
|
|
|
|
1636
|
|
|
public function test_post_name_single_value() { |
1637
|
|
|
$p1 = self::factory()->post->create( array( 'post_name' => 'foo' ) ); |
1638
|
|
|
$p2 = self::factory()->post->create( array( 'post_name' => 'bar' ) ); |
1639
|
|
|
|
1640
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
|
|
|
|
1641
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1642
|
|
|
|
1643
|
|
|
$q = new WP_Comment_Query(); |
1644
|
|
|
$found = $q->query( array( |
1645
|
|
|
'fields' => 'ids', |
1646
|
|
|
'post_name' => 'bar', |
1647
|
|
|
) ); |
1648
|
|
|
|
1649
|
|
|
$this->assertEqualSets( $c2, $found ); |
1650
|
|
|
} |
1651
|
|
|
|
1652
|
|
|
/** |
1653
|
|
|
* @ticket 20006 |
1654
|
|
|
*/ |
1655
|
|
|
public function test_post_name_singleton_array() { |
1656
|
|
|
$p1 = self::factory()->post->create( array( 'post_name' => 'foo' ) ); |
1657
|
|
|
$p2 = self::factory()->post->create( array( 'post_name' => 'bar' ) ); |
1658
|
|
|
|
1659
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
|
|
|
|
1660
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1661
|
|
|
|
1662
|
|
|
$q = new WP_Comment_Query(); |
1663
|
|
|
$found = $q->query( array( |
1664
|
|
|
'fields' => 'ids', |
1665
|
|
|
'post_name' => array( 'bar' ), |
1666
|
|
|
) ); |
1667
|
|
|
|
1668
|
|
|
$this->assertEqualSets( $c2, $found ); |
1669
|
|
|
} |
1670
|
|
|
|
1671
|
|
|
/** |
1672
|
|
|
* @ticket 20006 |
1673
|
|
|
*/ |
1674
|
|
|
public function test_post_name_array() { |
1675
|
|
|
$p1 = self::factory()->post->create( array( 'post_name' => 'foo' ) ); |
1676
|
|
|
$p2 = self::factory()->post->create( array( 'post_name' => 'bar' ) ); |
1677
|
|
|
$p3 = self::factory()->post->create( array( 'post_name' => 'baz' ) ); |
1678
|
|
|
|
1679
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
1680
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
|
|
|
|
1681
|
|
|
$c3 = self::factory()->comment->create_post_comments( $p3, 1 ); |
1682
|
|
|
|
1683
|
|
|
$q = new WP_Comment_Query(); |
1684
|
|
|
$found = $q->query( array( |
1685
|
|
|
'fields' => 'ids', |
1686
|
|
|
'post_name' => array( 'foo', 'baz' ), |
1687
|
|
|
) ); |
1688
|
|
|
|
1689
|
|
|
$this->assertEqualSets( array_merge( $c1, $c3 ), $found ); |
1690
|
|
|
} |
1691
|
|
|
|
1692
|
|
|
public function test_post_status_single_value() { |
1693
|
|
|
$p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); |
1694
|
|
|
$p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) ); |
1695
|
|
|
|
1696
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
|
|
|
|
1697
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1698
|
|
|
|
1699
|
|
|
$q = new WP_Comment_Query(); |
1700
|
|
|
$found = $q->query( array( |
1701
|
|
|
'fields' => 'ids', |
1702
|
|
|
'post_status' => 'draft', |
1703
|
|
|
) ); |
1704
|
|
|
|
1705
|
|
|
$this->assertEqualSets( $c2, $found ); |
1706
|
|
|
} |
1707
|
|
|
|
1708
|
|
|
/** |
1709
|
|
|
* @ticket 20006 |
1710
|
|
|
*/ |
1711
|
|
|
public function test_post_status_singleton_array() { |
1712
|
|
|
$p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); |
1713
|
|
|
$p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) ); |
1714
|
|
|
|
1715
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
|
|
|
|
1716
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1717
|
|
|
|
1718
|
|
|
$q = new WP_Comment_Query(); |
1719
|
|
|
$found = $q->query( array( |
1720
|
|
|
'fields' => 'ids', |
1721
|
|
|
'post_status' => array( 'draft' ), |
1722
|
|
|
) ); |
1723
|
|
|
|
1724
|
|
|
$this->assertEqualSets( $c2, $found ); |
1725
|
|
|
} |
1726
|
|
|
|
1727
|
|
|
/** |
1728
|
|
|
* @ticket 20006 |
1729
|
|
|
*/ |
1730
|
|
|
public function test_post_status_array() { |
1731
|
|
|
$p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); |
1732
|
|
|
$p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) ); |
1733
|
|
|
$p3 = self::factory()->post->create( array( 'post_status' => 'future' ) ); |
1734
|
|
|
|
1735
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
1736
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
|
|
|
|
1737
|
|
|
$c3 = self::factory()->comment->create_post_comments( $p3, 1 ); |
1738
|
|
|
|
1739
|
|
|
$q = new WP_Comment_Query(); |
1740
|
|
|
$found = $q->query( array( |
1741
|
|
|
'fields' => 'ids', |
1742
|
|
|
'post_status' => array( 'publish', 'future' ), |
1743
|
|
|
) ); |
1744
|
|
|
|
1745
|
|
|
$this->assertEqualSets( array_merge( $c1, $c3 ), $found ); |
1746
|
|
|
} |
1747
|
|
|
|
1748
|
|
|
/** |
1749
|
|
|
* @ticket 35512 |
1750
|
|
|
*/ |
1751
|
|
|
public function test_post_type_any_should_override_other_post_types() { |
1752
|
|
|
register_post_type( 'post-type-1', array( 'exclude_from_search' => false ) ); |
1753
|
|
|
register_post_type( 'post-type-2', array( 'exclude_from_search' => false ) ); |
1754
|
|
|
|
1755
|
|
|
$p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) ); |
1756
|
|
|
$p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) ); |
1757
|
|
|
|
1758
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
1759
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1760
|
|
|
|
1761
|
|
|
$q = new WP_Comment_Query(); |
1762
|
|
|
$found = $q->query( array( |
1763
|
|
|
'fields' => 'ids', |
1764
|
|
|
'post_type' => array( 'any', 'post-type-1' ), |
1765
|
|
|
) ); |
1766
|
|
|
$this->assertEqualSets( array_merge( $c1, $c2 ), $found ); |
1767
|
|
|
} |
1768
|
|
|
|
1769
|
|
|
/** |
1770
|
|
|
* @ticket 35512 |
1771
|
|
|
*/ |
1772
|
|
|
public function test_post_type_any_as_part_of_an_array_of_post_types() { |
1773
|
|
|
register_post_type( 'post-type-1', array( 'exclude_from_search' => false ) ); |
1774
|
|
|
register_post_type( 'post-type-2', array( 'exclude_from_search' => false ) ); |
1775
|
|
|
|
1776
|
|
|
$p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) ); |
1777
|
|
|
$p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) ); |
1778
|
|
|
|
1779
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
1780
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1781
|
|
|
|
1782
|
|
|
$q = new WP_Comment_Query(); |
1783
|
|
|
$found = $q->query( array( |
1784
|
|
|
'fields' => 'ids', |
1785
|
|
|
'post_type' => array( 'any' ), |
1786
|
|
|
) ); |
1787
|
|
|
$this->assertEqualSets( array_merge( $c1, $c2 ), $found ); |
1788
|
|
|
} |
1789
|
|
|
|
1790
|
|
|
/** |
1791
|
|
|
* @ticket 35512 |
1792
|
|
|
*/ |
1793
|
|
|
public function test_post_status_any_should_override_other_post_statuses() { |
1794
|
|
|
$p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); |
1795
|
|
|
$p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) ); |
1796
|
|
|
|
1797
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
1798
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1799
|
|
|
|
1800
|
|
|
$q = new WP_Comment_Query(); |
1801
|
|
|
$found = $q->query( array( |
1802
|
|
|
'fields' => 'ids', |
1803
|
|
|
'post_status' => array( 'any', 'draft' ), |
1804
|
|
|
) ); |
1805
|
|
|
$this->assertEqualSets( array_merge( $c1, $c2 ), $found ); |
1806
|
|
|
} |
1807
|
|
|
|
1808
|
|
|
/** |
1809
|
|
|
* @ticket 35512 |
1810
|
|
|
*/ |
1811
|
|
|
public function test_post_status_any_as_part_of_an_array_of_post_statuses() { |
1812
|
|
|
$p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); |
1813
|
|
|
$p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) ); |
1814
|
|
|
|
1815
|
|
|
$c1 = self::factory()->comment->create_post_comments( $p1, 1 ); |
1816
|
|
|
$c2 = self::factory()->comment->create_post_comments( $p2, 1 ); |
1817
|
|
|
|
1818
|
|
|
$q = new WP_Comment_Query(); |
1819
|
|
|
$found = $q->query( array( |
1820
|
|
|
'fields' => 'ids', |
1821
|
|
|
'post_status' => array( 'any' ), |
1822
|
|
|
) ); |
1823
|
|
|
$this->assertEqualSets( array_merge( $c1, $c2 ), $found ); |
1824
|
|
|
} |
1825
|
|
|
|
1826
|
|
|
/** |
1827
|
|
|
* @ticket 24826 |
1828
|
|
|
*/ |
1829
|
|
|
public function test_comment_query_object() { |
1830
|
|
|
$comment_id = self::factory()->comment->create(); |
|
|
|
|
1831
|
|
|
|
1832
|
|
|
$query1 = new WP_Comment_Query(); |
1833
|
|
|
$this->assertNull( $query1->query_vars ); |
1834
|
|
|
$this->assertEmpty( $query1->comments ); |
1835
|
|
|
$comments = $query1->query( array( 'status' => 'all' ) ); |
|
|
|
|
1836
|
|
|
$this->assertInternalType( 'array', $query1->query_vars ); |
1837
|
|
|
$this->assertNotEmpty( $query1->comments ); |
1838
|
|
|
$this->assertInternalType( 'array', $query1->comments ); |
1839
|
|
|
|
1840
|
|
|
$query2 = new WP_Comment_Query( array( 'status' => 'all' ) ); |
1841
|
|
|
$this->assertNotEmpty( $query2->query_vars ); |
1842
|
|
|
$this->assertNotEmpty( $query2->comments ); |
1843
|
|
|
$this->assertEquals( $query2->comments, $query1->get_comments() ); |
1844
|
|
|
} |
1845
|
|
|
|
1846
|
|
|
/** |
1847
|
|
|
* @ticket 22400 |
1848
|
|
|
*/ |
1849
|
|
|
public function test_comment_cache_key_should_ignore_custom_params() { |
1850
|
|
|
global $wpdb; |
1851
|
|
|
|
1852
|
|
|
$p = self::factory()->post->create(); |
1853
|
|
|
$c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) ); |
|
|
|
|
1854
|
|
|
|
1855
|
|
|
$q1 = new WP_Comment_Query(); |
1856
|
|
|
$q1->query( array( |
1857
|
|
|
'post_id' => $p, |
1858
|
|
|
'fields' => 'ids', |
1859
|
|
|
) ); |
1860
|
|
|
|
1861
|
|
|
$num_queries = $wpdb->num_queries; |
1862
|
|
|
|
1863
|
|
|
$q2 = new WP_Comment_Query(); |
1864
|
|
|
$q2->query( array( |
1865
|
|
|
'post_id' => $p, |
1866
|
|
|
'fields' => 'ids', |
1867
|
|
|
'foo' => 'bar', |
1868
|
|
|
) ); |
1869
|
|
|
|
1870
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
1871
|
|
|
} |
1872
|
|
|
|
1873
|
|
|
/** |
1874
|
|
|
* @ticket 35677 |
1875
|
|
|
*/ |
1876
|
|
|
public function test_cache_should_be_sensitive_to_parent__in() { |
1877
|
|
|
global $wpdb; |
1878
|
|
|
|
1879
|
|
|
$q1 = new WP_Comment_Query( array( |
|
|
|
|
1880
|
|
|
'parent__in' => array( 1, 2, 3 ), |
1881
|
|
|
) ); |
1882
|
|
|
|
1883
|
|
|
$num_queries = $wpdb->num_queries; |
1884
|
|
|
|
1885
|
|
|
$q2 = new WP_Comment_Query( array( |
|
|
|
|
1886
|
|
|
'parent__in' => array( 4, 5, 6 ), |
1887
|
|
|
) ); |
1888
|
|
|
|
1889
|
|
|
$this->assertNotEquals( $num_queries, $wpdb->num_queries ); |
1890
|
|
|
} |
1891
|
|
|
|
1892
|
|
|
/** |
1893
|
|
|
* @ticket 35677 |
1894
|
|
|
*/ |
1895
|
|
|
public function test_cache_should_be_sensitive_to_parent__not_in() { |
1896
|
|
|
global $wpdb; |
1897
|
|
|
|
1898
|
|
|
$q1 = new WP_Comment_Query( array( |
|
|
|
|
1899
|
|
|
'parent__not_in' => array( 1, 2, 3 ), |
1900
|
|
|
) ); |
1901
|
|
|
|
1902
|
|
|
$num_queries = $wpdb->num_queries; |
1903
|
|
|
|
1904
|
|
|
$q2 = new WP_Comment_Query( array( |
|
|
|
|
1905
|
|
|
'parent__not_in' => array( 4, 5, 6 ), |
1906
|
|
|
) ); |
1907
|
|
|
|
1908
|
|
|
$this->assertNotEquals( $num_queries, $wpdb->num_queries ); |
1909
|
|
|
} |
1910
|
|
|
|
1911
|
|
|
/** |
1912
|
|
|
* @ticket 32762 |
1913
|
|
|
*/ |
1914
|
|
|
public function test_it_should_be_possible_to_modify_meta_query_using_pre_get_comments_action() { |
1915
|
|
|
$comments = self::factory()->comment->create_many( 2, array( |
1916
|
|
|
'comment_post_ID' => self::$post_id, |
1917
|
|
|
) ); |
1918
|
|
|
|
1919
|
|
|
add_comment_meta( $comments[1], 'foo', 'bar' ); |
1920
|
|
|
|
1921
|
|
|
add_action( 'pre_get_comments', array( $this, 'modify_meta_query' ) ); |
1922
|
|
|
|
1923
|
|
|
$q = new WP_Comment_Query( array( |
1924
|
|
|
'comment_post_ID' => self::$post_id, |
1925
|
|
|
'fields' => 'ids', |
1926
|
|
|
) ); |
1927
|
|
|
|
1928
|
|
|
remove_action( 'pre_get_comments', array( $this, 'modify_meta_query' ) ); |
1929
|
|
|
|
1930
|
|
|
$this->assertEqualSets( array( $comments[1] ), $q->comments ); |
1931
|
|
|
} |
1932
|
|
|
|
1933
|
|
|
public function modify_meta_query( $q ) { |
1934
|
|
|
$q->meta_query = new WP_Meta_Query( array( |
1935
|
|
|
array( |
1936
|
|
|
'key' => 'foo', |
1937
|
|
|
'value' => 'bar', |
1938
|
|
|
), |
1939
|
|
|
) ); |
1940
|
|
|
} |
1941
|
|
|
|
1942
|
|
|
/** |
1943
|
|
|
* @ticket 32762 |
1944
|
|
|
*/ |
1945
|
|
|
public function test_it_should_be_possible_to_modify_meta_params_using_pre_get_comments_action() { |
1946
|
|
|
$comments = self::factory()->comment->create_many( 2, array( |
1947
|
|
|
'comment_post_ID' => self::$post_id, |
1948
|
|
|
) ); |
1949
|
|
|
|
1950
|
|
|
add_comment_meta( $comments[1], 'foo', 'bar' ); |
1951
|
|
|
|
1952
|
|
|
add_action( 'pre_get_comments', array( $this, 'modify_meta_params' ) ); |
1953
|
|
|
|
1954
|
|
|
$q = new WP_Comment_Query( array( |
1955
|
|
|
'comment_post_ID' => self::$post_id, |
1956
|
|
|
'fields' => 'ids', |
1957
|
|
|
) ); |
1958
|
|
|
|
1959
|
|
|
remove_action( 'pre_get_comments', array( $this, 'modify_meta_params' ) ); |
1960
|
|
|
|
1961
|
|
|
$this->assertEqualSets( array( $comments[1] ), $q->comments ); |
1962
|
|
|
} |
1963
|
|
|
|
1964
|
|
|
public function modify_meta_params( $q ) { |
1965
|
|
|
$q->query_vars['meta_key'] = 'foo'; |
1966
|
|
|
$q->query_vars['meta_value'] = 'bar'; |
1967
|
|
|
} |
1968
|
|
|
|
1969
|
|
|
/** |
1970
|
|
|
* @ticket 33882 |
1971
|
|
|
*/ |
1972
|
|
|
public function test_parent__in() { |
1973
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
1974
|
|
|
$c2 = self::factory()->comment->create( array( |
1975
|
|
|
'comment_post_ID' => self::$post_id, |
1976
|
|
|
'comment_approved' => '1', |
1977
|
|
|
'comment_parent' => $c1, |
1978
|
|
|
) ); |
1979
|
|
|
|
1980
|
|
|
$ids = new WP_Comment_Query( array( |
1981
|
|
|
'comment_post_ID' => self::$post_id, |
1982
|
|
|
'fields' => 'ids', |
1983
|
|
|
'parent__in' => array( $c1 ) |
1984
|
|
|
) ); |
1985
|
|
|
|
1986
|
|
|
$this->assertEqualSets( array( $c2 ), $ids->comments ); |
1987
|
|
|
} |
1988
|
|
|
|
1989
|
|
|
/** |
1990
|
|
|
* @ticket 33882 |
1991
|
|
|
*/ |
1992
|
|
|
public function test_parent__in_commas() { |
1993
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
1994
|
|
|
$c2 = self::factory()->comment->create( array( |
1995
|
|
|
'comment_post_ID' => self::$post_id, |
1996
|
|
|
'comment_approved' => '1' |
1997
|
|
|
) ); |
1998
|
|
|
$c3 = self::factory()->comment->create( array( |
1999
|
|
|
'comment_post_ID' => self::$post_id, |
2000
|
|
|
'comment_approved' => '1', |
2001
|
|
|
'comment_parent' => $c1, |
2002
|
|
|
) ); |
2003
|
|
|
$c4 = self::factory()->comment->create( array( |
2004
|
|
|
'comment_post_ID' => self::$post_id, |
2005
|
|
|
'comment_approved' => '1', |
2006
|
|
|
'comment_parent' => $c2, |
2007
|
|
|
) ); |
2008
|
|
|
|
2009
|
|
|
$ids = new WP_Comment_Query( array( |
2010
|
|
|
'comment_post_ID' => self::$post_id, |
2011
|
|
|
'fields' => 'ids', |
2012
|
|
|
'parent__in' => "$c1,$c2" |
2013
|
|
|
) ); |
2014
|
|
|
|
2015
|
|
|
$this->assertEqualSets( array( $c3, $c4 ), $ids->comments ); |
2016
|
|
|
} |
2017
|
|
|
|
2018
|
|
|
/** |
2019
|
|
|
* @ticket 33882 |
2020
|
|
|
*/ |
2021
|
|
|
public function test_parent__not_in() { |
2022
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
2023
|
|
|
|
2024
|
|
|
self::factory()->comment->create( array( |
2025
|
|
|
'comment_post_ID' => self::$post_id, |
2026
|
|
|
'comment_approved' => '1', |
2027
|
|
|
'comment_parent' => $c1, |
2028
|
|
|
) ); |
2029
|
|
|
|
2030
|
|
|
$ids = new WP_Comment_Query( array( |
2031
|
|
|
'comment_post_ID' => self::$post_id, |
2032
|
|
|
'fields' => 'ids', |
2033
|
|
|
'parent__not_in' => array( $c1 ) |
2034
|
|
|
) ); |
2035
|
|
|
|
2036
|
|
|
$this->assertEqualSets( array( $c1 ), $ids->comments ); |
2037
|
|
|
} |
2038
|
|
|
|
2039
|
|
|
/** |
2040
|
|
|
* @ticket 33882 |
2041
|
|
|
*/ |
2042
|
|
|
public function test_parent__not_in_commas() { |
2043
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
2044
|
|
|
$c2 = self::factory()->comment->create( array( |
2045
|
|
|
'comment_post_ID' => self::$post_id, |
2046
|
|
|
'comment_approved' => '1' |
2047
|
|
|
) ); |
2048
|
|
|
|
2049
|
|
|
self::factory()->comment->create( array( |
2050
|
|
|
'comment_post_ID' => self::$post_id, |
2051
|
|
|
'comment_approved' => '1', |
2052
|
|
|
'comment_parent' => $c1, |
2053
|
|
|
) ); |
2054
|
|
|
self::factory()->comment->create( array( |
2055
|
|
|
'comment_post_ID' => self::$post_id, |
2056
|
|
|
'comment_approved' => '1', |
2057
|
|
|
'comment_parent' => $c2, |
2058
|
|
|
) ); |
2059
|
|
|
|
2060
|
|
|
$ids = new WP_Comment_Query( array( |
2061
|
|
|
'comment_post_ID' => self::$post_id, |
2062
|
|
|
'fields' => 'ids', |
2063
|
|
|
'parent__not_in' => "$c1,$c2" |
2064
|
|
|
) ); |
2065
|
|
|
|
2066
|
|
|
$this->assertEqualSets( array( $c1, $c2 ), $ids->comments ); |
2067
|
|
|
} |
2068
|
|
|
|
2069
|
|
|
/** |
2070
|
|
|
* @ticket 33883 |
2071
|
|
|
*/ |
2072
|
|
|
public function test_orderby_comment__in() { |
2073
|
|
|
self::factory()->comment->create( array( |
2074
|
|
|
'comment_post_ID' => self::$post_id, |
2075
|
|
|
'comment_approved' => '1' |
2076
|
|
|
) ); |
2077
|
|
|
|
2078
|
|
|
$c2 = self::factory()->comment->create( array( |
2079
|
|
|
'comment_post_ID' => self::$post_id, |
2080
|
|
|
'comment_approved' => '1' |
2081
|
|
|
) ); |
2082
|
|
|
$c3 = self::factory()->comment->create( array( |
2083
|
|
|
'comment_post_ID' => self::$post_id, |
2084
|
|
|
'comment_approved' => '1' |
2085
|
|
|
) ); |
2086
|
|
|
|
2087
|
|
|
self::factory()->comment->create( array( |
2088
|
|
|
'comment_post_ID' => self::$post_id, |
2089
|
|
|
'comment_approved' => '1' |
2090
|
|
|
) ); |
2091
|
|
|
|
2092
|
|
|
|
2093
|
|
|
$ids = new WP_Comment_Query( array( |
2094
|
|
|
'fields' => 'ids', |
2095
|
|
|
'comment__in' => array( $c2, $c3 ), |
2096
|
|
|
'orderby' => 'comment__in' |
2097
|
|
|
) ); |
2098
|
|
|
|
2099
|
|
|
$this->assertEquals( array( $c2, $c3 ), $ids->comments ); |
2100
|
|
|
|
2101
|
|
|
} |
2102
|
|
|
|
2103
|
|
|
/** |
2104
|
|
|
* @ticket 8071 |
2105
|
|
|
*/ |
2106
|
|
|
public function test_no_found_rows_should_default_to_true() { |
2107
|
|
|
$comments = self::factory()->comment->create_many( 3, array( 'comment_post_ID' => self::$post_id ) ); |
|
|
|
|
2108
|
|
|
|
2109
|
|
|
$q = new WP_Comment_Query( array( |
2110
|
|
|
'post_id' => self::$post_id, |
2111
|
|
|
'number' => 2, |
2112
|
|
|
) ); |
2113
|
|
|
|
2114
|
|
|
$this->assertEquals( 0, $q->found_comments ); |
2115
|
|
|
$this->assertEquals( 0, $q->max_num_pages ); |
2116
|
|
|
} |
2117
|
|
|
|
2118
|
|
|
/** |
2119
|
|
|
* @ticket 8071 |
2120
|
|
|
*/ |
2121
|
|
|
public function test_should_respect_no_found_rows_true() { |
2122
|
|
|
$comments = self::factory()->comment->create_many( 3, array( 'comment_post_ID' => self::$post_id ) ); |
|
|
|
|
2123
|
|
|
|
2124
|
|
|
$q = new WP_Comment_Query( array( |
2125
|
|
|
'post_id' => self::$post_id, |
2126
|
|
|
'number' => 2, |
2127
|
|
|
'no_found_rows' => true, |
2128
|
|
|
) ); |
2129
|
|
|
|
2130
|
|
|
$this->assertEquals( 0, $q->found_comments ); |
2131
|
|
|
$this->assertEquals( 0, $q->max_num_pages ); |
2132
|
|
|
} |
2133
|
|
|
|
2134
|
|
|
/** |
2135
|
|
|
* @ticket 8071 |
2136
|
|
|
*/ |
2137
|
|
|
public function test_should_respect_no_found_rows_false() { |
2138
|
|
|
$comments = self::factory()->comment->create_many( 3, array( 'comment_post_ID' => self::$post_id ) ); |
|
|
|
|
2139
|
|
|
|
2140
|
|
|
$q = new WP_Comment_Query( array( |
2141
|
|
|
'post_id' => self::$post_id, |
2142
|
|
|
'number' => 2, |
2143
|
|
|
'no_found_rows' => false, |
2144
|
|
|
) ); |
2145
|
|
|
|
2146
|
|
|
$this->assertEquals( 3, $q->found_comments ); |
2147
|
|
|
$this->assertEquals( 2, $q->max_num_pages ); |
2148
|
|
|
} |
2149
|
|
|
|
2150
|
|
|
/** |
2151
|
|
|
* @ticket 37184 |
2152
|
|
|
*/ |
2153
|
|
|
public function test_found_rows_should_be_fetched_from_the_cache() { |
2154
|
|
|
$comments = self::factory()->comment->create_many( 3, array( 'comment_post_ID' => self::$post_id ) ); |
|
|
|
|
2155
|
|
|
|
2156
|
|
|
// Prime cache. |
2157
|
|
|
new WP_Comment_Query( array( |
2158
|
|
|
'post_id' => self::$post_id, |
2159
|
|
|
'number' => 2, |
2160
|
|
|
'no_found_rows' => false, |
2161
|
|
|
) ); |
2162
|
|
|
|
2163
|
|
|
$q = new WP_Comment_Query( array( |
2164
|
|
|
'post_id' => self::$post_id, |
2165
|
|
|
'number' => 2, |
2166
|
|
|
'no_found_rows' => false, |
2167
|
|
|
) ); |
2168
|
|
|
|
2169
|
|
|
$this->assertEquals( 3, $q->found_comments ); |
2170
|
|
|
$this->assertEquals( 2, $q->max_num_pages ); |
2171
|
|
|
} |
2172
|
|
|
|
2173
|
|
|
/** |
2174
|
|
|
* @ticket 8071 |
2175
|
|
|
*/ |
2176
|
|
|
public function test_hierarchical_should_skip_child_comments_in_offset() { |
2177
|
|
|
$top_level_0 = self::factory()->comment->create( array( |
2178
|
|
|
'comment_post_ID' => self::$post_id, |
2179
|
|
|
'comment_approved' => '1', |
2180
|
|
|
) ); |
2181
|
|
|
|
2182
|
|
|
$child_of_0 = self::factory()->comment->create( array( |
|
|
|
|
2183
|
|
|
'comment_post_ID' => self::$post_id, |
2184
|
|
|
'comment_approved' => '1', |
2185
|
|
|
'comment_parent' => $top_level_0, |
2186
|
|
|
) ); |
2187
|
|
|
|
2188
|
|
|
$top_level_comments = self::factory()->comment->create_many( 3, array( |
2189
|
|
|
'comment_post_ID' => self::$post_id, |
2190
|
|
|
'comment_approved' => '1', |
2191
|
|
|
) ); |
2192
|
|
|
|
2193
|
|
|
$q = new WP_Comment_Query( array( |
2194
|
|
|
'post_id' => self::$post_id, |
2195
|
|
|
'hierarchical' => 'flat', |
2196
|
|
|
'number' => 2, |
2197
|
|
|
'offset' => 1, |
2198
|
|
|
'orderby' => 'comment_ID', |
2199
|
|
|
'order' => 'ASC', |
2200
|
|
|
'fields' => 'ids', |
2201
|
|
|
) ); |
2202
|
|
|
|
2203
|
|
|
$this->assertEquals( array( $top_level_comments[0], $top_level_comments[1] ), $q->comments ); |
2204
|
|
|
} |
2205
|
|
|
|
2206
|
|
|
/** |
2207
|
|
|
* @ticket 8071 |
2208
|
|
|
*/ |
2209
|
|
|
public function test_hierarchical_should_not_include_child_comments_in_number() { |
2210
|
|
|
$top_level_0 = self::factory()->comment->create( array( |
2211
|
|
|
'comment_post_ID' => self::$post_id, |
2212
|
|
|
'comment_approved' => '1', |
2213
|
|
|
) ); |
2214
|
|
|
|
2215
|
|
|
$child_of_0 = self::factory()->comment->create( array( |
2216
|
|
|
'comment_post_ID' => self::$post_id, |
2217
|
|
|
'comment_approved' => '1', |
2218
|
|
|
'comment_parent' => $top_level_0, |
2219
|
|
|
) ); |
2220
|
|
|
|
2221
|
|
|
$top_level_comments = self::factory()->comment->create_many( 3, array( |
2222
|
|
|
'comment_post_ID' => self::$post_id, |
2223
|
|
|
'comment_approved' => '1', |
2224
|
|
|
) ); |
2225
|
|
|
|
2226
|
|
|
$q = new WP_Comment_Query( array( |
2227
|
|
|
'post_id' => self::$post_id, |
2228
|
|
|
'hierarchical' => 'flat', |
2229
|
|
|
'number' => 2, |
2230
|
|
|
'orderby' => 'comment_ID', |
2231
|
|
|
'order' => 'ASC', |
2232
|
|
|
) ); |
2233
|
|
|
|
2234
|
|
|
$this->assertEqualSets( array( $top_level_0, $child_of_0, $top_level_comments[0] ), wp_list_pluck( $q->comments, 'comment_ID' ) ); |
2235
|
|
|
} |
2236
|
|
|
|
2237
|
|
|
/** |
2238
|
|
|
* @ticket 8071 |
2239
|
|
|
*/ |
2240
|
|
|
public function test_hierarchical_threaded() { |
2241
|
|
|
$c1 = self::factory()->comment->create( array( |
2242
|
|
|
'comment_post_ID' => self::$post_id, |
2243
|
|
|
'comment_approved' => '1', |
2244
|
|
|
) ); |
2245
|
|
|
|
2246
|
|
|
$c2 = self::factory()->comment->create( array( |
2247
|
|
|
'comment_post_ID' => self::$post_id, |
2248
|
|
|
'comment_approved' => '1', |
2249
|
|
|
'comment_parent' => $c1, |
2250
|
|
|
) ); |
2251
|
|
|
|
2252
|
|
|
$c3 = self::factory()->comment->create( array( |
2253
|
|
|
'comment_post_ID' => self::$post_id, |
2254
|
|
|
'comment_approved' => '1', |
2255
|
|
|
'comment_parent' => $c2, |
2256
|
|
|
) ); |
2257
|
|
|
|
2258
|
|
|
$c4 = self::factory()->comment->create( array( |
2259
|
|
|
'comment_post_ID' => self::$post_id, |
2260
|
|
|
'comment_approved' => '1', |
2261
|
|
|
'comment_parent' => $c1, |
2262
|
|
|
) ); |
2263
|
|
|
|
2264
|
|
|
$c5 = self::factory()->comment->create( array( |
2265
|
|
|
'comment_post_ID' => self::$post_id, |
2266
|
|
|
'comment_approved' => '1', |
2267
|
|
|
) ); |
2268
|
|
|
|
2269
|
|
|
$c6 = self::factory()->comment->create( array( |
2270
|
|
|
'comment_post_ID' => self::$post_id, |
2271
|
|
|
'comment_approved' => '1', |
2272
|
|
|
'comment_parent' => $c5, |
2273
|
|
|
) ); |
2274
|
|
|
|
2275
|
|
|
$args = array( |
2276
|
|
|
'hierarchical' => 'threaded', |
2277
|
|
|
'orderby' => 'comment_ID', |
2278
|
|
|
'order' => 'ASC', |
2279
|
|
|
); |
2280
|
|
|
|
2281
|
|
|
$query_args = array_merge( $args, array( |
2282
|
|
|
'post_id' => self::$post_id, |
2283
|
|
|
) ); |
2284
|
|
|
|
2285
|
|
|
$q = new WP_Comment_Query( $query_args ); |
2286
|
|
|
|
2287
|
|
|
// Top-level comments. |
2288
|
|
|
$this->assertEqualSets( array( $c1, $c5 ), array_values( wp_list_pluck( $q->comments, 'comment_ID' ) ) ); |
2289
|
|
|
|
2290
|
|
|
// Direct descendants of $c1. |
2291
|
|
|
$this->assertEqualSets( array( $c2, $c4 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_children( $args ), 'comment_ID' ) ) ); |
2292
|
|
|
|
2293
|
|
|
// Direct descendants of $c2. |
2294
|
|
|
$this->assertEqualSets( array( $c3 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_child( $c2 )->get_children( $args ), 'comment_ID' ) ) ); |
2295
|
|
|
|
2296
|
|
|
// Direct descendants of $c5. |
2297
|
|
|
$this->assertEqualSets( array( $c6 ), array_values( wp_list_pluck( $q->comments[ $c5 ]->get_children( $args ), 'comment_ID' ) ) ); |
2298
|
|
|
} |
2299
|
|
|
|
2300
|
|
|
/** |
2301
|
|
|
* @ticket 8071 |
2302
|
|
|
*/ |
2303
|
|
|
public function test_hierarchical_threaded_approved() { |
2304
|
|
|
$c1 = self::factory()->comment->create( array( |
2305
|
|
|
'comment_post_ID' => self::$post_id, |
2306
|
|
|
'comment_approved' => '1', |
2307
|
|
|
) ); |
2308
|
|
|
|
2309
|
|
|
$c2 = self::factory()->comment->create( array( |
2310
|
|
|
'comment_post_ID' => self::$post_id, |
2311
|
|
|
'comment_approved' => '1', |
2312
|
|
|
'comment_parent' => $c1, |
2313
|
|
|
) ); |
2314
|
|
|
|
2315
|
|
|
$c3 = self::factory()->comment->create( array( |
|
|
|
|
2316
|
|
|
'comment_post_ID' => self::$post_id, |
2317
|
|
|
'comment_approved' => '0', |
2318
|
|
|
'comment_parent' => $c2, |
2319
|
|
|
) ); |
2320
|
|
|
|
2321
|
|
|
$c4 = self::factory()->comment->create( array( |
2322
|
|
|
'comment_post_ID' => self::$post_id, |
2323
|
|
|
'comment_approved' => '1', |
2324
|
|
|
'comment_parent' => $c1, |
2325
|
|
|
) ); |
2326
|
|
|
|
2327
|
|
|
$c5 = self::factory()->comment->create( array( |
2328
|
|
|
'comment_post_ID' => self::$post_id, |
2329
|
|
|
'comment_approved' => '1', |
2330
|
|
|
) ); |
2331
|
|
|
|
2332
|
|
|
self::factory()->comment->create( array( |
2333
|
|
|
'comment_post_ID' => self::$post_id, |
2334
|
|
|
'comment_approved' => '1', |
2335
|
|
|
'comment_parent' => $c5, |
2336
|
|
|
) ); |
2337
|
|
|
|
2338
|
|
|
$args = array( |
2339
|
|
|
'hierarchical' => 'threaded', |
2340
|
|
|
'status' => 'approve', |
2341
|
|
|
'orderby' => 'comment_ID', |
2342
|
|
|
'order' => 'ASC', |
2343
|
|
|
); |
2344
|
|
|
|
2345
|
|
|
$query_args = array_merge( $args, array( |
2346
|
|
|
'post_id' => self::$post_id, |
2347
|
|
|
) ); |
2348
|
|
|
|
2349
|
|
|
$q = new WP_Comment_Query( $query_args ); |
2350
|
|
|
|
2351
|
|
|
// Top-level comments. |
2352
|
|
|
$this->assertEqualSets( array( $c1, $c5 ), array_values( wp_list_pluck( $q->comments, 'comment_ID' ) ) ); |
2353
|
|
|
|
2354
|
|
|
// Direct descendants of $c1. |
2355
|
|
|
$this->assertEqualSets( array( $c2, $c4 ), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_children( $args ), 'comment_ID' ) ) ); |
2356
|
|
|
|
2357
|
|
|
// Direct descendants of $c2. |
2358
|
|
|
$this->assertEqualSets( array(), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_child( $c2 )->get_children( $args ), 'comment_ID' ) ) ); |
2359
|
|
|
} |
2360
|
|
|
|
2361
|
|
|
/** |
2362
|
|
|
* @ticket 35192 |
2363
|
|
|
*/ |
2364
|
|
|
public function test_comment_clauses_prepend_callback_should_be_respected_when_filling_descendants() { |
2365
|
|
|
$top_level_0 = self::factory()->comment->create( array( |
2366
|
|
|
'comment_post_ID' => self::$post_id, |
2367
|
|
|
'comment_approved' => '1', |
2368
|
|
|
) ); |
2369
|
|
|
|
2370
|
|
|
$child1_of_0 = self::factory()->comment->create( array( |
2371
|
|
|
'comment_post_ID' => self::$post_id, |
2372
|
|
|
'comment_approved' => '1', |
2373
|
|
|
'comment_parent' => $top_level_0, |
2374
|
|
|
) ); |
2375
|
|
|
|
2376
|
|
|
$child2_of_0 = self::factory()->comment->create( array( |
2377
|
|
|
'comment_post_ID' => self::$post_id, |
2378
|
|
|
'comment_approved' => '1', |
2379
|
|
|
'comment_parent' => $top_level_0, |
2380
|
|
|
) ); |
2381
|
|
|
|
2382
|
|
|
$top_level_comments = self::factory()->comment->create_many( 3, array( |
2383
|
|
|
'comment_post_ID' => self::$post_id, |
2384
|
|
|
'comment_approved' => '1', |
2385
|
|
|
) ); |
2386
|
|
|
|
2387
|
|
|
$this->to_exclude = array( $child2_of_0, $top_level_comments[1] ); |
2388
|
|
|
|
2389
|
|
|
add_filter( 'comments_clauses', array( $this, 'prepend_exclusions' ) ); |
2390
|
|
|
$q = new WP_Comment_Query( array( |
2391
|
|
|
'post_id' => self::$post_id, |
2392
|
|
|
'hierarchical' => 'flat', |
2393
|
|
|
) ); |
2394
|
|
|
remove_filter( 'comments_clauses', array( $this, 'prepend_exclusions' ) ); |
2395
|
|
|
|
2396
|
|
|
unset( $this->to_exclude ); |
2397
|
|
|
|
2398
|
|
|
$this->assertEqualSets( array( $top_level_0, $child1_of_0, $top_level_comments[0], $top_level_comments[2] ), wp_list_pluck( $q->comments, 'comment_ID' ) ); |
2399
|
|
|
} |
2400
|
|
|
|
2401
|
|
|
public function prepend_exclusions( $clauses ) { |
2402
|
|
|
global $wpdb; |
2403
|
|
|
$clauses['where'] = $wpdb->prepare( 'comment_ID != %d AND comment_ID != %d AND ', $this->to_exclude[0], $this->to_exclude[1] ) . $clauses['where']; |
2404
|
|
|
return $clauses; |
2405
|
|
|
} |
2406
|
|
|
|
2407
|
|
|
/** |
2408
|
|
|
* @ticket 35192 |
2409
|
|
|
*/ |
2410
|
|
|
public function test_comment_clauses_append_callback_should_be_respected_when_filling_descendants() { |
2411
|
|
|
$top_level_0 = self::factory()->comment->create( array( |
2412
|
|
|
'comment_post_ID' => self::$post_id, |
2413
|
|
|
'comment_approved' => '1', |
2414
|
|
|
) ); |
2415
|
|
|
|
2416
|
|
|
$child1_of_0 = self::factory()->comment->create( array( |
2417
|
|
|
'comment_post_ID' => self::$post_id, |
2418
|
|
|
'comment_approved' => '1', |
2419
|
|
|
'comment_parent' => $top_level_0, |
2420
|
|
|
) ); |
2421
|
|
|
|
2422
|
|
|
$child2_of_0 = self::factory()->comment->create( array( |
2423
|
|
|
'comment_post_ID' => self::$post_id, |
2424
|
|
|
'comment_approved' => '1', |
2425
|
|
|
'comment_parent' => $top_level_0, |
2426
|
|
|
) ); |
2427
|
|
|
|
2428
|
|
|
$top_level_comments = self::factory()->comment->create_many( 3, array( |
2429
|
|
|
'comment_post_ID' => self::$post_id, |
2430
|
|
|
'comment_approved' => '1', |
2431
|
|
|
) ); |
2432
|
|
|
|
2433
|
|
|
$this->to_exclude = array( $child2_of_0, $top_level_comments[1] ); |
2434
|
|
|
|
2435
|
|
|
add_filter( 'comments_clauses', array( $this, 'append_exclusions' ) ); |
2436
|
|
|
$q = new WP_Comment_Query( array( |
2437
|
|
|
'post_id' => self::$post_id, |
2438
|
|
|
'hierarchical' => 'flat', |
2439
|
|
|
) ); |
2440
|
|
|
remove_filter( 'comments_clauses', array( $this, 'append_exclusions' ) ); |
2441
|
|
|
|
2442
|
|
|
unset( $this->to_exclude ); |
2443
|
|
|
|
2444
|
|
|
$this->assertEqualSets( array( $top_level_0, $child1_of_0, $top_level_comments[0], $top_level_comments[2] ), wp_list_pluck( $q->comments, 'comment_ID' ) ); |
2445
|
|
|
} |
2446
|
|
|
|
2447
|
|
|
public function append_exclusions( $clauses ) { |
2448
|
|
|
global $wpdb; |
2449
|
|
|
$clauses['where'] .= $wpdb->prepare( ' AND comment_ID != %d AND comment_ID != %d', $this->to_exclude[0], $this->to_exclude[1] ); |
2450
|
|
|
return $clauses; |
2451
|
|
|
} |
2452
|
|
|
|
2453
|
|
|
/** |
2454
|
|
|
* @ticket 36487 |
2455
|
|
|
*/ |
2456
|
|
|
public function test_cache_should_be_hit_when_querying_descendants() { |
2457
|
|
|
global $wpdb; |
2458
|
|
|
|
2459
|
|
|
$p = self::factory()->post->create(); |
2460
|
|
|
$comment_1 = self::factory()->comment->create( array( |
2461
|
|
|
'comment_post_ID' => $p, |
2462
|
|
|
'comment_approved' => '1', |
2463
|
|
|
) ); |
2464
|
|
|
$comment_2 = self::factory()->comment->create( array( |
2465
|
|
|
'comment_post_ID' => $p, |
2466
|
|
|
'comment_approved' => '1', |
2467
|
|
|
'comment_parent' => $comment_1, |
2468
|
|
|
) ); |
2469
|
|
|
$comment_3 = self::factory()->comment->create( array( |
|
|
|
|
2470
|
|
|
'comment_post_ID' => $p, |
2471
|
|
|
'comment_approved' => '1', |
2472
|
|
|
'comment_parent' => $comment_1, |
2473
|
|
|
) ); |
2474
|
|
|
$comment_4 = self::factory()->comment->create( array( |
|
|
|
|
2475
|
|
|
'comment_post_ID' => $p, |
2476
|
|
|
'comment_approved' => '1', |
2477
|
|
|
'comment_parent' => $comment_2, |
2478
|
|
|
) ); |
2479
|
|
|
|
2480
|
|
|
$q1 = new WP_Comment_Query( array( |
2481
|
|
|
'post_id' => $p, |
2482
|
|
|
'hierarchical' => true, |
2483
|
|
|
) ); |
2484
|
|
|
$q1_ids = wp_list_pluck( $q1->comments, 'comment_ID' ); |
2485
|
|
|
|
2486
|
|
|
$num_queries = $wpdb->num_queries; |
2487
|
|
|
$q2 = new WP_Comment_Query( array( |
2488
|
|
|
'post_id' => $p, |
2489
|
|
|
'hierarchical' => true, |
2490
|
|
|
) ); |
2491
|
|
|
$q2_ids = wp_list_pluck( $q2->comments, 'comment_ID' ); |
2492
|
|
|
|
2493
|
|
|
$this->assertEqualSets( $q1_ids, $q2_ids ); |
2494
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2495
|
|
|
} |
2496
|
|
|
|
2497
|
|
|
/** |
2498
|
|
|
* @ticket 37696 |
2499
|
|
|
*/ |
2500
|
|
|
public function test_hierarchy_should_be_filled_when_cache_is_incomplete() { |
2501
|
|
|
global $wpdb; |
2502
|
|
|
|
2503
|
|
|
$p = self::factory()->post->create(); |
2504
|
|
|
$comment_1 = self::factory()->comment->create( array( |
2505
|
|
|
'comment_post_ID' => $p, |
2506
|
|
|
'comment_approved' => '1', |
2507
|
|
|
) ); |
2508
|
|
|
$comment_2 = self::factory()->comment->create( array( |
2509
|
|
|
'comment_post_ID' => $p, |
2510
|
|
|
'comment_approved' => '1', |
2511
|
|
|
'comment_parent' => $comment_1, |
2512
|
|
|
) ); |
2513
|
|
|
$comment_3 = self::factory()->comment->create( array( |
2514
|
|
|
'comment_post_ID' => $p, |
2515
|
|
|
'comment_approved' => '1', |
2516
|
|
|
'comment_parent' => $comment_1, |
2517
|
|
|
) ); |
2518
|
|
|
$comment_4 = self::factory()->comment->create( array( |
2519
|
|
|
'comment_post_ID' => $p, |
2520
|
|
|
'comment_approved' => '1', |
2521
|
|
|
'comment_parent' => $comment_2, |
2522
|
|
|
) ); |
2523
|
|
|
|
2524
|
|
|
// Prime cache. |
2525
|
|
|
$q1 = new WP_Comment_Query( array( |
2526
|
|
|
'post_id' => $p, |
2527
|
|
|
'hierarchical' => true, |
2528
|
|
|
) ); |
2529
|
|
|
$q1_ids = wp_list_pluck( $q1->comments, 'comment_ID' ); |
2530
|
|
|
$this->assertEqualSets( array( $comment_1, $comment_2, $comment_3, $comment_4 ), $q1_ids ); |
2531
|
|
|
|
2532
|
|
|
// Delete one of the parent caches. |
2533
|
|
|
$last_changed = wp_cache_get( 'last_changed', 'comment' ); |
2534
|
|
|
$key = md5( serialize( wp_array_slice_assoc( $q1->query_vars, array_keys( $q1->query_var_defaults ) ) ) ); |
2535
|
|
|
$cache_key = "get_comment_child_ids:$comment_2:$key:$last_changed"; |
2536
|
|
|
wp_cache_delete( $cache_key, 'comment' ); |
2537
|
|
|
|
2538
|
|
|
$q2 = new WP_Comment_Query( array( |
2539
|
|
|
'post_id' => $p, |
2540
|
|
|
'hierarchical' => true, |
2541
|
|
|
) ); |
2542
|
|
|
$q2_ids = wp_list_pluck( $q2->comments, 'comment_ID' ); |
2543
|
|
|
$this->assertEqualSets( $q1_ids, $q2_ids ); |
2544
|
|
|
} |
2545
|
|
|
|
2546
|
|
|
/** |
2547
|
|
|
* @ticket 37966 |
2548
|
|
|
* @ticket 37696 |
2549
|
|
|
*/ |
2550
|
|
|
public function test_fill_hierarchy_should_disregard_offset_and_number() { |
2551
|
|
|
$c0 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
|
|
|
|
2552
|
|
|
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
2553
|
|
|
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c1 ) ); |
2554
|
|
|
$c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) ); |
2555
|
|
|
$c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c3 ) ); |
2556
|
|
|
$c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c3 ) ); |
2557
|
|
|
|
2558
|
|
|
$q = new WP_Comment_Query(); |
2559
|
|
|
$found = $q->query( array( |
2560
|
|
|
'orderby' => 'comment_date_gmt', |
2561
|
|
|
'order' => 'ASC', |
2562
|
|
|
'status' => 'approve', |
2563
|
|
|
'post_id' => self::$post_id, |
2564
|
|
|
'no_found_rows' => false, |
2565
|
|
|
'hierarchical' => 'threaded', |
2566
|
|
|
'number' => 2, |
2567
|
|
|
'offset' => 1, |
2568
|
|
|
) ); |
2569
|
|
|
|
2570
|
|
|
|
2571
|
|
|
$found_1 = $found[ $c1 ]; |
2572
|
|
|
$children_1 = $found_1->get_children(); |
2573
|
|
|
$this->assertEqualSets( array( $c2 ), array_keys( $children_1 ) ); |
2574
|
|
|
|
2575
|
|
|
$found_3 = $found[ $c3 ]; |
2576
|
|
|
$children_3 = $found_3->get_children(); |
2577
|
|
|
$this->assertEqualSets( array( $c4, $c5 ), array_keys( $children_3 ) ); |
2578
|
|
|
} |
2579
|
|
|
|
2580
|
|
|
/** |
2581
|
|
|
* @ticket 27571 |
2582
|
|
|
*/ |
2583
|
|
|
public function test_update_comment_post_cache_should_be_disabled_by_default() { |
2584
|
|
|
global $wpdb; |
2585
|
|
|
|
2586
|
|
|
$p = self::factory()->post->create(); |
2587
|
|
|
$c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) ); |
|
|
|
|
2588
|
|
|
|
2589
|
|
|
$q = new WP_Comment_Query( array( |
2590
|
|
|
'post_ID' => $p, |
2591
|
|
|
) ); |
2592
|
|
|
|
2593
|
|
|
$num_queries = $wpdb->num_queries; |
2594
|
|
|
$this->assertTrue( isset( $q->comments[0]->post_name ) ); |
2595
|
|
|
$this->assertSame( $num_queries + 1, $wpdb->num_queries ); |
2596
|
|
|
} |
2597
|
|
|
|
2598
|
|
|
/** |
2599
|
|
|
* @ticket 27571 |
2600
|
|
|
*/ |
2601
|
|
|
public function test_should_respect_update_comment_post_cache_true() { |
2602
|
|
|
global $wpdb; |
2603
|
|
|
|
2604
|
|
|
$p = self::factory()->post->create(); |
2605
|
|
|
$c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) ); |
|
|
|
|
2606
|
|
|
|
2607
|
|
|
$q = new WP_Comment_Query( array( |
2608
|
|
|
'post_ID' => $p, |
2609
|
|
|
'update_comment_post_cache' => true, |
2610
|
|
|
) ); |
2611
|
|
|
|
2612
|
|
|
$num_queries = $wpdb->num_queries; |
2613
|
|
|
$this->assertTrue( isset( $q->comments[0]->post_name ) ); |
2614
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2615
|
|
|
} |
2616
|
|
|
|
2617
|
|
|
/** |
2618
|
|
|
* @ticket 34138 |
2619
|
|
|
*/ |
2620
|
|
|
public function test_comment_objects_should_be_filled_from_cache() { |
2621
|
|
|
global $wpdb; |
2622
|
|
|
|
2623
|
|
|
$comments = self::factory()->comment->create_many( 3, array( 'comment_post_ID' => self::$post_id ) ); |
2624
|
|
|
clean_comment_cache( $comments ); |
2625
|
|
|
|
2626
|
|
|
$num_queries = $wpdb->num_queries; |
2627
|
|
|
$q = new WP_Comment_Query( array( |
2628
|
|
|
'post_id' => self::$post_id, |
2629
|
|
|
'no_found_rows' => true, |
2630
|
|
|
'update_comment_post_cache' => false, |
2631
|
|
|
'update_comment_meta_cache' => false, |
2632
|
|
|
) ); |
2633
|
|
|
|
2634
|
|
|
// 2 queries should have been fired: one for IDs, one to prime comment caches. |
2635
|
|
|
$num_queries += 2; |
2636
|
|
|
|
2637
|
|
|
$found = wp_list_pluck( $q->comments, 'comment_ID' ); |
2638
|
|
|
$this->assertEqualSets( $comments, $found ); |
2639
|
|
|
|
2640
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2641
|
|
|
} |
2642
|
|
|
|
2643
|
|
|
/** |
2644
|
|
|
* @ticket 34138 |
2645
|
|
|
*/ |
2646
|
|
|
public function test_comment_objects_should_be_fetched_from_database_when_suspend_cache_addition() { |
2647
|
|
|
$suspend = wp_suspend_cache_addition(); |
2648
|
|
|
wp_suspend_cache_addition( true ); |
2649
|
|
|
|
2650
|
|
|
$c = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id ) ); |
2651
|
|
|
|
2652
|
|
|
$q = new WP_Comment_Query( array( |
2653
|
|
|
'post_id' => self::$post_id, |
2654
|
|
|
) ); |
2655
|
|
|
|
2656
|
|
|
wp_suspend_cache_addition( $suspend ); |
2657
|
|
|
|
2658
|
|
|
$found = wp_list_pluck( $q->comments, 'comment_ID' ); |
2659
|
|
|
$this->assertEqualSets( array( $c ), $found ); |
2660
|
|
|
} |
2661
|
|
|
|
2662
|
|
|
public function test_comment_query_should_be_cached() { |
2663
|
|
|
global $wpdb; |
2664
|
|
|
|
2665
|
|
|
$q = new WP_Comment_Query( array( |
|
|
|
|
2666
|
|
|
'post_id' => self::$post_id, |
2667
|
|
|
'fields' => 'ids', |
2668
|
|
|
) ); |
2669
|
|
|
|
2670
|
|
|
$c = wp_insert_comment( array( |
|
|
|
|
2671
|
|
|
'comment_author' => 'Foo', |
2672
|
|
|
'comment_author_email' => '[email protected]', |
2673
|
|
|
'comment_post_ID' => self::$post_id, |
2674
|
|
|
) ); |
2675
|
|
|
|
2676
|
|
|
$num_queries = $wpdb->num_queries; |
|
|
|
|
2677
|
|
|
} |
2678
|
|
|
|
2679
|
|
|
public function test_created_comment_should_invalidate_query_cache() { |
2680
|
|
|
global $wpdb; |
2681
|
|
|
|
2682
|
|
|
$c = self::factory()->comment->create( array( |
2683
|
|
|
'comment_post_ID' => self::$post_id, |
2684
|
|
|
'comment_approved' => '1', |
2685
|
|
|
) ); |
2686
|
|
|
|
2687
|
|
|
$q = new WP_Comment_Query( array( |
|
|
|
|
2688
|
|
|
'post_id' => self::$post_id, |
2689
|
|
|
'fields' => 'ids', |
2690
|
|
|
) ); |
2691
|
|
|
|
2692
|
|
|
$num_queries = $wpdb->num_queries; |
2693
|
|
|
|
2694
|
|
|
$q = new WP_Comment_Query( array( |
2695
|
|
|
'post_id' => self::$post_id, |
2696
|
|
|
'fields' => 'ids', |
2697
|
|
|
) ); |
2698
|
|
|
|
2699
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2700
|
|
|
$this->assertEqualSets( array( $c ), $q->comments ); |
2701
|
|
|
} |
2702
|
|
|
|
2703
|
|
|
public function test_updated_comment_should_invalidate_query_cache() { |
2704
|
|
|
global $wpdb; |
2705
|
|
|
|
2706
|
|
|
$c = self::factory()->comment->create( array( |
2707
|
|
|
'comment_post_ID' => self::$post_id, |
2708
|
|
|
'comment_approved' => '1', |
2709
|
|
|
) ); |
2710
|
|
|
|
2711
|
|
|
$q = new WP_Comment_Query( array( |
|
|
|
|
2712
|
|
|
'post_id' => self::$post_id, |
2713
|
|
|
'fields' => 'ids', |
2714
|
|
|
) ); |
2715
|
|
|
|
2716
|
|
|
wp_update_comment( array( |
2717
|
|
|
'comment_ID' => $c, |
2718
|
|
|
'comment_author' => 'Foo', |
2719
|
|
|
'comment_author_email' => '[email protected]', |
2720
|
|
|
'comment_post_ID' => self::$post_id, |
2721
|
|
|
) ); |
2722
|
|
|
|
2723
|
|
|
$num_queries = $wpdb->num_queries; |
2724
|
|
|
|
2725
|
|
|
$q = new WP_Comment_Query( array( |
2726
|
|
|
'post_id' => self::$post_id, |
2727
|
|
|
'fields' => 'ids', |
2728
|
|
|
) ); |
2729
|
|
|
|
2730
|
|
|
$num_queries++; |
2731
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2732
|
|
|
$this->assertEqualSets( array( $c ), $q->comments ); |
2733
|
|
|
} |
2734
|
|
|
|
2735
|
|
|
public function test_deleted_comment_should_invalidate_query_cache() { |
2736
|
|
|
global $wpdb; |
2737
|
|
|
|
2738
|
|
|
$c = self::factory()->comment->create( array( |
2739
|
|
|
'comment_post_ID' => self::$post_id, |
2740
|
|
|
'comment_approved' => '1', |
2741
|
|
|
) ); |
2742
|
|
|
|
2743
|
|
|
$q = new WP_Comment_Query( array( |
|
|
|
|
2744
|
|
|
'post_id' => self::$post_id, |
2745
|
|
|
'fields' => 'ids', |
2746
|
|
|
) ); |
2747
|
|
|
|
2748
|
|
|
wp_delete_comment( $c ); |
2749
|
|
|
|
2750
|
|
|
$num_queries = $wpdb->num_queries; |
2751
|
|
|
|
2752
|
|
|
$q = new WP_Comment_Query( array( |
2753
|
|
|
'post_id' => self::$post_id, |
2754
|
|
|
'fields' => 'ids', |
2755
|
|
|
) ); |
2756
|
|
|
|
2757
|
|
|
$num_queries++; |
2758
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2759
|
|
|
$this->assertEqualSets( array(), $q->comments ); |
2760
|
|
|
} |
2761
|
|
|
|
2762
|
|
|
public function test_trashed_comment_should_invalidate_query_cache() { |
2763
|
|
|
global $wpdb; |
2764
|
|
|
|
2765
|
|
|
$c = self::factory()->comment->create( array( |
2766
|
|
|
'comment_post_ID' => self::$post_id, |
2767
|
|
|
'comment_approved' => '1', |
2768
|
|
|
) ); |
2769
|
|
|
|
2770
|
|
|
$q = new WP_Comment_Query( array( |
|
|
|
|
2771
|
|
|
'post_id' => self::$post_id, |
2772
|
|
|
'fields' => 'ids', |
2773
|
|
|
) ); |
2774
|
|
|
|
2775
|
|
|
wp_trash_comment( $c ); |
2776
|
|
|
|
2777
|
|
|
$num_queries = $wpdb->num_queries; |
2778
|
|
|
|
2779
|
|
|
$q = new WP_Comment_Query( array( |
2780
|
|
|
'post_id' => self::$post_id, |
2781
|
|
|
'fields' => 'ids', |
2782
|
|
|
) ); |
2783
|
|
|
|
2784
|
|
|
$num_queries++; |
2785
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2786
|
|
|
$this->assertEqualSets( array(), $q->comments ); |
2787
|
|
|
} |
2788
|
|
|
|
2789
|
|
|
public function test_untrashed_comment_should_invalidate_query_cache() { |
2790
|
|
|
global $wpdb; |
2791
|
|
|
|
2792
|
|
|
$c = self::factory()->comment->create( array( |
2793
|
|
|
'comment_post_ID' => self::$post_id, |
2794
|
|
|
'comment_approved' => '1', |
2795
|
|
|
) ); |
2796
|
|
|
|
2797
|
|
|
wp_trash_comment( $c ); |
2798
|
|
|
|
2799
|
|
|
$q = new WP_Comment_Query( array( |
|
|
|
|
2800
|
|
|
'post_id' => self::$post_id, |
2801
|
|
|
'fields' => 'ids', |
2802
|
|
|
) ); |
2803
|
|
|
|
2804
|
|
|
wp_untrash_comment( $c ); |
2805
|
|
|
|
2806
|
|
|
$num_queries = $wpdb->num_queries; |
2807
|
|
|
|
2808
|
|
|
$q = new WP_Comment_Query( array( |
2809
|
|
|
'post_id' => self::$post_id, |
2810
|
|
|
'fields' => 'ids', |
2811
|
|
|
) ); |
2812
|
|
|
|
2813
|
|
|
$num_queries++; |
2814
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2815
|
|
|
$this->assertEqualSets( array( $c ), $q->comments ); |
2816
|
|
|
} |
2817
|
|
|
|
2818
|
|
|
public function test_spammed_comment_should_invalidate_query_cache() { |
2819
|
|
|
global $wpdb; |
2820
|
|
|
|
2821
|
|
|
$c = self::factory()->comment->create( array( |
2822
|
|
|
'comment_post_ID' => self::$post_id, |
2823
|
|
|
'comment_approved' => '1', |
2824
|
|
|
) ); |
2825
|
|
|
|
2826
|
|
|
$q = new WP_Comment_Query( array( |
|
|
|
|
2827
|
|
|
'post_id' => self::$post_id, |
2828
|
|
|
'fields' => 'ids', |
2829
|
|
|
) ); |
2830
|
|
|
|
2831
|
|
|
wp_spam_comment( $c ); |
2832
|
|
|
|
2833
|
|
|
$num_queries = $wpdb->num_queries; |
2834
|
|
|
|
2835
|
|
|
$q = new WP_Comment_Query( array( |
2836
|
|
|
'post_id' => self::$post_id, |
2837
|
|
|
'fields' => 'ids', |
2838
|
|
|
) ); |
2839
|
|
|
|
2840
|
|
|
$num_queries++; |
2841
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2842
|
|
|
$this->assertEqualSets( array(), $q->comments ); |
2843
|
|
|
} |
2844
|
|
|
|
2845
|
|
|
public function test_unspammed_comment_should_invalidate_query_cache() { |
2846
|
|
|
global $wpdb; |
2847
|
|
|
|
2848
|
|
|
$c = self::factory()->comment->create( array( |
2849
|
|
|
'comment_post_ID' => self::$post_id, |
2850
|
|
|
'comment_approved' => '1', |
2851
|
|
|
) ); |
2852
|
|
|
|
2853
|
|
|
wp_spam_comment( $c ); |
2854
|
|
|
|
2855
|
|
|
$q = new WP_Comment_Query( array( |
|
|
|
|
2856
|
|
|
'post_id' => self::$post_id, |
2857
|
|
|
'fields' => 'ids', |
2858
|
|
|
) ); |
2859
|
|
|
|
2860
|
|
|
wp_unspam_comment( $c ); |
2861
|
|
|
|
2862
|
|
|
$num_queries = $wpdb->num_queries; |
2863
|
|
|
|
2864
|
|
|
$q = new WP_Comment_Query( array( |
2865
|
|
|
'post_id' => self::$post_id, |
2866
|
|
|
'fields' => 'ids', |
2867
|
|
|
) ); |
2868
|
|
|
|
2869
|
|
|
$num_queries++; |
2870
|
|
|
$this->assertSame( $num_queries, $wpdb->num_queries ); |
2871
|
|
|
$this->assertEqualSets( array( $c ), $q->comments ); |
2872
|
|
|
} |
2873
|
|
|
} |
2874
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.