|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Test the is_*() functions in query.php across the URL structure |
|
5
|
|
|
* |
|
6
|
|
|
* This exercises both query.php and rewrite.php: urls are fed through the rewrite code, |
|
7
|
|
|
* then we test the effects of each url on the wp_query object. |
|
8
|
|
|
* |
|
9
|
|
|
* @group query |
|
10
|
|
|
* @group rewrite |
|
11
|
|
|
*/ |
|
12
|
|
|
class Tests_Query_Conditionals extends WP_UnitTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
protected $page_ids; |
|
16
|
|
|
protected $post_ids; |
|
17
|
|
|
|
|
18
|
|
View Code Duplication |
function setUp() |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
parent::setUp(); |
|
21
|
|
|
|
|
22
|
|
|
set_current_screen('front'); |
|
23
|
|
|
|
|
24
|
|
|
update_option('comments_per_page', 5); |
|
25
|
|
|
update_option('posts_per_page', 5); |
|
26
|
|
|
|
|
27
|
|
|
$this->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); |
|
28
|
|
|
|
|
29
|
|
|
create_initial_taxonomies(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
function test_home() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->go_to('/'); |
|
35
|
|
|
$this->assertQueryTrue('is_home', 'is_front_page'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function test_page_on_front() |
|
39
|
|
|
{ |
|
40
|
|
|
$page_on_front = self::factory()->post->create( |
|
41
|
|
|
array( |
|
42
|
|
|
'post_type' => 'page', |
|
43
|
|
|
) |
|
44
|
|
|
); |
|
45
|
|
|
$page_for_posts = self::factory()->post->create( |
|
46
|
|
|
array( |
|
47
|
|
|
'post_type' => 'page', |
|
48
|
|
|
) |
|
49
|
|
|
); |
|
50
|
|
|
update_option('show_on_front', 'page'); |
|
51
|
|
|
update_option('page_on_front', $page_on_front); |
|
52
|
|
|
update_option('page_for_posts', $page_for_posts); |
|
53
|
|
|
|
|
54
|
|
|
$this->go_to('/'); |
|
55
|
|
|
$this->assertQueryTrue('is_front_page', 'is_page', 'is_singular'); |
|
56
|
|
|
|
|
57
|
|
|
$this->go_to(get_permalink($page_for_posts)); |
|
58
|
|
|
$this->assertQueryTrue('is_home', 'is_posts_page'); |
|
59
|
|
|
|
|
60
|
|
|
update_option('show_on_front', 'posts'); |
|
61
|
|
|
delete_option('page_on_front'); |
|
62
|
|
|
delete_option('page_for_posts'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
function test_404() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->go_to('/notapage'); |
|
68
|
|
|
$this->assertQueryTrue('is_404'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
function test_permalink() |
|
72
|
|
|
{ |
|
73
|
|
|
$post_id = self::factory()->post->create(array( 'post_title' => 'hello-world' )); |
|
74
|
|
|
$this->go_to(get_permalink($post_id)); |
|
75
|
|
|
$this->assertQueryTrue('is_single', 'is_singular'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
View Code Duplication |
function test_post_comments_feed() |
|
79
|
|
|
{ |
|
80
|
|
|
$post_id = self::factory()->post->create(array( 'post_title' => 'hello-world' )); |
|
81
|
|
|
self::factory()->comment->create_post_comments($post_id, 2); |
|
82
|
|
|
$this->go_to(get_post_comments_feed_link($post_id)); |
|
83
|
|
|
$this->assertQueryTrue('is_feed', 'is_single', 'is_singular', 'is_comment_feed'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
function test_post_comments_feed_with_no_comments() |
|
88
|
|
|
{ |
|
89
|
|
|
$post_id = self::factory()->post->create(array( 'post_title' => 'hello-world' )); |
|
90
|
|
|
$this->go_to(get_post_comments_feed_link($post_id)); |
|
91
|
|
|
$this->assertQueryTrue('is_feed', 'is_single', 'is_singular', 'is_comment_feed'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
View Code Duplication |
function test_attachment_comments_feed() |
|
95
|
|
|
{ |
|
96
|
|
|
$attachment_id = self::factory()->post->create(array( 'post_type' => 'attachment' )); |
|
97
|
|
|
self::factory()->comment->create_post_comments($attachment_id, 2); |
|
98
|
|
|
$this->go_to(get_post_comments_feed_link($attachment_id)); |
|
99
|
|
|
$this->assertQueryTrue('is_feed', 'is_attachment', 'is_single', 'is_singular', 'is_comment_feed'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
function test_page() |
|
103
|
|
|
{ |
|
104
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'about' )); |
|
105
|
|
|
$this->go_to(get_permalink($page_id)); |
|
106
|
|
|
$this->assertQueryTrue('is_page', 'is_singular'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
function test_parent_page() |
|
110
|
|
|
{ |
|
111
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'parent-page' )); |
|
112
|
|
|
$this->go_to(get_permalink($page_id)); |
|
113
|
|
|
|
|
114
|
|
|
$this->assertQueryTrue('is_page', 'is_singular'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
function test_child_page_1() |
|
118
|
|
|
{ |
|
119
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'parent-page' )); |
|
120
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id )); |
|
121
|
|
|
$this->go_to(get_permalink($page_id)); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertQueryTrue('is_page', 'is_singular'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
function test_child_page_2() |
|
127
|
|
|
{ |
|
128
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'parent-page' )); |
|
129
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id )); |
|
130
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id )); |
|
131
|
|
|
$this->go_to(get_permalink($page_id)); |
|
132
|
|
|
|
|
133
|
|
|
$this->assertQueryTrue('is_page', 'is_singular'); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
// '(about)/trackback/?$' => 'index.php?pagename=$matches[1]&tb=1' |
|
137
|
|
View Code Duplication |
function test_page_trackback() |
|
138
|
|
|
{ |
|
139
|
|
|
$page_ids = array(); |
|
140
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'parent-page' )); |
|
141
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id )); |
|
142
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id )); |
|
143
|
|
|
foreach ( $page_ids as $page_id ) { |
|
144
|
|
|
$url = get_permalink($page_id); |
|
145
|
|
|
$this->go_to("{$url}trackback/"); |
|
146
|
|
|
|
|
147
|
|
|
// make sure the correct wp_query flags are set |
|
148
|
|
|
$this->assertQueryTrue('is_page', 'is_singular', 'is_trackback'); |
|
149
|
|
|
|
|
150
|
|
|
// make sure the correct page was fetched |
|
151
|
|
|
global $wp_query; |
|
152
|
|
|
$this->assertEquals($page_id, $wp_query->get_queried_object()->ID); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
//'(about)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$matches[1]&feed=$matches[2]' |
|
157
|
|
View Code Duplication |
function test_page_feed() |
|
158
|
|
|
{ |
|
159
|
|
|
$page_ids = array(); |
|
160
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'parent-page' )); |
|
161
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id )); |
|
162
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id )); |
|
163
|
|
|
foreach ( $page_ids as $page_id ) { |
|
164
|
|
|
self::factory()->comment->create_post_comments($page_id, 2); |
|
165
|
|
|
$url = get_permalink($page_id); |
|
166
|
|
|
$this->go_to("{$url}feed/"); |
|
167
|
|
|
|
|
168
|
|
|
// make sure the correct wp_query flags are set |
|
169
|
|
|
$this->assertQueryTrue('is_page', 'is_singular', 'is_feed', 'is_comment_feed'); |
|
170
|
|
|
|
|
171
|
|
|
// make sure the correct page was fetched |
|
172
|
|
|
global $wp_query; |
|
173
|
|
|
$this->assertEquals($page_id, $wp_query->get_queried_object()->ID); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
View Code Duplication |
function test_page_feed_with_no_comments() |
|
178
|
|
|
{ |
|
179
|
|
|
$page_ids = array(); |
|
180
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'parent-page' )); |
|
181
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id )); |
|
182
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id )); |
|
183
|
|
|
foreach ( $page_ids as $page_id ) { |
|
184
|
|
|
$url = get_permalink($page_id); |
|
185
|
|
|
$this->go_to("{$url}feed/"); |
|
186
|
|
|
|
|
187
|
|
|
// make sure the correct wp_query flags are set |
|
188
|
|
|
$this->assertQueryTrue('is_page', 'is_singular', 'is_feed', 'is_comment_feed'); |
|
189
|
|
|
|
|
190
|
|
|
// make sure the correct page was fetched |
|
191
|
|
|
global $wp_query; |
|
192
|
|
|
$this->assertEquals($page_id, $wp_query->get_queried_object()->ID); |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
// '(about)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?pagename=$matches[1]&feed=$matches[2]' |
|
197
|
|
View Code Duplication |
function test_page_feed_atom() |
|
198
|
|
|
{ |
|
199
|
|
|
$page_ids = array(); |
|
200
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'parent-page' )); |
|
201
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $page_id )); |
|
202
|
|
|
$page_ids[] = $page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'child-page-2', 'post_parent' => $page_id )); |
|
203
|
|
|
foreach ( $page_ids as $page_id ) { |
|
204
|
|
|
self::factory()->comment->create_post_comments($page_id, 2); |
|
205
|
|
|
|
|
206
|
|
|
$url = get_permalink($page_id); |
|
207
|
|
|
$this->go_to("{$url}feed/atom/"); |
|
208
|
|
|
|
|
209
|
|
|
// make sure the correct wp_query flags are set |
|
210
|
|
|
$this->assertQueryTrue('is_page', 'is_singular', 'is_feed', 'is_comment_feed'); |
|
211
|
|
|
|
|
212
|
|
|
// make sure the correct page was fetched |
|
213
|
|
|
global $wp_query; |
|
214
|
|
|
$this->assertEquals($page_id, $wp_query->get_queried_object()->ID); |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
// '(about)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[2]' |
|
219
|
|
View Code Duplication |
function test_page_page_2() |
|
220
|
|
|
{ |
|
221
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'about', 'post_content' => 'Page 1 <!--nextpage--> Page 2' )); |
|
222
|
|
|
$this->go_to("/about/page/2/"); |
|
223
|
|
|
|
|
224
|
|
|
// make sure the correct wp_query flags are set |
|
225
|
|
|
$this->assertQueryTrue('is_page', 'is_singular', 'is_paged'); |
|
226
|
|
|
|
|
227
|
|
|
// make sure the correct page was fetched |
|
228
|
|
|
global $wp_query; |
|
229
|
|
|
$this->assertEquals($page_id, $wp_query->get_queried_object()->ID); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
// '(about)/page/?([0-9]{1,})/?$' => 'index.php?pagename=$matches[1]&paged=$matches[2]' |
|
233
|
|
View Code Duplication |
function test_page_page_2_no_slash() |
|
234
|
|
|
{ |
|
235
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'about', 'post_content' => 'Page 1 <!--nextpage--> Page 2' )); |
|
236
|
|
|
$this->go_to("/about/page2/"); |
|
237
|
|
|
|
|
238
|
|
|
// make sure the correct wp_query flags are set |
|
239
|
|
|
$this->assertQueryTrue('is_page', 'is_singular', 'is_paged'); |
|
240
|
|
|
|
|
241
|
|
|
// make sure the correct page was fetched |
|
242
|
|
|
global $wp_query; |
|
243
|
|
|
$this->assertEquals($page_id, $wp_query->get_queried_object()->ID); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
// '(about)(/[0-9]+)?/?$' => 'index.php?pagename=$matches[1]&page=$matches[2]' |
|
247
|
|
|
function test_pagination_of_posts_page() |
|
248
|
|
|
{ |
|
249
|
|
|
$page_id = self::factory()->post->create(array( 'post_type' => 'page', 'post_title' => 'about', 'post_content' => 'Page 1 <!--nextpage--> Page 2' )); |
|
250
|
|
|
update_option('show_on_front', 'page'); |
|
251
|
|
|
update_option('page_for_posts', $page_id); |
|
252
|
|
|
|
|
253
|
|
|
$this->go_to('/about/2/'); |
|
254
|
|
|
|
|
255
|
|
|
$this->assertQueryTrue('is_home', 'is_posts_page'); |
|
256
|
|
|
|
|
257
|
|
|
// make sure the correct page was fetched |
|
258
|
|
|
global $wp_query; |
|
259
|
|
|
$this->assertEquals($page_id, $wp_query->get_queried_object()->ID); |
|
260
|
|
|
|
|
261
|
|
|
update_option('show_on_front', 'posts'); |
|
262
|
|
|
delete_option('page_for_posts'); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
// FIXME: no tests for these yet |
|
266
|
|
|
// 'about/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', |
|
267
|
|
|
// 'about/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', |
|
268
|
|
|
// 'about/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', |
|
269
|
|
|
// 'about/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', |
|
270
|
|
|
|
|
271
|
|
|
// 'feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]', |
|
272
|
|
|
// '(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]', |
|
273
|
|
|
function test_main_feed_2() |
|
274
|
|
|
{ |
|
275
|
|
|
self::factory()->post->create(); // @test_404 |
|
276
|
|
|
$feeds = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
277
|
|
|
|
|
278
|
|
|
// long version |
|
279
|
|
|
foreach ($feeds as $feed) { |
|
|
|
|
|
|
280
|
|
|
$this->go_to("/feed/{$feed}/"); |
|
281
|
|
|
$this->assertQueryTrue('is_feed'); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
// short version |
|
285
|
|
|
foreach ($feeds as $feed) { |
|
|
|
|
|
|
286
|
|
|
$this->go_to("/{$feed}/"); |
|
287
|
|
|
$this->assertQueryTrue('is_feed'); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
function test_main_feed() |
|
293
|
|
|
{ |
|
294
|
|
|
self::factory()->post->create(); // @test_404 |
|
295
|
|
|
$types = array('rss2', 'rss', 'atom'); |
|
296
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
297
|
|
|
$this->go_to(get_feed_link($type)); |
|
298
|
|
|
$this->assertQueryTrue('is_feed'); |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
// 'page/?([0-9]{1,})/?$' => 'index.php?&paged=$matches[1]', |
|
303
|
|
View Code Duplication |
function test_paged() |
|
304
|
|
|
{ |
|
305
|
|
|
update_option('posts_per_page', 2); |
|
306
|
|
|
self::factory()->post->create_many(5); |
|
307
|
|
|
for ( $i = 2; $i <= 3; $i++ ) { |
|
308
|
|
|
$this->go_to("/page/{$i}/"); |
|
309
|
|
|
$this->assertQueryTrue('is_home', 'is_front_page', 'is_paged'); |
|
310
|
|
|
} |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
// 'comments/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]&withcomments=1', |
|
314
|
|
|
// 'comments/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?&feed=$matches[1]&withcomments=1', |
|
315
|
|
|
function test_main_comments_feed() |
|
316
|
|
|
{ |
|
317
|
|
|
$post_id = self::factory()->post->create(array( 'post_title' => 'hello-world' )); |
|
318
|
|
|
self::factory()->comment->create_post_comments($post_id, 2); |
|
319
|
|
|
|
|
320
|
|
|
// check the url as generated by get_post_comments_feed_link() |
|
321
|
|
|
$this->go_to(get_post_comments_feed_link($post_id)); |
|
322
|
|
|
$this->assertQueryTrue('is_feed', 'is_single', 'is_singular', 'is_comment_feed'); |
|
323
|
|
|
|
|
324
|
|
|
// check the long form |
|
325
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
326
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
327
|
|
|
$this->go_to("/comments/feed/{$type}"); |
|
328
|
|
|
$this->assertQueryTrue('is_feed', 'is_comment_feed'); |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
// check the short form |
|
332
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
333
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
334
|
|
|
$this->go_to("/comments/{$type}"); |
|
335
|
|
|
$this->assertQueryTrue('is_feed', 'is_comment_feed'); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
// 'search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?s=$matches[1]&feed=$matches[2]', |
|
341
|
|
|
// 'search/(.+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?s=$matches[1]&feed=$matches[2]', |
|
342
|
|
|
function test_search_feed() |
|
343
|
|
|
{ |
|
344
|
|
|
// check the long form |
|
345
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
346
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
347
|
|
|
$this->go_to("/search/test/feed/{$type}"); |
|
348
|
|
|
$this->assertQueryTrue('is_feed', 'is_search'); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
// check the short form |
|
352
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
353
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
354
|
|
|
$this->go_to("/search/test/{$type}"); |
|
355
|
|
|
$this->assertQueryTrue('is_feed', 'is_search'); |
|
356
|
|
|
} |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
// 'search/(.+)/page/?([0-9]{1,})/?$' => 'index.php?s=$matches[1]&paged=$matches[2]', |
|
360
|
|
View Code Duplication |
function test_search_paged() |
|
361
|
|
|
{ |
|
362
|
|
|
update_option('posts_per_page', 2); |
|
363
|
|
|
self::factory()->post->create_many(3, array( 'post_title' => 'test' )); |
|
364
|
|
|
$this->go_to('/search/test/page/2/'); |
|
365
|
|
|
$this->assertQueryTrue('is_search', 'is_paged'); |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
// 'search/(.+)/?$' => 'index.php?s=$matches[1]', |
|
369
|
|
|
function test_search() |
|
370
|
|
|
{ |
|
371
|
|
|
$this->go_to('/search/test/'); |
|
372
|
|
|
$this->assertQueryTrue('is_search'); |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* @ticket 13961 |
|
377
|
|
|
*/ |
|
378
|
|
|
function test_search_encoded_chars() |
|
379
|
|
|
{ |
|
380
|
|
|
$this->go_to('/search/F%C3%BCnf%2Bbar/'); |
|
381
|
|
|
$this->assertEquals(get_query_var('s'), 'Fünf+bar'); |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
// 'category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]', |
|
385
|
|
|
// 'category/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?category_name=$matches[1]&feed=$matches[2]', |
|
386
|
|
View Code Duplication |
function test_category_feed() |
|
387
|
|
|
{ |
|
388
|
|
|
self::factory()->term->create(array( 'name' => 'cat-a', 'taxonomy' => 'category' )); |
|
389
|
|
|
|
|
390
|
|
|
// check the long form |
|
391
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
392
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
393
|
|
|
$this->go_to("/category/cat-a/feed/{$type}"); |
|
394
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_category'); |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
// check the short form |
|
398
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
399
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
400
|
|
|
$this->go_to("/category/cat-a/{$type}"); |
|
401
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_category'); |
|
402
|
|
|
} |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
// 'category/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]', |
|
406
|
|
View Code Duplication |
function test_category_paged() |
|
407
|
|
|
{ |
|
408
|
|
|
update_option('posts_per_page', 2); |
|
409
|
|
|
self::factory()->post->create_many(3); |
|
410
|
|
|
$this->go_to('/category/uncategorized/page/2/'); |
|
411
|
|
|
$this->assertQueryTrue('is_archive', 'is_category', 'is_paged'); |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
// 'category/(.+?)/?$' => 'index.php?category_name=$matches[1]', |
|
415
|
|
|
function test_category() |
|
416
|
|
|
{ |
|
417
|
|
|
self::factory()->term->create(array( 'name' => 'cat-a', 'taxonomy' => 'category' )); |
|
418
|
|
|
$this->go_to('/category/cat-a/'); |
|
419
|
|
|
$this->assertQueryTrue('is_archive', 'is_category'); |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
// 'tag/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag=$matches[1]&feed=$matches[2]', |
|
423
|
|
|
// 'tag/(.+?)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag=$matches[1]&feed=$matches[2]', |
|
424
|
|
View Code Duplication |
function test_tag_feed() |
|
425
|
|
|
{ |
|
426
|
|
|
self::factory()->term->create(array( 'name' => 'tag-a', 'taxonomy' => 'post_tag' )); |
|
427
|
|
|
// check the long form |
|
428
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
429
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
430
|
|
|
$this->go_to("/tag/tag-a/feed/{$type}"); |
|
431
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_tag'); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
// check the short form |
|
435
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
436
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
437
|
|
|
$this->go_to("/tag/tag-a/{$type}"); |
|
438
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_tag'); |
|
439
|
|
|
} |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
// 'tag/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]', |
|
443
|
|
View Code Duplication |
function test_tag_paged() |
|
444
|
|
|
{ |
|
445
|
|
|
update_option('posts_per_page', 2); |
|
446
|
|
|
$post_ids = self::factory()->post->create_many(3); |
|
447
|
|
|
foreach ( $post_ids as $post_id ) { |
|
448
|
|
|
self::factory()->term->add_post_terms($post_id, 'tag-a', 'post_tag'); |
|
449
|
|
|
} |
|
450
|
|
|
$this->go_to('/tag/tag-a/page/2/'); |
|
451
|
|
|
$this->assertQueryTrue('is_archive', 'is_tag', 'is_paged'); |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
// 'tag/(.+?)/?$' => 'index.php?tag=$matches[1]', |
|
455
|
|
|
function test_tag() |
|
456
|
|
|
{ |
|
457
|
|
|
$term_id = self::factory()->term->create(array( 'name' => 'Tag Named A', 'slug' => 'tag-a', 'taxonomy' => 'post_tag' )); |
|
458
|
|
|
$this->go_to('/tag/tag-a/'); |
|
459
|
|
|
$this->assertQueryTrue('is_archive', 'is_tag'); |
|
460
|
|
|
|
|
461
|
|
|
$tag = get_term($term_id, 'post_tag'); |
|
462
|
|
|
|
|
463
|
|
|
$this->assertTrue(is_tag()); |
|
464
|
|
|
$this->assertTrue(is_tag($tag->name)); |
|
465
|
|
|
$this->assertTrue(is_tag($tag->slug)); |
|
466
|
|
|
$this->assertTrue(is_tag($tag->term_id)); |
|
467
|
|
|
$this->assertTrue(is_tag(array())); |
|
468
|
|
|
$this->assertTrue(is_tag(array( $tag->name ))); |
|
469
|
|
|
$this->assertTrue(is_tag(array( $tag->slug ))); |
|
470
|
|
|
$this->assertTrue(is_tag(array( $tag->term_id ))); |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
// 'author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]', |
|
474
|
|
|
// 'author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?author_name=$matches[1]&feed=$matches[2]', |
|
475
|
|
View Code Duplication |
function test_author_feed() |
|
476
|
|
|
{ |
|
477
|
|
|
self::factory()->user->create(array( 'user_login' => 'user-a' )); |
|
478
|
|
|
// check the long form |
|
479
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
480
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
481
|
|
|
$this->go_to("/author/user-a/feed/{$type}"); |
|
482
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_author'); |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
// check the short form |
|
486
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
487
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
488
|
|
|
$this->go_to("/author/user-a/{$type}"); |
|
489
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_author'); |
|
490
|
|
|
} |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
// 'author/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&paged=$matches[2]', |
|
494
|
|
|
function test_author_paged() |
|
495
|
|
|
{ |
|
496
|
|
|
update_option('posts_per_page', 2); |
|
497
|
|
|
$user_id = self::factory()->user->create(array( 'user_login' => 'user-a' )); |
|
498
|
|
|
self::factory()->post->create_many(3, array( 'post_author' => $user_id )); |
|
499
|
|
|
$this->go_to('/author/user-a/page/2/'); |
|
500
|
|
|
$this->assertQueryTrue('is_archive', 'is_author', 'is_paged'); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
// 'author/([^/]+)/?$' => 'index.php?author_name=$matches[1]', |
|
504
|
|
|
function test_author() |
|
505
|
|
|
{ |
|
506
|
|
|
$user_id = self::factory()->user->create(array( 'user_login' => 'user-a' )); |
|
507
|
|
|
self::factory()->post->create(array( 'post_author' => $user_id )); |
|
508
|
|
|
$this->go_to('/author/user-a/'); |
|
509
|
|
|
$this->assertQueryTrue('is_archive', 'is_author'); |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
function test_author_with_no_posts() |
|
513
|
|
|
{ |
|
514
|
|
|
$user_id = self::factory()->user->create(array( 'user_login' => 'user-a' )); |
|
515
|
|
|
$this->go_to('/author/user-a/'); |
|
516
|
|
|
$this->assertQueryTrue('is_archive', 'is_author'); |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
// '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]', |
|
520
|
|
|
// '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]', |
|
521
|
|
View Code Duplication |
function test_ymd_feed() |
|
522
|
|
|
{ |
|
523
|
|
|
self::factory()->post->create(array( 'post_date' => '2007-09-04 00:00:00' )); |
|
524
|
|
|
// check the long form |
|
525
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
526
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
527
|
|
|
$this->go_to("/2007/09/04/feed/{$type}"); |
|
528
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_day', 'is_date'); |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
// check the short form |
|
532
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
533
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
534
|
|
|
$this->go_to("/2007/09/04/{$type}"); |
|
535
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_day', 'is_date'); |
|
536
|
|
|
} |
|
537
|
|
|
} |
|
538
|
|
|
|
|
539
|
|
|
// '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]', |
|
540
|
|
View Code Duplication |
function test_ymd_paged() |
|
541
|
|
|
{ |
|
542
|
|
|
update_option('posts_per_page', 2); |
|
543
|
|
|
self::factory()->post->create_many(3, array( 'post_date' => '2007-09-04 00:00:00' )); |
|
544
|
|
|
$this->go_to('/2007/09/04/page/2/'); |
|
545
|
|
|
$this->assertQueryTrue('is_archive', 'is_day', 'is_date', 'is_paged'); |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
// '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]', |
|
549
|
|
|
function test_ymd() |
|
550
|
|
|
{ |
|
551
|
|
|
self::factory()->post->create(array( 'post_date' => '2007-09-04 00:00:00' )); |
|
552
|
|
|
$this->go_to('/2007/09/04/'); |
|
553
|
|
|
$this->assertQueryTrue('is_archive', 'is_day', 'is_date'); |
|
554
|
|
|
} |
|
555
|
|
|
|
|
556
|
|
|
// '([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]', |
|
557
|
|
|
// '([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]', |
|
558
|
|
View Code Duplication |
function test_ym_feed() |
|
559
|
|
|
{ |
|
560
|
|
|
self::factory()->post->create(array( 'post_date' => '2007-09-04 00:00:00' )); |
|
561
|
|
|
// check the long form |
|
562
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
563
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
564
|
|
|
$this->go_to("/2007/09/feed/{$type}"); |
|
565
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_month', 'is_date'); |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
// check the short form |
|
569
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
570
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
571
|
|
|
$this->go_to("/2007/09/{$type}"); |
|
572
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_month', 'is_date'); |
|
573
|
|
|
} |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
// '([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]', |
|
577
|
|
View Code Duplication |
function test_ym_paged() |
|
578
|
|
|
{ |
|
579
|
|
|
update_option('posts_per_page', 2); |
|
580
|
|
|
self::factory()->post->create_many(3, array( 'post_date' => '2007-09-04 00:00:00' )); |
|
581
|
|
|
$this->go_to('/2007/09/page/2/'); |
|
582
|
|
|
$this->assertQueryTrue('is_archive', 'is_date', 'is_month', 'is_paged'); |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
// '([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]', |
|
586
|
|
|
function test_ym() |
|
587
|
|
|
{ |
|
588
|
|
|
self::factory()->post->create(array( 'post_date' => '2007-09-04 00:00:00' )); |
|
589
|
|
|
$this->go_to('/2007/09/'); |
|
590
|
|
|
$this->assertQueryTrue('is_archive', 'is_date', 'is_month'); |
|
591
|
|
|
} |
|
592
|
|
|
|
|
593
|
|
|
// '([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&feed=$matches[2]', |
|
594
|
|
|
// '([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&feed=$matches[2]', |
|
595
|
|
View Code Duplication |
function test_y_feed() |
|
596
|
|
|
{ |
|
597
|
|
|
self::factory()->post->create(array( 'post_date' => '2007-09-04 00:00:00' )); |
|
598
|
|
|
// check the long form |
|
599
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
600
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
601
|
|
|
$this->go_to("/2007/feed/{$type}"); |
|
602
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_year', 'is_date'); |
|
603
|
|
|
} |
|
604
|
|
|
|
|
605
|
|
|
// check the short form |
|
606
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
607
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
608
|
|
|
$this->go_to("/2007/{$type}"); |
|
609
|
|
|
$this->assertQueryTrue('is_archive', 'is_feed', 'is_year', 'is_date'); |
|
610
|
|
|
} |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
|
|
// '([0-9]{4})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&paged=$matches[2]', |
|
614
|
|
View Code Duplication |
function test_y_paged() |
|
615
|
|
|
{ |
|
616
|
|
|
update_option('posts_per_page', 2); |
|
617
|
|
|
self::factory()->post->create_many(3, array( 'post_date' => '2007-09-04 00:00:00' )); |
|
618
|
|
|
$this->go_to('/2007/page/2/'); |
|
619
|
|
|
$this->assertQueryTrue('is_archive', 'is_date', 'is_year', 'is_paged'); |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
// '([0-9]{4})/?$' => 'index.php?year=$matches[1]', |
|
623
|
|
|
function test_y() |
|
624
|
|
|
{ |
|
625
|
|
|
self::factory()->post->create(array( 'post_date' => '2007-09-04 00:00:00' )); |
|
626
|
|
|
$this->go_to('/2007/'); |
|
627
|
|
|
$this->assertQueryTrue('is_archive', 'is_date', 'is_year'); |
|
628
|
|
|
} |
|
629
|
|
|
|
|
630
|
|
|
// '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/trackback/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&tb=1', |
|
631
|
|
|
function test_post_trackback() |
|
632
|
|
|
{ |
|
633
|
|
|
$post_id = self::factory()->post->create(); |
|
634
|
|
|
$permalink = get_permalink($post_id); |
|
635
|
|
|
$this->go_to("{$permalink}trackback/"); |
|
636
|
|
|
$this->assertQueryTrue('is_single', 'is_singular', 'is_trackback'); |
|
637
|
|
|
} |
|
638
|
|
|
|
|
639
|
|
|
// '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&feed=$matches[5]', |
|
640
|
|
|
// '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&feed=$matches[5]', |
|
641
|
|
|
function test_post_comment_feed() |
|
642
|
|
|
{ |
|
643
|
|
|
$post_id = self::factory()->post->create(); |
|
644
|
|
|
$permalink = get_permalink($post_id); |
|
645
|
|
|
|
|
646
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
647
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
648
|
|
|
$this->go_to("{$permalink}feed/{$type}"); |
|
649
|
|
|
$this->assertQueryTrue('is_single', 'is_singular', 'is_feed', 'is_comment_feed'); |
|
650
|
|
|
} |
|
651
|
|
|
|
|
652
|
|
|
// check the short form |
|
653
|
|
|
$types = array('feed', 'rdf', 'rss', 'rss2', 'atom'); |
|
654
|
|
|
foreach ($types as $type) { |
|
|
|
|
|
|
655
|
|
|
$this->go_to("{$permalink}{$type}"); |
|
656
|
|
|
$this->assertQueryTrue('is_single', 'is_singular', 'is_feed', 'is_comment_feed'); |
|
657
|
|
|
} |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
// '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&page=$matches[5]', |
|
661
|
|
|
function test_post_paged_short() |
|
662
|
|
|
{ |
|
663
|
|
|
$post_id = self::factory()->post->create( |
|
664
|
|
|
array( |
|
665
|
|
|
'post_date' => '2007-09-04 00:00:00', |
|
666
|
|
|
'post_title' => 'a-post-with-multiple-pages', |
|
667
|
|
|
'post_content' => 'Page 1 <!--nextpage--> Page 2' |
|
668
|
|
|
) |
|
669
|
|
|
); |
|
670
|
|
|
$this->go_to(get_permalink($post_id) . '2/'); |
|
671
|
|
|
// should is_paged be true also? |
|
672
|
|
|
$this->assertQueryTrue('is_single', 'is_singular'); |
|
673
|
|
|
|
|
674
|
|
|
} |
|
675
|
|
|
|
|
676
|
|
|
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]', |
|
677
|
|
|
function test_post_attachment() |
|
678
|
|
|
{ |
|
679
|
|
|
$post_id = self::factory()->post->create(array( 'post_type' => 'attachment' )); |
|
680
|
|
|
$permalink = get_attachment_link($post_id); |
|
681
|
|
|
$this->go_to($permalink); |
|
682
|
|
|
$this->assertQueryTrue('is_single', 'is_attachment', 'is_singular'); |
|
683
|
|
|
} |
|
684
|
|
|
|
|
685
|
|
|
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', |
|
686
|
|
|
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', |
|
687
|
|
|
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', |
|
688
|
|
|
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', |
|
689
|
|
|
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', |
|
690
|
|
|
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', |
|
691
|
|
|
// '[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', |
|
692
|
|
|
|
|
693
|
|
|
/** |
|
694
|
|
|
* @expectedIncorrectUsage WP_Date_Query |
|
695
|
|
|
*/ |
|
696
|
|
|
function test_bad_dates() |
|
697
|
|
|
{ |
|
698
|
|
|
$this->go_to('/2013/13/13/'); |
|
699
|
|
|
$this->assertQueryTrue('is_404'); |
|
700
|
|
|
|
|
701
|
|
|
$this->go_to('/2013/11/41/'); |
|
702
|
|
|
$this->assertQueryTrue('is_404'); |
|
703
|
|
|
} |
|
704
|
|
|
|
|
705
|
|
|
function test_post_type_archive_with_tax_query() |
|
706
|
|
|
{ |
|
707
|
|
|
delete_option('rewrite_rules'); |
|
708
|
|
|
|
|
709
|
|
|
$cpt_name = 'ptawtq'; |
|
710
|
|
|
register_post_type( |
|
711
|
|
|
$cpt_name, array( |
|
712
|
|
|
'taxonomies' => array( 'post_tag', 'category' ), |
|
713
|
|
|
'rewrite' => true, |
|
714
|
|
|
'has_archive' => true, |
|
715
|
|
|
'public' => true |
|
716
|
|
|
) |
|
717
|
|
|
); |
|
718
|
|
|
|
|
719
|
|
|
$tag_id = self::factory()->tag->create(array( 'slug' => 'tag-slug' )); |
|
720
|
|
|
$post_id = self::factory()->post->create(array( 'post_type' => $cpt_name )); |
|
721
|
|
|
wp_set_object_terms($post_id, $tag_id, 'post_tag'); |
|
722
|
|
|
|
|
723
|
|
|
$this->go_to('/ptawtq/'); |
|
724
|
|
|
$this->assertQueryTrue('is_post_type_archive', 'is_archive'); |
|
725
|
|
|
$this->assertEquals(get_queried_object(), get_post_type_object($cpt_name)); |
|
726
|
|
|
|
|
727
|
|
|
add_action('pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' )); |
|
728
|
|
|
|
|
729
|
|
|
$this->go_to('/ptawtq/'); |
|
730
|
|
|
$this->assertQueryTrue('is_post_type_archive', 'is_archive'); |
|
731
|
|
|
$this->assertEquals(get_queried_object(), get_post_type_object($cpt_name)); |
|
732
|
|
|
|
|
733
|
|
|
remove_action('pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' )); |
|
734
|
|
|
} |
|
735
|
|
|
|
|
736
|
|
|
function pre_get_posts_with_tax_query( &$query ) |
|
737
|
|
|
{ |
|
738
|
|
|
$term = get_term_by('slug', 'tag-slug', 'post_tag'); |
|
739
|
|
|
$query->set( |
|
740
|
|
|
'tax_query', array( |
|
741
|
|
|
array( 'taxonomy' => 'post_tag', 'field' => 'term_id', 'terms' => $term->term_id ) |
|
742
|
|
|
) |
|
743
|
|
|
); |
|
744
|
|
|
} |
|
745
|
|
|
|
|
746
|
|
|
function test_post_type_array() |
|
747
|
|
|
{ |
|
748
|
|
|
delete_option('rewrite_rules'); |
|
749
|
|
|
|
|
750
|
|
|
$cpt_name = 'thearray'; |
|
751
|
|
|
register_post_type( |
|
752
|
|
|
$cpt_name, array( |
|
753
|
|
|
'taxonomies' => array( 'post_tag', 'category' ), |
|
754
|
|
|
'rewrite' => true, |
|
755
|
|
|
'has_archive' => true, |
|
756
|
|
|
'public' => true |
|
757
|
|
|
) |
|
758
|
|
|
); |
|
759
|
|
|
self::factory()->post->create(array( 'post_type' => $cpt_name )); |
|
760
|
|
|
|
|
761
|
|
|
$this->go_to("/$cpt_name/"); |
|
762
|
|
|
$this->assertQueryTrue('is_post_type_archive', 'is_archive'); |
|
763
|
|
|
$this->assertEquals(get_queried_object(), get_post_type_object($cpt_name)); |
|
764
|
|
|
|
|
765
|
|
|
add_action('pre_get_posts', array( $this, 'pre_get_posts_with_type_array' )); |
|
766
|
|
|
|
|
767
|
|
|
$this->go_to("/$cpt_name/"); |
|
768
|
|
|
$this->assertQueryTrue('is_post_type_archive', 'is_archive'); |
|
769
|
|
|
$this->assertEquals(get_queried_object(), get_post_type_object('post')); |
|
770
|
|
|
|
|
771
|
|
|
remove_action('pre_get_posts', array( $this, 'pre_get_posts_with_type_array' )); |
|
772
|
|
|
} |
|
773
|
|
|
|
|
774
|
|
|
function pre_get_posts_with_type_array( &$query ) |
|
775
|
|
|
{ |
|
776
|
|
|
$query->set('post_type', array( 'post', 'thearray' )); |
|
777
|
|
|
} |
|
778
|
|
|
|
|
779
|
|
|
function test_is_single() |
|
780
|
|
|
{ |
|
781
|
|
|
$post_id = self::factory()->post->create(); |
|
782
|
|
|
$this->go_to("/?p=$post_id"); |
|
783
|
|
|
|
|
784
|
|
|
$post = get_queried_object(); |
|
785
|
|
|
$q = $GLOBALS['wp_query']; |
|
786
|
|
|
|
|
787
|
|
|
$this->assertTrue(is_single()); |
|
788
|
|
|
$this->assertTrue($q->is_single); |
|
789
|
|
|
$this->assertFalse($q->is_page); |
|
790
|
|
|
$this->assertFalse($q->is_attachment); |
|
791
|
|
|
$this->assertTrue(is_single($post)); |
|
792
|
|
|
$this->assertTrue(is_single($post->ID)); |
|
793
|
|
|
$this->assertTrue(is_single($post->post_title)); |
|
794
|
|
|
$this->assertTrue(is_single($post->post_name)); |
|
795
|
|
|
} |
|
796
|
|
|
|
|
797
|
|
|
/** |
|
798
|
|
|
* @ticket 16802 |
|
799
|
|
|
*/ |
|
800
|
|
|
function test_is_single_with_parent() |
|
801
|
|
|
{ |
|
802
|
|
|
// Use custom hierarchical post type |
|
803
|
|
|
$post_type = 'test_hierarchical'; |
|
804
|
|
|
|
|
805
|
|
|
register_post_type( |
|
806
|
|
|
$post_type, array( |
|
807
|
|
|
'hierarchical' => true, |
|
808
|
|
|
'rewrite' => true, |
|
809
|
|
|
'has_archive' => true, |
|
810
|
|
|
'public' => true |
|
811
|
|
|
) |
|
812
|
|
|
); |
|
813
|
|
|
|
|
814
|
|
|
// Create parent and child posts |
|
815
|
|
|
$parent_id = self::factory()->post->create( |
|
816
|
|
|
array( |
|
817
|
|
|
'post_type' => $post_type, |
|
818
|
|
|
'post_name' => 'foo' |
|
819
|
|
|
) |
|
820
|
|
|
); |
|
821
|
|
|
|
|
822
|
|
|
$post_id = self::factory()->post->create( |
|
823
|
|
|
array( |
|
824
|
|
|
'post_type' => $post_type, |
|
825
|
|
|
'post_name' => 'bar', |
|
826
|
|
|
'post_parent' => $parent_id |
|
827
|
|
|
) |
|
828
|
|
|
); |
|
829
|
|
|
|
|
830
|
|
|
// Tests |
|
831
|
|
|
$this->go_to("/?p=$post_id&post_type=$post_type"); |
|
832
|
|
|
|
|
833
|
|
|
$post = get_queried_object(); |
|
834
|
|
|
$q = $GLOBALS['wp_query']; |
|
835
|
|
|
|
|
836
|
|
|
$this->assertTrue(is_single()); |
|
837
|
|
|
$this->assertFalse($q->is_page); |
|
838
|
|
|
$this->assertTrue($q->is_single); |
|
839
|
|
|
$this->assertFalse($q->is_attachment); |
|
840
|
|
|
$this->assertTrue(is_single($post)); |
|
841
|
|
|
$this->assertTrue(is_single($post->ID)); |
|
842
|
|
|
$this->assertTrue(is_single($post->post_title)); |
|
843
|
|
|
$this->assertTrue(is_single($post->post_name)); |
|
844
|
|
|
$this->assertTrue(is_single('foo/bar')); |
|
845
|
|
|
$this->assertFalse(is_single($parent_id)); |
|
846
|
|
|
$this->assertFalse(is_single('foo/bar/baz')); |
|
847
|
|
|
$this->assertFalse(is_single('bar/bar')); |
|
848
|
|
|
$this->assertFalse(is_single('foo')); |
|
849
|
|
|
} |
|
850
|
|
|
|
|
851
|
|
|
/** |
|
852
|
|
|
* @ticket 24674 |
|
853
|
|
|
*/ |
|
854
|
|
View Code Duplication |
public function test_is_single_with_slug_that_begins_with_a_number_that_clashes_with_another_post_id() |
|
855
|
|
|
{ |
|
856
|
|
|
$p1 = self::factory()->post->create(); |
|
857
|
|
|
|
|
858
|
|
|
$p2_name = $p1 . '-post'; |
|
859
|
|
|
$p2 = self::factory()->post->create( |
|
860
|
|
|
array( |
|
861
|
|
|
'slug' => $p2_name, |
|
862
|
|
|
) |
|
863
|
|
|
); |
|
864
|
|
|
|
|
865
|
|
|
$this->go_to("/?p=$p1"); |
|
866
|
|
|
|
|
867
|
|
|
$q = $GLOBALS['wp_query']; |
|
868
|
|
|
|
|
869
|
|
|
$this->assertTrue($q->is_single()); |
|
870
|
|
|
$this->assertTrue($q->is_single($p1)); |
|
871
|
|
|
$this->assertFalse($q->is_single($p2_name)); |
|
872
|
|
|
$this->assertFalse($q->is_single($p2)); |
|
873
|
|
|
} |
|
874
|
|
|
|
|
875
|
|
|
/** |
|
876
|
|
|
* @ticket 24612 |
|
877
|
|
|
*/ |
|
878
|
|
|
public function test_is_single_with_slug_that_clashes_with_attachment() |
|
879
|
|
|
{ |
|
880
|
|
|
$this->set_permalink_structure('/%postname%/'); |
|
881
|
|
|
|
|
882
|
|
|
$attachment_id = $this->factory->post->create( |
|
883
|
|
|
array( |
|
884
|
|
|
'post_type' => 'attachment', |
|
885
|
|
|
) |
|
886
|
|
|
); |
|
887
|
|
|
|
|
888
|
|
|
$post_id = $this->factory->post->create( |
|
889
|
|
|
array( |
|
890
|
|
|
'post_title' => get_post($attachment_id)->post_title |
|
891
|
|
|
) |
|
892
|
|
|
); |
|
893
|
|
|
|
|
894
|
|
|
$this->go_to(get_permalink($post_id)); |
|
895
|
|
|
|
|
896
|
|
|
$q = $GLOBALS['wp_query']; |
|
897
|
|
|
|
|
898
|
|
|
$this->assertTrue($q->is_single()); |
|
899
|
|
|
$this->assertTrue($q->is_single($post_id)); |
|
900
|
|
|
$this->assertFalse($q->is_attachment()); |
|
901
|
|
|
$this->assertFalse($q->is_404()); |
|
902
|
|
|
|
|
903
|
|
|
$this->set_permalink_structure(); |
|
904
|
|
|
} |
|
905
|
|
|
|
|
906
|
|
|
/** |
|
907
|
|
|
* @ticket 38225 |
|
908
|
|
|
*/ |
|
909
|
|
|
function test_is_single_with_attachment() |
|
910
|
|
|
{ |
|
911
|
|
|
$post_id = self::factory()->post->create(); |
|
912
|
|
|
|
|
913
|
|
|
$attachment_id = self::factory()->attachment->create_object( |
|
914
|
|
|
'image.jpg', $post_id, array( |
|
|
|
|
|
|
915
|
|
|
'post_mime_type' => 'image/jpeg', |
|
916
|
|
|
) |
|
917
|
|
|
); |
|
918
|
|
|
|
|
919
|
|
|
$this->go_to(get_permalink($attachment_id)); |
|
920
|
|
|
|
|
921
|
|
|
$q = $GLOBALS['wp_query']; |
|
922
|
|
|
|
|
923
|
|
|
$this->assertTrue(is_single()); |
|
924
|
|
|
$this->assertTrue($q->is_single); |
|
925
|
|
|
$this->assertTrue($q->is_attachment); |
|
926
|
|
|
} |
|
927
|
|
|
|
|
928
|
|
View Code Duplication |
function test_is_page() |
|
929
|
|
|
{ |
|
930
|
|
|
$post_id = self::factory()->post->create(array( 'post_type' => 'page' )); |
|
931
|
|
|
$this->go_to("/?page_id=$post_id"); |
|
932
|
|
|
|
|
933
|
|
|
$post = get_queried_object(); |
|
934
|
|
|
$q = $GLOBALS['wp_query']; |
|
935
|
|
|
|
|
936
|
|
|
$this->assertTrue(is_page()); |
|
937
|
|
|
$this->assertFalse($q->is_single); |
|
938
|
|
|
$this->assertTrue($q->is_page); |
|
939
|
|
|
$this->assertFalse($q->is_attachment); |
|
940
|
|
|
$this->assertTrue(is_page($post)); |
|
941
|
|
|
$this->assertTrue(is_page($post->ID)); |
|
942
|
|
|
$this->assertTrue(is_page($post->post_title)); |
|
943
|
|
|
$this->assertTrue(is_page($post->post_name)); |
|
944
|
|
|
} |
|
945
|
|
|
|
|
946
|
|
|
/** |
|
947
|
|
|
* @ticket 16802 |
|
948
|
|
|
*/ |
|
949
|
|
|
function test_is_page_with_parent() |
|
950
|
|
|
{ |
|
951
|
|
|
$parent_id = self::factory()->post->create( |
|
952
|
|
|
array( |
|
953
|
|
|
'post_type' => 'page', |
|
954
|
|
|
'post_name' => 'foo', |
|
955
|
|
|
) |
|
956
|
|
|
); |
|
957
|
|
|
$post_id = self::factory()->post->create( |
|
958
|
|
|
array( |
|
959
|
|
|
'post_type' => 'page', |
|
960
|
|
|
'post_name' => 'bar', |
|
961
|
|
|
'post_parent' => $parent_id, |
|
962
|
|
|
) |
|
963
|
|
|
); |
|
964
|
|
|
$this->go_to("/?page_id=$post_id"); |
|
965
|
|
|
|
|
966
|
|
|
$post = get_queried_object(); |
|
967
|
|
|
$q = $GLOBALS['wp_query']; |
|
968
|
|
|
|
|
969
|
|
|
$this->assertTrue(is_page()); |
|
970
|
|
|
$this->assertFalse($q->is_single); |
|
971
|
|
|
$this->assertTrue($q->is_page); |
|
972
|
|
|
$this->assertFalse($q->is_attachment); |
|
973
|
|
|
$this->assertTrue(is_page($post)); |
|
974
|
|
|
$this->assertTrue(is_page($post->ID)); |
|
975
|
|
|
$this->assertTrue(is_page($post->post_title)); |
|
976
|
|
|
$this->assertTrue(is_page($post->post_name)); |
|
977
|
|
|
$this->assertTrue(is_page('foo/bar')); |
|
978
|
|
|
$this->assertFalse(is_page($parent_id)); |
|
979
|
|
|
$this->assertFalse(is_page('foo/bar/baz')); |
|
980
|
|
|
$this->assertFalse(is_page('bar/bar')); |
|
981
|
|
|
$this->assertFalse(is_page('foo')); |
|
982
|
|
|
} |
|
983
|
|
|
|
|
984
|
|
View Code Duplication |
function test_is_attachment() |
|
985
|
|
|
{ |
|
986
|
|
|
$post_id = self::factory()->post->create(array( 'post_type' => 'attachment' )); |
|
987
|
|
|
$this->go_to("/?attachment_id=$post_id"); |
|
988
|
|
|
|
|
989
|
|
|
$post = get_queried_object(); |
|
990
|
|
|
$q = $GLOBALS['wp_query']; |
|
991
|
|
|
|
|
992
|
|
|
$this->assertTrue(is_attachment()); |
|
993
|
|
|
$this->assertTrue(is_single()); |
|
994
|
|
|
$this->assertTrue($q->is_attachment); |
|
995
|
|
|
$this->assertTrue($q->is_single); |
|
996
|
|
|
$this->assertFalse($q->is_page); |
|
997
|
|
|
$this->assertTrue(is_attachment($post)); |
|
998
|
|
|
$this->assertTrue(is_attachment($post->ID)); |
|
999
|
|
|
$this->assertTrue(is_attachment($post->post_title)); |
|
1000
|
|
|
$this->assertTrue(is_attachment($post->post_name)); |
|
1001
|
|
|
} |
|
1002
|
|
|
|
|
1003
|
|
|
/** |
|
1004
|
|
|
* @ticket 24674 |
|
1005
|
|
|
*/ |
|
1006
|
|
View Code Duplication |
public function test_is_attachment_with_slug_that_begins_with_a_number_that_clashes_with_a_page_ID() |
|
|
|
|
|
|
1007
|
|
|
{ |
|
1008
|
|
|
$p1 = self::factory()->post->create(array( 'post_type' => 'attachment' )); |
|
1009
|
|
|
|
|
1010
|
|
|
$p2_name = $p1 . '-attachment'; |
|
1011
|
|
|
$p2 = self::factory()->post->create( |
|
1012
|
|
|
array( |
|
1013
|
|
|
'post_type' => 'attachment', |
|
1014
|
|
|
'post_name' => $p2_name, |
|
1015
|
|
|
) |
|
1016
|
|
|
); |
|
1017
|
|
|
|
|
1018
|
|
|
$this->go_to("/?attachment_id=$p1"); |
|
1019
|
|
|
|
|
1020
|
|
|
$q = $GLOBALS['wp_query']; |
|
1021
|
|
|
|
|
1022
|
|
|
$this->assertTrue($q->is_attachment()); |
|
1023
|
|
|
$this->assertTrue($q->is_attachment($p1)); |
|
1024
|
|
|
$this->assertFalse($q->is_attachment($p2_name)); |
|
1025
|
|
|
$this->assertFalse($q->is_attachment($p2)); |
|
1026
|
|
|
} |
|
1027
|
|
|
|
|
1028
|
|
|
/** |
|
1029
|
|
|
* @ticket 24674 |
|
1030
|
|
|
*/ |
|
1031
|
|
View Code Duplication |
public function test_is_author_with_nicename_that_begins_with_a_number_that_clashes_with_another_author_id() |
|
1032
|
|
|
{ |
|
1033
|
|
|
$u1 = self::factory()->user->create(); |
|
1034
|
|
|
|
|
1035
|
|
|
$u2_name = $u1 . '_user'; |
|
1036
|
|
|
$u2 = self::factory()->user->create( |
|
1037
|
|
|
array( |
|
1038
|
|
|
'user_nicename' => $u2_name, |
|
1039
|
|
|
) |
|
1040
|
|
|
); |
|
1041
|
|
|
|
|
1042
|
|
|
$this->go_to("/?author=$u1"); |
|
1043
|
|
|
|
|
1044
|
|
|
$q = $GLOBALS['wp_query']; |
|
1045
|
|
|
|
|
1046
|
|
|
$this->assertTrue($q->is_author()); |
|
1047
|
|
|
$this->assertTrue($q->is_author($u1)); |
|
1048
|
|
|
$this->assertFalse($q->is_author($u2_name)); |
|
1049
|
|
|
$this->assertFalse($q->is_author($u2)); |
|
1050
|
|
|
} |
|
1051
|
|
|
|
|
1052
|
|
|
/** |
|
1053
|
|
|
* @ticket 24674 |
|
1054
|
|
|
*/ |
|
1055
|
|
View Code Duplication |
public function test_is_category_with_slug_that_begins_with_a_number_that_clashes_with_another_category_id() |
|
1056
|
|
|
{ |
|
1057
|
|
|
$c1 = self::factory()->category->create(); |
|
1058
|
|
|
|
|
1059
|
|
|
$c2_name = $c1 . '-category'; |
|
1060
|
|
|
$c2 = self::factory()->category->create( |
|
1061
|
|
|
array( |
|
1062
|
|
|
'slug' => $c2_name, |
|
1063
|
|
|
) |
|
1064
|
|
|
); |
|
1065
|
|
|
|
|
1066
|
|
|
$this->go_to("/?cat=$c1"); |
|
1067
|
|
|
|
|
1068
|
|
|
$q = $GLOBALS['wp_query']; |
|
1069
|
|
|
|
|
1070
|
|
|
$this->assertTrue($q->is_category()); |
|
1071
|
|
|
$this->assertTrue($q->is_category($c1)); |
|
1072
|
|
|
$this->assertFalse($q->is_category($c2_name)); |
|
1073
|
|
|
$this->assertFalse($q->is_category($c2)); |
|
1074
|
|
|
} |
|
1075
|
|
|
|
|
1076
|
|
|
/** |
|
1077
|
|
|
* @ticket 24674 |
|
1078
|
|
|
*/ |
|
1079
|
|
View Code Duplication |
public function test_is_tag_with_slug_that_begins_with_a_number_that_clashes_with_another_tag_id() |
|
1080
|
|
|
{ |
|
1081
|
|
|
$t1 = self::factory()->tag->create(); |
|
1082
|
|
|
|
|
1083
|
|
|
$t2_name = $t1 . '-tag'; |
|
1084
|
|
|
$t2 = self::factory()->tag->create( |
|
1085
|
|
|
array( |
|
1086
|
|
|
'slug' => $t2_name, |
|
1087
|
|
|
) |
|
1088
|
|
|
); |
|
1089
|
|
|
|
|
1090
|
|
|
$this->go_to("/?tag_id=$t1"); |
|
1091
|
|
|
|
|
1092
|
|
|
$q = $GLOBALS['wp_query']; |
|
1093
|
|
|
|
|
1094
|
|
|
$this->assertTrue($q->is_tag()); |
|
1095
|
|
|
$this->assertTrue($q->is_tag($t1)); |
|
1096
|
|
|
$this->assertFalse($q->is_tag($t2_name)); |
|
1097
|
|
|
$this->assertFalse($q->is_tag($t2)); |
|
1098
|
|
|
} |
|
1099
|
|
|
|
|
1100
|
|
|
/** |
|
1101
|
|
|
* @ticket 24674 |
|
1102
|
|
|
*/ |
|
1103
|
|
|
public function test_is_page_with_page_id_zero_and_random_page_slug() |
|
1104
|
|
|
{ |
|
1105
|
|
|
$post_id = self::factory()->post->create(array( 'post_type' => 'page' )); |
|
1106
|
|
|
$this->go_to("/?page_id=$post_id"); |
|
1107
|
|
|
|
|
1108
|
|
|
// override post ID to 0 temporarily for testing |
|
1109
|
|
|
$_id = $GLOBALS['wp_query']->post->ID; |
|
1110
|
|
|
$GLOBALS['wp_query']->post->ID = 0; |
|
1111
|
|
|
|
|
1112
|
|
|
$post = get_queried_object(); |
|
1113
|
|
|
$q = $GLOBALS['wp_query']; |
|
1114
|
|
|
|
|
1115
|
|
|
$this->assertTrue($q->is_page()); |
|
1116
|
|
|
$this->assertFalse($q->is_page('sample-page')); |
|
1117
|
|
|
$this->assertFalse($q->is_page('random-page-slug')); |
|
1118
|
|
|
|
|
1119
|
|
|
// revert $wp_query global change |
|
1120
|
|
|
$GLOBALS['wp_query']->post->ID = $_id; |
|
1121
|
|
|
} |
|
1122
|
|
|
|
|
1123
|
|
|
/** |
|
1124
|
|
|
* @ticket 24674 |
|
1125
|
|
|
*/ |
|
1126
|
|
View Code Duplication |
public function test_is_page_with_page_slug_that_begins_with_a_number_that_clashes_with_a_page_ID() |
|
|
|
|
|
|
1127
|
|
|
{ |
|
1128
|
|
|
$p1 = self::factory()->post->create(array( 'post_type' => 'page' )); |
|
1129
|
|
|
|
|
1130
|
|
|
$p2_name = $p1 . '-page'; |
|
1131
|
|
|
$p2 = self::factory()->post->create( |
|
1132
|
|
|
array( |
|
1133
|
|
|
'post_type' => 'page', |
|
1134
|
|
|
'post_name' => $p2_name, |
|
1135
|
|
|
) |
|
1136
|
|
|
); |
|
1137
|
|
|
|
|
1138
|
|
|
$this->go_to("/?page_id=$p1"); |
|
1139
|
|
|
|
|
1140
|
|
|
$q = $GLOBALS['wp_query']; |
|
1141
|
|
|
|
|
1142
|
|
|
$this->assertTrue($q->is_page()); |
|
1143
|
|
|
$this->assertTrue($q->is_page($p1)); |
|
1144
|
|
|
$this->assertFalse($q->is_page($p2_name)); |
|
1145
|
|
|
$this->assertFalse($q->is_page($p2)); |
|
1146
|
|
|
} |
|
1147
|
|
|
|
|
1148
|
|
|
function test_is_page_template() |
|
1149
|
|
|
{ |
|
1150
|
|
|
$post_id = self::factory()->post->create(array( 'post_type' => 'page' )); |
|
1151
|
|
|
update_post_meta($post_id, '_wp_page_template', 'example.php'); |
|
1152
|
|
|
$this->go_to("/?page_id=$post_id"); |
|
1153
|
|
|
$this->assertTrue(is_page_template('example.php')); |
|
1154
|
|
|
} |
|
1155
|
|
|
|
|
1156
|
|
|
/** |
|
1157
|
|
|
* @ticket 31271 |
|
1158
|
|
|
*/ |
|
1159
|
|
|
function test_is_page_template_default() |
|
1160
|
|
|
{ |
|
1161
|
|
|
$post_id = self::factory()->post->create(array( 'post_type' => 'page' )); |
|
1162
|
|
|
$this->go_to("/?page_id=$post_id"); |
|
1163
|
|
|
$this->assertTrue(is_page_template('default')); |
|
1164
|
|
|
$this->assertTrue(is_page_template(array( 'random', 'default' ))); |
|
1165
|
|
|
} |
|
1166
|
|
|
|
|
1167
|
|
|
/** |
|
1168
|
|
|
* @ticket 31271 |
|
1169
|
|
|
*/ |
|
1170
|
|
View Code Duplication |
function test_is_page_template_array() |
|
1171
|
|
|
{ |
|
1172
|
|
|
$post_id = self::factory()->post->create(array( 'post_type' => 'page' )); |
|
1173
|
|
|
update_post_meta($post_id, '_wp_page_template', 'example.php'); |
|
1174
|
|
|
$this->go_to("/?page_id=$post_id"); |
|
1175
|
|
|
$this->assertFalse(is_page_template(array( 'test.php' ))); |
|
1176
|
|
|
$this->assertTrue(is_page_template(array('test.php', 'example.php'))); |
|
1177
|
|
|
} |
|
1178
|
|
|
|
|
1179
|
|
|
/** |
|
1180
|
|
|
* @ticket 18375 |
|
1181
|
|
|
*/ |
|
1182
|
|
View Code Duplication |
function test_is_page_template_other_post_type() |
|
1183
|
|
|
{ |
|
1184
|
|
|
$post_id = self::factory()->post->create(array( 'post_type' => 'post' )); |
|
1185
|
|
|
update_post_meta($post_id, '_wp_page_template', 'example.php'); |
|
1186
|
|
|
$this->go_to(get_post_permalink($post_id)); |
|
1187
|
|
|
$this->assertFalse(is_page_template(array( 'test.php' ))); |
|
1188
|
|
|
$this->assertTrue(is_page_template(array( 'test.php', 'example.php' ))); |
|
1189
|
|
|
} |
|
1190
|
|
|
|
|
1191
|
|
|
/** |
|
1192
|
|
|
* @ticket 35902 |
|
1193
|
|
|
*/ |
|
1194
|
|
View Code Duplication |
public function test_is_attachment_should_not_match_numeric_id_to_post_title_beginning_with_id() |
|
1195
|
|
|
{ |
|
1196
|
|
|
$p1 = self::factory()->post->create( |
|
1197
|
|
|
array( |
|
1198
|
|
|
'post_type' => 'attachment', |
|
1199
|
|
|
'post_title' => 'Foo', |
|
1200
|
|
|
'post_name' => 'foo', |
|
1201
|
|
|
) |
|
1202
|
|
|
); |
|
1203
|
|
|
$p2 = self::factory()->post->create( |
|
1204
|
|
|
array( |
|
1205
|
|
|
'post_type' => 'attachment', |
|
1206
|
|
|
'post_title' => "$p1 Foo", |
|
1207
|
|
|
'post_name' => 'foo-2', |
|
1208
|
|
|
) |
|
1209
|
|
|
); |
|
1210
|
|
|
|
|
1211
|
|
|
$this->go_to(get_permalink($p2)); |
|
1212
|
|
|
|
|
1213
|
|
|
$this->assertTrue(is_attachment($p2)); |
|
1214
|
|
|
$this->assertFalse(is_attachment($p1)); |
|
1215
|
|
|
} |
|
1216
|
|
|
|
|
1217
|
|
|
/** |
|
1218
|
|
|
* @ticket 35902 |
|
1219
|
|
|
*/ |
|
1220
|
|
View Code Duplication |
public function test_is_attachment_should_not_match_numeric_id_to_post_name_beginning_with_id() |
|
1221
|
|
|
{ |
|
1222
|
|
|
$p1 = self::factory()->post->create( |
|
1223
|
|
|
array( |
|
1224
|
|
|
'post_type' => 'attachment', |
|
1225
|
|
|
'post_title' => 'Foo', |
|
1226
|
|
|
'post_name' => 'foo', |
|
1227
|
|
|
) |
|
1228
|
|
|
); |
|
1229
|
|
|
$p2 = self::factory()->post->create( |
|
1230
|
|
|
array( |
|
1231
|
|
|
'post_type' => 'attachment', |
|
1232
|
|
|
'post_title' => 'Foo', |
|
1233
|
|
|
'post_name' => "$p1-foo", |
|
1234
|
|
|
) |
|
1235
|
|
|
); |
|
1236
|
|
|
|
|
1237
|
|
|
$this->go_to(get_permalink($p2)); |
|
1238
|
|
|
|
|
1239
|
|
|
$this->assertTrue(is_attachment($p2)); |
|
1240
|
|
|
$this->assertFalse(is_attachment($p1)); |
|
1241
|
|
|
} |
|
1242
|
|
|
|
|
1243
|
|
|
/** |
|
1244
|
|
|
* @ticket 35902 |
|
1245
|
|
|
*/ |
|
1246
|
|
View Code Duplication |
public function test_is_author_should_not_match_numeric_id_to_nickname_beginning_with_id() |
|
1247
|
|
|
{ |
|
1248
|
|
|
$u1 = self::factory()->user->create( |
|
1249
|
|
|
array( |
|
1250
|
|
|
'nickname' => 'Foo', |
|
1251
|
|
|
'user_nicename' => 'foo', |
|
1252
|
|
|
) |
|
1253
|
|
|
); |
|
1254
|
|
|
$u2 = self::factory()->user->create( |
|
1255
|
|
|
array( |
|
1256
|
|
|
'nickname' => "$u1 Foo", |
|
1257
|
|
|
'user_nicename' => 'foo-2', |
|
1258
|
|
|
) |
|
1259
|
|
|
); |
|
1260
|
|
|
|
|
1261
|
|
|
$this->go_to(get_author_posts_url($u2)); |
|
1262
|
|
|
|
|
1263
|
|
|
$this->assertTrue(is_author($u2)); |
|
1264
|
|
|
$this->assertFalse(is_author($u1)); |
|
1265
|
|
|
} |
|
1266
|
|
|
|
|
1267
|
|
|
/** |
|
1268
|
|
|
* @ticket 35902 |
|
1269
|
|
|
*/ |
|
1270
|
|
View Code Duplication |
public function test_is_author_should_not_match_numeric_id_to_user_nicename_beginning_with_id() |
|
1271
|
|
|
{ |
|
1272
|
|
|
$u1 = self::factory()->user->create( |
|
1273
|
|
|
array( |
|
1274
|
|
|
'nickname' => 'Foo', |
|
1275
|
|
|
'user_nicename' => 'foo', |
|
1276
|
|
|
) |
|
1277
|
|
|
); |
|
1278
|
|
|
$u2 = self::factory()->user->create( |
|
1279
|
|
|
array( |
|
1280
|
|
|
'nickname' => 'Foo', |
|
1281
|
|
|
'user_nicename' => "$u1-foo", |
|
1282
|
|
|
) |
|
1283
|
|
|
); |
|
1284
|
|
|
|
|
1285
|
|
|
$this->go_to(get_author_posts_url($u2)); |
|
1286
|
|
|
|
|
1287
|
|
|
$this->assertTrue(is_author($u2)); |
|
1288
|
|
|
$this->assertFalse(is_author($u1)); |
|
1289
|
|
|
} |
|
1290
|
|
|
|
|
1291
|
|
|
/** |
|
1292
|
|
|
* @ticket 35902 |
|
1293
|
|
|
*/ |
|
1294
|
|
View Code Duplication |
public function test_is_category_should_not_match_numeric_id_to_name_beginning_with_id() |
|
1295
|
|
|
{ |
|
1296
|
|
|
$t1 = self::factory()->term->create( |
|
1297
|
|
|
array( |
|
1298
|
|
|
'taxonomy' => 'category', |
|
1299
|
|
|
'slug' => 'foo', |
|
1300
|
|
|
'name' => 'foo', |
|
1301
|
|
|
) |
|
1302
|
|
|
); |
|
1303
|
|
|
$t2 = self::factory()->term->create( |
|
1304
|
|
|
array( |
|
1305
|
|
|
'taxonomy' => 'category', |
|
1306
|
|
|
'slug' => "$t1-foo", |
|
1307
|
|
|
'name' => 'foo 2', |
|
1308
|
|
|
) |
|
1309
|
|
|
); |
|
1310
|
|
|
|
|
1311
|
|
|
$this->go_to(get_term_link($t2)); |
|
1312
|
|
|
|
|
1313
|
|
|
$this->assertTrue(is_category($t2)); |
|
1314
|
|
|
$this->assertFalse(is_category($t1)); |
|
1315
|
|
|
} |
|
1316
|
|
|
|
|
1317
|
|
|
/** |
|
1318
|
|
|
* @ticket 35902 |
|
1319
|
|
|
*/ |
|
1320
|
|
View Code Duplication |
public function test_is_category_should_not_match_numeric_id_to_slug_beginning_with_id() |
|
1321
|
|
|
{ |
|
1322
|
|
|
$t1 = self::factory()->term->create( |
|
1323
|
|
|
array( |
|
1324
|
|
|
'taxonomy' => 'category', |
|
1325
|
|
|
'slug' => 'foo', |
|
1326
|
|
|
'name' => 'foo', |
|
1327
|
|
|
) |
|
1328
|
|
|
); |
|
1329
|
|
|
$t2 = self::factory()->term->create( |
|
1330
|
|
|
array( |
|
1331
|
|
|
'taxonomy' => 'category', |
|
1332
|
|
|
'slug' => 'foo-2', |
|
1333
|
|
|
'name' => "$t1 foo", |
|
1334
|
|
|
) |
|
1335
|
|
|
); |
|
1336
|
|
|
|
|
1337
|
|
|
$this->go_to(get_term_link($t2)); |
|
1338
|
|
|
|
|
1339
|
|
|
$this->assertTrue(is_category($t2)); |
|
1340
|
|
|
$this->assertFalse(is_category($t1)); |
|
1341
|
|
|
} |
|
1342
|
|
|
|
|
1343
|
|
|
/** |
|
1344
|
|
|
* @ticket 35902 |
|
1345
|
|
|
*/ |
|
1346
|
|
View Code Duplication |
public function test_is_tag_should_not_match_numeric_id_to_name_beginning_with_id() |
|
1347
|
|
|
{ |
|
1348
|
|
|
$t1 = self::factory()->term->create( |
|
1349
|
|
|
array( |
|
1350
|
|
|
'taxonomy' => 'post_tag', |
|
1351
|
|
|
'slug' => 'foo', |
|
1352
|
|
|
'name' => 'foo', |
|
1353
|
|
|
) |
|
1354
|
|
|
); |
|
1355
|
|
|
$t2 = self::factory()->term->create( |
|
1356
|
|
|
array( |
|
1357
|
|
|
'taxonomy' => 'post_tag', |
|
1358
|
|
|
'slug' => "$t1-foo", |
|
1359
|
|
|
'name' => 'foo 2', |
|
1360
|
|
|
) |
|
1361
|
|
|
); |
|
1362
|
|
|
|
|
1363
|
|
|
$this->go_to(get_term_link($t2)); |
|
1364
|
|
|
|
|
1365
|
|
|
$this->assertTrue(is_tag($t2)); |
|
1366
|
|
|
$this->assertFalse(is_tag($t1)); |
|
1367
|
|
|
} |
|
1368
|
|
|
|
|
1369
|
|
|
/** |
|
1370
|
|
|
* @ticket 35902 |
|
1371
|
|
|
*/ |
|
1372
|
|
View Code Duplication |
public function test_is_tag_should_not_match_numeric_id_to_slug_beginning_with_id() |
|
1373
|
|
|
{ |
|
1374
|
|
|
$t1 = self::factory()->term->create( |
|
1375
|
|
|
array( |
|
1376
|
|
|
'taxonomy' => 'post_tag', |
|
1377
|
|
|
'slug' => 'foo', |
|
1378
|
|
|
'name' => 'foo', |
|
1379
|
|
|
) |
|
1380
|
|
|
); |
|
1381
|
|
|
$t2 = self::factory()->term->create( |
|
1382
|
|
|
array( |
|
1383
|
|
|
'taxonomy' => 'post_tag', |
|
1384
|
|
|
'slug' => 'foo-2', |
|
1385
|
|
|
'name' => "$t1 foo", |
|
1386
|
|
|
) |
|
1387
|
|
|
); |
|
1388
|
|
|
|
|
1389
|
|
|
$this->go_to(get_term_link($t2)); |
|
1390
|
|
|
|
|
1391
|
|
|
$this->assertTrue(is_tag($t2)); |
|
1392
|
|
|
$this->assertFalse(is_tag($t1)); |
|
1393
|
|
|
} |
|
1394
|
|
|
|
|
1395
|
|
|
/** |
|
1396
|
|
|
* @ticket 35902 |
|
1397
|
|
|
*/ |
|
1398
|
|
View Code Duplication |
public function test_is_page_should_not_match_numeric_id_to_post_title_beginning_with_id() |
|
1399
|
|
|
{ |
|
1400
|
|
|
$p1 = self::factory()->post->create( |
|
1401
|
|
|
array( |
|
1402
|
|
|
'post_type' => 'page', |
|
1403
|
|
|
'post_title' => 'Foo', |
|
1404
|
|
|
'post_name' => 'foo', |
|
1405
|
|
|
) |
|
1406
|
|
|
); |
|
1407
|
|
|
$p2 = self::factory()->post->create( |
|
1408
|
|
|
array( |
|
1409
|
|
|
'post_type' => 'page', |
|
1410
|
|
|
'post_title' => "$p1 Foo", |
|
1411
|
|
|
'post_name' => 'foo-2', |
|
1412
|
|
|
) |
|
1413
|
|
|
); |
|
1414
|
|
|
|
|
1415
|
|
|
$this->go_to(get_permalink($p2)); |
|
1416
|
|
|
|
|
1417
|
|
|
$this->assertTrue(is_page($p2)); |
|
1418
|
|
|
$this->assertFalse(is_page($p1)); |
|
1419
|
|
|
} |
|
1420
|
|
|
|
|
1421
|
|
|
/** |
|
1422
|
|
|
* @ticket 35902 |
|
1423
|
|
|
*/ |
|
1424
|
|
View Code Duplication |
public function test_is_page_should_not_match_numeric_id_to_post_name_beginning_with_id() |
|
1425
|
|
|
{ |
|
1426
|
|
|
$p1 = self::factory()->post->create( |
|
1427
|
|
|
array( |
|
1428
|
|
|
'post_type' => 'page', |
|
1429
|
|
|
'post_title' => 'Foo', |
|
1430
|
|
|
'post_name' => 'foo', |
|
1431
|
|
|
) |
|
1432
|
|
|
); |
|
1433
|
|
|
$p2 = self::factory()->post->create( |
|
1434
|
|
|
array( |
|
1435
|
|
|
'post_type' => 'page', |
|
1436
|
|
|
'post_title' => 'Foo', |
|
1437
|
|
|
'post_name' => "$p1-foo", |
|
1438
|
|
|
) |
|
1439
|
|
|
); |
|
1440
|
|
|
|
|
1441
|
|
|
$this->go_to(get_permalink($p2)); |
|
1442
|
|
|
|
|
1443
|
|
|
$this->assertTrue(is_page($p2)); |
|
1444
|
|
|
$this->assertFalse(is_page($p1)); |
|
1445
|
|
|
} |
|
1446
|
|
|
|
|
1447
|
|
|
/** |
|
1448
|
|
|
* @ticket 35902 |
|
1449
|
|
|
*/ |
|
1450
|
|
View Code Duplication |
public function test_is_single_should_not_match_numeric_id_to_post_title_beginning_with_id() |
|
1451
|
|
|
{ |
|
1452
|
|
|
$p1 = self::factory()->post->create( |
|
1453
|
|
|
array( |
|
1454
|
|
|
'post_type' => 'post', |
|
1455
|
|
|
'post_title' => 'Foo', |
|
1456
|
|
|
'post_name' => 'foo', |
|
1457
|
|
|
) |
|
1458
|
|
|
); |
|
1459
|
|
|
$p2 = self::factory()->post->create( |
|
1460
|
|
|
array( |
|
1461
|
|
|
'post_type' => 'post', |
|
1462
|
|
|
'post_title' => "$p1 Foo", |
|
1463
|
|
|
'post_name' => 'foo-2', |
|
1464
|
|
|
) |
|
1465
|
|
|
); |
|
1466
|
|
|
|
|
1467
|
|
|
$this->go_to(get_permalink($p2)); |
|
1468
|
|
|
|
|
1469
|
|
|
$this->assertTrue(is_single($p2)); |
|
1470
|
|
|
$this->assertFalse(is_single($p1)); |
|
1471
|
|
|
} |
|
1472
|
|
|
|
|
1473
|
|
|
/** |
|
1474
|
|
|
* @ticket 35902 |
|
1475
|
|
|
*/ |
|
1476
|
|
View Code Duplication |
public function test_is_single_should_not_match_numeric_id_to_post_name_beginning_with_id() |
|
1477
|
|
|
{ |
|
1478
|
|
|
$p1 = self::factory()->post->create( |
|
1479
|
|
|
array( |
|
1480
|
|
|
'post_type' => 'post', |
|
1481
|
|
|
'post_title' => 'Foo', |
|
1482
|
|
|
'post_name' => 'foo', |
|
1483
|
|
|
) |
|
1484
|
|
|
); |
|
1485
|
|
|
$p2 = self::factory()->post->create( |
|
1486
|
|
|
array( |
|
1487
|
|
|
'post_type' => 'post', |
|
1488
|
|
|
'post_title' => 'Foo', |
|
1489
|
|
|
'post_name' => "$p1-foo", |
|
1490
|
|
|
) |
|
1491
|
|
|
); |
|
1492
|
|
|
|
|
1493
|
|
|
$this->go_to(get_permalink($p2)); |
|
1494
|
|
|
|
|
1495
|
|
|
$this->assertTrue(is_single($p2)); |
|
1496
|
|
|
$this->assertFalse(is_single($p1)); |
|
1497
|
|
|
} |
|
1498
|
|
|
} |
|
1499
|
|
|
|