forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseQuery.php
More file actions
236 lines (204 loc) · 4 KB
/
parseQuery.php
File metadata and controls
236 lines (204 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
/**
* @group query
*/
class Tests_Query_ParseQuery extends WP_UnitTestCase {
/**
* @ticket 29736
*/
public function test_parse_query_s_array() {
$q = new WP_Query();
$q->parse_query(
array(
's' => array( 'foo' ),
)
);
$this->assertSame( '', $q->query_vars['s'] );
}
public function test_parse_query_s_string() {
$q = new WP_Query();
$q->parse_query(
array(
's' => 'foo',
)
);
$this->assertSame( 'foo', $q->query_vars['s'] );
}
public function test_parse_query_s_float() {
$q = new WP_Query();
$q->parse_query(
array(
's' => 3.5,
)
);
$this->assertSame( 3.5, $q->query_vars['s'] );
}
public function test_parse_query_s_int() {
$q = new WP_Query();
$q->parse_query(
array(
's' => 3,
)
);
$this->assertSame( 3, $q->query_vars['s'] );
}
public function test_parse_query_s_bool() {
$q = new WP_Query();
$q->parse_query(
array(
's' => true,
)
);
$this->assertTrue( $q->query_vars['s'] );
}
/**
* @ticket 33372
*/
public function test_parse_query_p_negative_int() {
$q = new WP_Query();
$q->parse_query(
array(
'p' => -3,
)
);
$this->assertSame( '404', $q->query_vars['error'] );
}
/**
* @ticket 33372
*/
public function test_parse_query_p_array() {
$q = new WP_Query();
$q->parse_query(
array(
'p' => array(),
)
);
$this->assertSame( '404', $q->query_vars['error'] );
}
/**
* @ticket 33372
*/
public function test_parse_query_p_object() {
$q = new WP_Query();
$q->parse_query(
array(
'p' => new stdClass(),
)
);
$this->assertSame( '404', $q->query_vars['error'] );
}
/**
* Ensure an array of authors is rejected.
*
* @ticket 17737
*/
public function test_parse_query_author_array() {
$q = new WP_Query();
$q->parse_query(
array(
'author' => array( 1, 2, 3 ),
)
);
$this->assertEmpty( $q->query_vars['author'] );
}
/**
* Ensure a non-scalar (non-numeric) author value is rejected.
*
* @ticket 17737
*/
public function test_parse_query_author_string() {
$q = new WP_Query();
$q->parse_query(
array(
'author' => 'admin',
)
);
$this->assertEmpty( $q->query_vars['author'] );
}
/**
* Ensure nonscalar 'cat' array values are rejected.
*
* Note the returned 'cat' query_var value is a string.
*
* @ticket 17737
*/
public function test_parse_query_cat_array_mixed() {
$q = new WP_Query();
$q->parse_query(
array(
'cat' => array( 1, 'uncategorized', '-1' ),
)
);
$this->assertSame( '-1,1', $q->query_vars['cat'] );
}
/**
* Ensure a nonscalar menu_order value is rejected.
*
* @ticket 17737
*/
public function test_parse_query_menu_order_nonscalar() {
$q = new WP_Query();
$q->parse_query(
array(
'menu_order' => array( 1 ),
)
);
$this->assertEmpty( $q->query_vars['menu_order'] );
}
/**
* Ensure numeric 'subpost' gets assigned to 'attachment'.
*
* @ticket 17737
*/
public function test_parse_query_subpost_scalar() {
$q = new WP_Query();
$q->parse_query(
array(
'subpost' => 1,
)
);
$this->assertSame( 1, $q->query_vars['attachment'] );
}
/**
* Ensure non-scalar 'subpost' does not get assigned to 'attachment'.
*
* @ticket 17737
*/
public function test_parse_query_subpost_nonscalar() {
$q = new WP_Query();
$q->parse_query(
array(
'subpost' => array( 1 ),
)
);
$this->assertEmpty( $q->query_vars['attachment'] );
}
/**
* Ensure numeric 'attachment_id' value is assigned.
*
* @ticket 17737
*/
public function test_parse_query_attachment_id() {
$q = new WP_Query();
$q->parse_query(
array(
'attachment_id' => 1,
)
);
$this->assertSame( 1, $q->query_vars['attachment_id'] );
}
/**
* Ensure non-scalar 'attachment_id' value is rejected.
*
* @ticket 17737
*/
public function test_parse_query_attachment_id_nonscalar() {
$q = new WP_Query();
$q->parse_query(
array(
'attachment_id' => array( 1 ),
)
);
$this->assertEmpty( $q->query_vars['attachment_id'] );
}
}