| | 138 | |
| | 139 | /** |
| | 140 | * @ticket 27015 |
| | 141 | */ |
| | 142 | function test_single_default_permalink() { |
| | 143 | update_option( 'permalink_structure', '' ); |
| | 144 | $GLOBALS['wp_rewrite']->init(); |
| | 145 | flush_rewrite_rules(); |
| | 146 | |
| | 147 | // add the filter to parse_query (this is the first point at which ->get_queried_object() will be available) |
| | 148 | add_filter( 'parse_query', array( $this, '_single_default_parse_query_queried_object' ) ); |
| | 149 | |
| | 150 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-1' ) ); |
| | 151 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 152 | |
| | 153 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 154 | $this->assertNotEmpty( get_query_var( 'p' ) ); |
| | 155 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 156 | |
| | 157 | remove_filter( 'parse_query', array( $this, '_single_default_parse_query_queried_object' ) ); |
| | 158 | } |
| | 159 | |
| | 160 | function _single_default_parse_query_queried_object( &$query ) { |
| | 161 | $single = get_page_by_path( 'test-27015-1', OBJECT, 'post' ); |
| | 162 | $this->assertTrue( $query->is_single() ); |
| | 163 | $this->assertTrue( $query->is_singular() ); |
| | 164 | $this->assertNotEmpty( $query->get( 'p' ) ); |
| | 165 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 166 | } |
| | 167 | |
| | 168 | /** |
| | 169 | * @ticket 27015 |
| | 170 | */ |
| | 171 | function test_single_day_name_permalink() { |
| | 172 | update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
| | 173 | $GLOBALS['wp_rewrite']->init(); |
| | 174 | flush_rewrite_rules(); |
| | 175 | |
| | 176 | add_filter( 'parse_query', array( $this, '_single_day_name_parse_query_queried_object' ) ); |
| | 177 | |
| | 178 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-2' ) ); |
| | 179 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 180 | |
| | 181 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 182 | $this->assertNotEmpty( get_query_var( 'year' ) ); |
| | 183 | $this->assertNotEmpty( get_query_var( 'monthnum' ) ); |
| | 184 | $this->assertNotEmpty( get_query_var( 'day' ) ); |
| | 185 | $this->assertNotEmpty( get_query_var( 'name' ) ); |
| | 186 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 187 | |
| | 188 | remove_filter( 'parse_query', array( $this, '_single_day_name_parse_query_queried_object' ) ); |
| | 189 | } |
| | 190 | |
| | 191 | function _single_day_name_parse_query_queried_object( &$query ) { |
| | 192 | $single = get_page_by_path( 'test-27015-2', OBJECT, 'post' ); |
| | 193 | $this->assertTrue( $query->is_single() ); |
| | 194 | $this->assertTrue( $query->is_singular() ); |
| | 195 | $this->assertNotEmpty( $query->get( 'year' ) ); |
| | 196 | $this->assertNotEmpty( $query->get( 'monthnum' ) ); |
| | 197 | $this->assertNotEmpty( $query->get( 'day' ) ); |
| | 198 | $this->assertNotEmpty( $query->get( 'name' ) ); |
| | 199 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 200 | } |
| | 201 | |
| | 202 | /** |
| | 203 | * @ticket 27015 |
| | 204 | */ |
| | 205 | function test_single_month_name_permalink() { |
| | 206 | update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' ); |
| | 207 | $GLOBALS['wp_rewrite']->init(); |
| | 208 | flush_rewrite_rules(); |
| | 209 | |
| | 210 | add_filter( 'parse_query', array( $this, '_single_month_name_parse_query_queried_object' ) ); |
| | 211 | |
| | 212 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-3' ) ); |
| | 213 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 214 | |
| | 215 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 216 | $this->assertNotEmpty( get_query_var( 'year' ) ); |
| | 217 | $this->assertNotEmpty( get_query_var( 'monthnum' ) ); |
| | 218 | $this->assertNotEmpty( get_query_var( 'name' ) ); |
| | 219 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 220 | |
| | 221 | remove_filter( 'parse_query', array( $this, '_single_month_name_parse_query_queried_object' ) ); |
| | 222 | } |
| | 223 | |
| | 224 | function _single_month_name_parse_query_queried_object( &$query ) { |
| | 225 | $single = get_page_by_path( 'test-27015-3', OBJECT, 'post' ); |
| | 226 | $this->assertTrue( $query->is_single() ); |
| | 227 | $this->assertTrue( $query->is_singular() ); |
| | 228 | $this->assertNotEmpty( get_query_var( 'year' ) ); |
| | 229 | $this->assertNotEmpty( get_query_var( 'monthnum' ) ); |
| | 230 | $this->assertNotEmpty( get_query_var( 'name' ) ); |
| | 231 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 232 | } |
| | 233 | |
| | 234 | /** |
| | 235 | * @ticket 27015 |
| | 236 | */ |
| | 237 | function test_single_numeric_permalink() { |
| | 238 | update_option( 'permalink_structure', '/archives/%post_id%' ); |
| | 239 | $GLOBALS['wp_rewrite']->init(); |
| | 240 | flush_rewrite_rules(); |
| | 241 | |
| | 242 | add_filter( 'parse_query', array( $this, '_single_numeric_parse_query_queried_object' ) ); |
| | 243 | |
| | 244 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-4' ) ); |
| | 245 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 246 | |
| | 247 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 248 | $this->assertNotEmpty( get_query_var( 'p' ) ); |
| | 249 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 250 | |
| | 251 | remove_filter( 'parse_query', array( $this, '_single_numeric_parse_query_queried_object' ) ); |
| | 252 | } |
| | 253 | |
| | 254 | function _single_numeric_parse_query_queried_object( &$query ) { |
| | 255 | $single = get_page_by_path( 'test-27015-4', OBJECT, 'post' ); |
| | 256 | $this->assertTrue( $query->is_single() ); |
| | 257 | $this->assertTrue( $query->is_singular() ); |
| | 258 | $this->assertNotEmpty( $query->get( 'p' ) ); |
| | 259 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 260 | } |
| | 261 | |
| | 262 | /** |
| | 263 | * @ticket 27015 |
| | 264 | */ |
| | 265 | function test_single_postname_permalink() { |
| | 266 | update_option( 'permalink_structure', '/%postname%/' ); |
| | 267 | $GLOBALS['wp_rewrite']->init(); |
| | 268 | flush_rewrite_rules(); |
| | 269 | |
| | 270 | add_filter( 'parse_query', array( $this, '_single_postname_query_queried_object' ) ); |
| | 271 | |
| | 272 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'post', 'post_name' => 'test-27015-5' ) ); |
| | 273 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 274 | |
| | 275 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 276 | $this->assertNotEmpty( get_query_var( 'name' ) ); |
| | 277 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 278 | |
| | 279 | remove_filter( 'parse_query', array( $this, '_single_postname_query_queried_object' ) ); |
| | 280 | } |
| | 281 | |
| | 282 | function _single_postname_query_queried_object( &$query ) { |
| | 283 | $single = get_page_by_path( 'test-27015-5', OBJECT, 'post' ); |
| | 284 | $this->assertTrue( $query->is_single() ); |
| | 285 | $this->assertTrue( $query->is_singular() ); |
| | 286 | $this->assertNotEmpty( $query->get( 'name' ) ); |
| | 287 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 288 | } |
| | 289 | |
| | 290 | /** |
| | 291 | * @ticket 27015 |
| | 292 | */ |
| | 293 | function test_page_default_permalink() { |
| | 294 | update_option( 'permalink_structure', '' ); |
| | 295 | $GLOBALS['wp_rewrite']->init(); |
| | 296 | flush_rewrite_rules(); |
| | 297 | |
| | 298 | add_filter( 'parse_query', array( $this, '_page_default_query_queried_object' ) ); |
| | 299 | |
| | 300 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-6' ) ); |
| | 301 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 302 | |
| | 303 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 304 | $this->assertNotEmpty( get_query_var( 'page_id' ) ); |
| | 305 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 306 | |
| | 307 | remove_filter( 'parse_query', array( $this, '_page_default_query_queried_object' ) ); |
| | 308 | } |
| | 309 | |
| | 310 | function _page_default_query_queried_object( &$query ) { |
| | 311 | $single = get_page_by_path( 'test-27015-6', OBJECT, 'page' ); |
| | 312 | $this->assertTrue( $query->is_page() ); |
| | 313 | $this->assertTrue( $query->is_singular() ); |
| | 314 | $this->assertNotEmpty( $query->get( 'page_id' ) ); |
| | 315 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 316 | } |
| | 317 | |
| | 318 | /** |
| | 319 | * @ticket 27015 |
| | 320 | */ |
| | 321 | function test_page_day_name_permalink() { |
| | 322 | update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
| | 323 | $GLOBALS['wp_rewrite']->init(); |
| | 324 | flush_rewrite_rules(); |
| | 325 | |
| | 326 | add_filter( 'parse_query', array( $this, '_page_day_name_query_queried_object' ) ); |
| | 327 | |
| | 328 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-7' ) ); |
| | 329 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 330 | |
| | 331 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 332 | $this->assertNotEmpty( get_query_var( 'pagename' ) ); |
| | 333 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 334 | |
| | 335 | remove_filter( 'parse_query', array( $this, '_page_day_name_query_queried_object' ) ); |
| | 336 | } |
| | 337 | |
| | 338 | function _page_day_name_query_queried_object( &$query ) { |
| | 339 | $single = get_page_by_path( 'test-27015-7', OBJECT, 'page' ); |
| | 340 | $this->assertTrue( $query->is_page() ); |
| | 341 | $this->assertTrue( $query->is_singular() ); |
| | 342 | $this->assertNotEmpty( $query->get( 'pagename' ) ); |
| | 343 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 344 | } |
| | 345 | |
| | 346 | /** |
| | 347 | * @ticket 27015 |
| | 348 | * Tests start failing here and I have no idea why. |
| | 349 | */ |
| | 350 | function test_page_month_name_permalink() { |
| | 351 | update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' ); |
| | 352 | $GLOBALS['wp_rewrite']->init(); |
| | 353 | flush_rewrite_rules(); |
| | 354 | |
| | 355 | add_filter( 'parse_query', array( $this, '_page_month_name_query_queried_object' ) ); |
| | 356 | |
| | 357 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-8' ) ); |
| | 358 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 359 | |
| | 360 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 361 | $this->assertNotEmpty( get_query_var( 'pagename' ) ); |
| | 362 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 363 | |
| | 364 | remove_filter( 'parse_query', array( $this, '_page_month_name_query_queried_object' ) ); |
| | 365 | } |
| | 366 | |
| | 367 | function _page_month_name_query_queried_object( &$query ) { |
| | 368 | $single = get_page_by_path( 'test-27015-8', OBJECT, 'page' ); |
| | 369 | $this->assertTrue( $query->is_page() ); |
| | 370 | $this->assertTrue( $query->is_singular() ); |
| | 371 | $this->assertNotEmpty( $query->get( 'pagename' ) ); |
| | 372 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 373 | } |
| | 374 | |
| | 375 | /** |
| | 376 | * @ticket 27015 |
| | 377 | */ |
| | 378 | function test_page_numeric_permalink() { |
| | 379 | update_option( 'permalink_structure', '/archives/%post_id%' ); |
| | 380 | $GLOBALS['wp_rewrite']->init(); |
| | 381 | flush_rewrite_rules(); |
| | 382 | |
| | 383 | add_filter( 'parse_query', array( $this, '_page_numeric_query_queried_object' ) ); |
| | 384 | |
| | 385 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-9' ) ); |
| | 386 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 387 | |
| | 388 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 389 | $this->assertNotEmpty( get_query_var( 'pagename' ) ); |
| | 390 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 391 | |
| | 392 | remove_filter( 'parse_query', array( $this, '_page_numeric_query_queried_object' ) ); |
| | 393 | } |
| | 394 | |
| | 395 | function _page_numeric_query_queried_object( &$query ) { |
| | 396 | $single = get_page_by_path( 'test-27015-9', OBJECT, 'page' ); |
| | 397 | $this->assertTrue( $query->is_page() ); |
| | 398 | $this->assertTrue( $query->is_singular() ); |
| | 399 | $this->assertNotEmpty( $query->get( 'pagename' ) ); |
| | 400 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 401 | } |
| | 402 | |
| | 403 | /** |
| | 404 | * @ticket 27015 |
| | 405 | */ |
| | 406 | function test_page_postname_permalink() { |
| | 407 | update_option( 'permalink_structure', '/%postname%/' ); |
| | 408 | $GLOBALS['wp_rewrite']->init(); |
| | 409 | flush_rewrite_rules(); |
| | 410 | |
| | 411 | add_filter( 'parse_query', array( $this, '_page_postname_query_queried_object' ) ); |
| | 412 | |
| | 413 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'page', 'post_name' => 'test-27015-10' ) ); |
| | 414 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 415 | |
| | 416 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 417 | $this->assertNotEmpty( get_query_var( 'pagename' ) ); |
| | 418 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 419 | |
| | 420 | remove_filter( 'parse_query', array( $this, '_page_postname_query_queried_object' ) ); |
| | 421 | } |
| | 422 | |
| | 423 | function _page_postname_query_queried_object( &$query ) { |
| | 424 | $single = get_page_by_path( 'test-27015-10', OBJECT, 'page' ); |
| | 425 | $this->assertTrue( $query->is_page() ); |
| | 426 | $this->assertTrue( $query->is_singular() ); |
| | 427 | $this->assertNotEmpty( $query->get( 'pagename' ) ); |
| | 428 | $this->assertEquals( $query->get_queried_object(), $single ); |
| | 429 | } |
| | 430 | |
| | 431 | /** |
| | 432 | * @ticket 27015 |
| | 433 | */ |
| | 434 | function test_front_page_default_permalink() { |
| | 435 | $front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-1', 'post_type' => 'page' ) ); |
| | 436 | |
| | 437 | update_option( 'show_on_front', 'page' ); |
| | 438 | update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) ); |
| | 439 | update_option( 'page_on_front', $front_page->ID ); |
| | 440 | update_option( 'permalink_structure', false ); |
| | 441 | $GLOBALS['wp_rewrite']->init(); |
| | 442 | flush_rewrite_rules(); |
| | 443 | |
| | 444 | add_filter( 'parse_query', array( $this, '_front_page_default_query' ) ); |
| | 445 | |
| | 446 | $this->go_to('/'); |
| | 447 | |
| | 448 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 449 | $this->assertTrue( is_front_page() ); |
| | 450 | $this->assertNotEmpty( get_query_var( 'page_id' ) ); |
| | 451 | $this->assertEquals( get_queried_object(), $front_page ); |
| | 452 | |
| | 453 | remove_filter( 'parse_query', array( $this, '_front_page_default_query' ) ); |
| | 454 | } |
| | 455 | |
| | 456 | function _front_page_default_query( &$query ) { |
| | 457 | $front_page = get_page_by_path( 'front-page-27015-1', OBJECT, 'page' ); |
| | 458 | $this->assertTrue( $query->is_page() ); |
| | 459 | $this->assertTrue( $query->is_singular() ); |
| | 460 | $this->assertTrue( $query->is_front_page() ); |
| | 461 | $this->assertNotEmpty( $query->get( 'page_id' ) ); |
| | 462 | $this->assertEquals( $query->get_queried_object(), $front_page ); |
| | 463 | } |
| | 464 | |
| | 465 | /** |
| | 466 | * @ticket 27015 |
| | 467 | */ |
| | 468 | function test_front_page_day_name_permalink() { |
| | 469 | $front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-2', 'post_type' => 'page' ) ); |
| | 470 | |
| | 471 | update_option( 'show_on_front', 'page' ); |
| | 472 | update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) ); |
| | 473 | update_option( 'page_on_front', $front_page->ID ); |
| | 474 | update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
| | 475 | $GLOBALS['wp_rewrite']->init(); |
| | 476 | flush_rewrite_rules(); |
| | 477 | |
| | 478 | add_filter( 'parse_query', array( $this, '_front_page_day_name_query' ) ); |
| | 479 | |
| | 480 | $this->go_to('/'); |
| | 481 | |
| | 482 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 483 | $this->assertTrue( is_front_page() ); |
| | 484 | $this->assertNotEmpty( get_query_var( 'page_id' ) ); |
| | 485 | $this->assertEquals( get_queried_object(), $front_page ); |
| | 486 | |
| | 487 | remove_filter( 'parse_query', array( $this, '_front_page_day_name_query' ) ); |
| | 488 | } |
| | 489 | |
| | 490 | function _front_page_day_name_query( &$query ) { |
| | 491 | $front_page = get_page_by_path( 'front-page-27015-2', OBJECT, 'page' ); |
| | 492 | $this->assertTrue( $query->is_page() ); |
| | 493 | $this->assertTrue( $query->is_singular() ); |
| | 494 | $this->assertTrue( $query->is_front_page() ); |
| | 495 | $this->assertNotEmpty( $query->get( 'page_id' ) ); |
| | 496 | $this->assertEquals( $query->get_queried_object(), $front_page ); |
| | 497 | } |
| | 498 | |
| | 499 | /** |
| | 500 | * @ticket 27015 |
| | 501 | */ |
| | 502 | function test_front_page_month_name_permalink() { |
| | 503 | $front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-3', 'post_type' => 'page' ) ); |
| | 504 | |
| | 505 | update_option( 'show_on_front', 'page' ); |
| | 506 | update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) ); |
| | 507 | update_option( 'page_on_front', $front_page->ID ); |
| | 508 | update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' ); |
| | 509 | $GLOBALS['wp_rewrite']->init(); |
| | 510 | flush_rewrite_rules(); |
| | 511 | |
| | 512 | add_filter( 'parse_query', array( $this, '_front_page_month_name_query' ) ); |
| | 513 | |
| | 514 | $this->go_to('/'); |
| | 515 | |
| | 516 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 517 | $this->assertTrue( is_front_page() ); |
| | 518 | $this->assertNotEmpty( get_query_var( 'page_id' ) ); |
| | 519 | $this->assertEquals( get_queried_object(), $front_page ); |
| | 520 | |
| | 521 | remove_filter( 'parse_query', array( $this, '_front_page_month_name_query' ) ); |
| | 522 | } |
| | 523 | |
| | 524 | function _front_page_month_name_query( &$query ) { |
| | 525 | $front_page = get_page_by_path( 'front-page-27015-3', OBJECT, 'page' ); |
| | 526 | $this->assertTrue( $query->is_page() ); |
| | 527 | $this->assertTrue( $query->is_singular() ); |
| | 528 | $this->assertTrue( $query->is_front_page() ); |
| | 529 | $this->assertNotEmpty( $query->get( 'page_id' ) ); |
| | 530 | $this->assertEquals( $query->get_queried_object(), $front_page ); |
| | 531 | } |
| | 532 | |
| | 533 | /** |
| | 534 | * @ticket 27015 |
| | 535 | */ |
| | 536 | function test_front_page_numeric_permalink() { |
| | 537 | $front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-4', 'post_type' => 'page' ) ); |
| | 538 | |
| | 539 | update_option( 'show_on_front', 'page' ); |
| | 540 | update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) ); |
| | 541 | update_option( 'page_on_front', $front_page->ID ); |
| | 542 | update_option( 'permalink_structure', '/archives/%post_id%' ); |
| | 543 | $GLOBALS['wp_rewrite']->init(); |
| | 544 | flush_rewrite_rules(); |
| | 545 | |
| | 546 | add_filter( 'parse_query', array( $this, '_front_page_numeric_query' ) ); |
| | 547 | |
| | 548 | $this->go_to('/'); |
| | 549 | |
| | 550 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 551 | $this->assertTrue( is_front_page() ); |
| | 552 | $this->assertNotEmpty( get_query_var( 'page_id' ) ); |
| | 553 | $this->assertEquals( get_queried_object(), $front_page ); |
| | 554 | |
| | 555 | remove_filter( 'parse_query', array( $this, '_front_page_numeric_query' ) ); |
| | 556 | } |
| | 557 | |
| | 558 | function _front_page_numeric_query( &$query ) { |
| | 559 | $front_page = get_page_by_path( 'front-page-27015-4', OBJECT, 'page' ); |
| | 560 | $this->assertTrue( $query->is_page() ); |
| | 561 | $this->assertTrue( $query->is_singular() ); |
| | 562 | $this->assertTrue( $query->is_front_page() ); |
| | 563 | $this->assertNotEmpty( $query->get( 'page_id' ) ); |
| | 564 | $this->assertEquals( $query->get_queried_object(), $front_page ); |
| | 565 | } |
| | 566 | |
| | 567 | /** |
| | 568 | * @ticket 27015 |
| | 569 | */ |
| | 570 | function test_front_page_postname_permalink() { |
| | 571 | $front_page = $this->factory->post->create_and_get( array( 'post_title' => 'front-page-27015-5', 'post_type' => 'page' ) ); |
| | 572 | |
| | 573 | update_option( 'show_on_front', 'page' ); |
| | 574 | update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) ); |
| | 575 | update_option( 'page_on_front', $front_page->ID ); |
| | 576 | update_option( 'permalink_structure', '/%postname%/' ); |
| | 577 | $GLOBALS['wp_rewrite']->init(); |
| | 578 | flush_rewrite_rules(); |
| | 579 | |
| | 580 | add_filter( 'parse_query', array( $this, '_front_page_postname_query' ) ); |
| | 581 | |
| | 582 | $this->go_to('/'); |
| | 583 | |
| | 584 | $this->assertQueryTrue( 'is_page', 'is_singular' ); |
| | 585 | $this->assertTrue( is_front_page() ); |
| | 586 | $this->assertNotEmpty( get_query_var( 'page_id' ) ); |
| | 587 | $this->assertEquals( get_queried_object(), $front_page ); |
| | 588 | |
| | 589 | remove_filter( 'parse_query', array( $this, '_front_page_postname_query' ) ); |
| | 590 | } |
| | 591 | |
| | 592 | function _front_page_postname_query( &$query ) { |
| | 593 | $front_page = get_page_by_path( 'front-page-27015-5', OBJECT, 'page' ); |
| | 594 | $this->assertTrue( $query->is_page() ); |
| | 595 | $this->assertTrue( $query->is_singular() ); |
| | 596 | $this->assertTrue( $query->is_front_page() ); |
| | 597 | $this->assertNotEmpty( $query->get( 'page_id' ) ); |
| | 598 | $this->assertEquals( $query->get_queried_object(), $front_page ); |
| | 599 | } |
| | 600 | |
| | 601 | /** |
| | 602 | * @ticket 27015 |
| | 603 | */ |
| | 604 | function test_author_archive_default_permalink() { |
| | 605 | update_option( 'permalink_structure', false ); |
| | 606 | $GLOBALS['wp_rewrite']->init(); |
| | 607 | flush_rewrite_rules(); |
| | 608 | |
| | 609 | $posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) ); |
| | 610 | |
| | 611 | add_filter( 'parse_query', array( $this, '_author_archive_default_query' ) ); |
| | 612 | |
| | 613 | $this->go_to( get_author_posts_url( 1 ) ); |
| | 614 | |
| | 615 | $this->assertQueryTrue( 'is_author', 'is_archive' ); |
| | 616 | $this->assertTrue( is_author() ); |
| | 617 | $this->assertTrue( is_archive() ); |
| | 618 | $this->assertNotEmpty( get_query_var( 'author' ) ); |
| | 619 | $this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) ); |
| | 620 | |
| | 621 | remove_filter( 'parse_query', array( $this, '_author_archive_default_query' ) ); |
| | 622 | } |
| | 623 | |
| | 624 | function _author_archive_default_query( &$query ) { |
| | 625 | $this->assertTrue( $query->is_author() ); |
| | 626 | $this->assertTrue( $query->is_archive() ); |
| | 627 | $this->assertNotEmpty( $query->get( 'author' ) ); |
| | 628 | $this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) ); |
| | 629 | } |
| | 630 | |
| | 631 | /** |
| | 632 | * @ticket 27015 |
| | 633 | */ |
| | 634 | function test_author_archive_day_name_permalink() { |
| | 635 | update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
| | 636 | $GLOBALS['wp_rewrite']->init(); |
| | 637 | flush_rewrite_rules(); |
| | 638 | |
| | 639 | $posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) ); |
| | 640 | |
| | 641 | add_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) ); |
| | 642 | |
| | 643 | $this->go_to( get_author_posts_url( 1 ) ); |
| | 644 | |
| | 645 | $this->assertQueryTrue( 'is_author', 'is_archive' ); |
| | 646 | $this->assertTrue( is_author() ); |
| | 647 | $this->assertTrue( is_archive() ); |
| | 648 | $this->assertNotEmpty( get_query_var( 'author_name' ) ); |
| | 649 | $this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) ); |
| | 650 | |
| | 651 | remove_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) ); |
| | 652 | } |
| | 653 | |
| | 654 | /** |
| | 655 | * @ticket 27015 |
| | 656 | */ |
| | 657 | function test_author_archive_month_name_permalink() { |
| | 658 | update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' ); |
| | 659 | $GLOBALS['wp_rewrite']->init(); |
| | 660 | flush_rewrite_rules(); |
| | 661 | |
| | 662 | $posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) ); |
| | 663 | |
| | 664 | add_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) ); |
| | 665 | |
| | 666 | $this->go_to( get_author_posts_url( 1 ) ); |
| | 667 | |
| | 668 | $this->assertQueryTrue( 'is_author', 'is_archive' ); |
| | 669 | $this->assertTrue( is_author() ); |
| | 670 | $this->assertTrue( is_archive() ); |
| | 671 | $this->assertNotEmpty( get_query_var( 'author_name' ) ); |
| | 672 | $this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) ); |
| | 673 | |
| | 674 | remove_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) ); |
| | 675 | } |
| | 676 | |
| | 677 | /** |
| | 678 | * @ticket 27015 |
| | 679 | */ |
| | 680 | function test_author_archive_numeric_permalink() { |
| | 681 | update_option( 'permalink_structure', '/archives/%post_id%' ); |
| | 682 | $GLOBALS['wp_rewrite']->init(); |
| | 683 | flush_rewrite_rules(); |
| | 684 | |
| | 685 | $posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) ); |
| | 686 | |
| | 687 | add_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) ); |
| | 688 | |
| | 689 | $this->go_to( get_author_posts_url( 1 ) ); |
| | 690 | |
| | 691 | $this->assertQueryTrue( 'is_author', 'is_archive' ); |
| | 692 | $this->assertTrue( is_author() ); |
| | 693 | $this->assertTrue( is_archive() ); |
| | 694 | $this->assertNotEmpty( get_query_var( 'author_name' ) ); |
| | 695 | $this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) ); |
| | 696 | |
| | 697 | remove_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) ); |
| | 698 | } |
| | 699 | |
| | 700 | /** |
| | 701 | * @ticket 27015 |
| | 702 | */ |
| | 703 | function test_author_archive_postname_permalink() { |
| | 704 | update_option( 'permalink_structure', '/%postname%/' ); |
| | 705 | $GLOBALS['wp_rewrite']->init(); |
| | 706 | flush_rewrite_rules(); |
| | 707 | |
| | 708 | $posts = $this->factory->post->create_many( 5, array( 'post_type' => 'post', 'post_author' => '1' ) ); |
| | 709 | |
| | 710 | add_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) ); |
| | 711 | |
| | 712 | $this->go_to( get_author_posts_url( 1 ) ); |
| | 713 | |
| | 714 | $this->assertQueryTrue( 'is_author', 'is_archive' ); |
| | 715 | $this->assertTrue( is_author() ); |
| | 716 | $this->assertTrue( is_archive() ); |
| | 717 | $this->assertNotEmpty( get_query_var( 'author_name' ) ); |
| | 718 | $this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) ); |
| | 719 | |
| | 720 | remove_filter( 'parse_query', array( $this, '_author_archive_not_default_query' ) ); |
| | 721 | } |
| | 722 | |
| | 723 | function _author_archive_not_default_query( &$query ) { |
| | 724 | $this->assertTrue( $query->is_author() ); |
| | 725 | $this->assertTrue( $query->is_archive() ); |
| | 726 | $this->assertNotEmpty( $query->get( 'author_name' ) ); |
| | 727 | $this->assertEquals( get_queried_object(), get_user_by( 'id', 1 ) ); |
| | 728 | } |
| | 729 | |
| | 730 | /** |
| | 731 | * @ticket 27015 |
| | 732 | */ |
| | 733 | function test_cpt_default_permalink() { |
| | 734 | register_post_type( 'test-27015', array( |
| | 735 | 'rewrite' => true, |
| | 736 | 'has_archive' => true, |
| | 737 | 'public' => true |
| | 738 | ) ); |
| | 739 | update_option( 'permalink_structure', '' ); |
| | 740 | $GLOBALS['wp_rewrite']->init(); |
| | 741 | flush_rewrite_rules(); |
| | 742 | |
| | 743 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-1' ) ); |
| | 744 | |
| | 745 | add_filter( 'parse_query', array( $this, '_cpt_default_permalink_query' ) ); |
| | 746 | |
| | 747 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 748 | |
| | 749 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 750 | $this->assertTrue( is_singular( 'test-27015' ) ); |
| | 751 | $this->assertNotEmpty( get_query_var( 'post_type' ) ); |
| | 752 | $this->assertNotEmpty( get_query_var( 'name' ) ); |
| | 753 | $this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) ); |
| | 754 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 755 | |
| | 756 | remove_filter( 'parse_query', array( $this, '_cpt_default_permalink_query' ) ); |
| | 757 | _unregister_post_type( 'test-27015' ); |
| | 758 | } |
| | 759 | |
| | 760 | function _cpt_default_permalink_query( &$query ) { |
| | 761 | $this->assertTrue( $query->is_single() ); |
| | 762 | $this->assertTrue( $query->is_singular( 'test-27015' ) ); |
| | 763 | $this->assertNotEmpty( $query->get( 'post_type' ) ); |
| | 764 | $this->assertNotEmpty( $query->get( 'name' ) ); |
| | 765 | $this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) ); |
| | 766 | $this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-1', OBJECT, 'test-27015' ) ); |
| | 767 | } |
| | 768 | |
| | 769 | /** |
| | 770 | * @ticket 27015 |
| | 771 | */ |
| | 772 | function test_cpt_day_name_permalink() { |
| | 773 | register_post_type( 'test-27015', array( |
| | 774 | 'rewrite' => true, |
| | 775 | 'has_archive' => true, |
| | 776 | 'public' => true |
| | 777 | ) ); |
| | 778 | update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
| | 779 | $GLOBALS['wp_rewrite']->init(); |
| | 780 | flush_rewrite_rules(); |
| | 781 | |
| | 782 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-2' ) ); |
| | 783 | |
| | 784 | add_filter( 'parse_query', array( $this, '_cpt_day_name_permalink_query' ) ); |
| | 785 | |
| | 786 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 787 | |
| | 788 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 789 | $this->assertTrue( is_singular( 'test-27015' ) ); |
| | 790 | $this->assertNotEmpty( get_query_var( 'post_type' ) ); |
| | 791 | $this->assertNotEmpty( get_query_var( 'name' ) ); |
| | 792 | $this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) ); |
| | 793 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 794 | |
| | 795 | remove_filter( 'parse_query', array( $this, '_cpt_day_name_permalink_query' ) ); |
| | 796 | _unregister_post_type( 'test-27015' ); |
| | 797 | } |
| | 798 | |
| | 799 | function _cpt_day_name_permalink_query( &$query ) { |
| | 800 | $this->assertTrue( $query->is_single() ); |
| | 801 | $this->assertTrue( $query->is_singular( 'test-27015' ) ); |
| | 802 | $this->assertNotEmpty( $query->get( 'post_type' ) ); |
| | 803 | $this->assertNotEmpty( $query->get( 'name' ) ); |
| | 804 | $this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) ); |
| | 805 | $this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-2', OBJECT, 'test-27015' ) ); |
| | 806 | } |
| | 807 | |
| | 808 | /** |
| | 809 | * @ticket 27015 |
| | 810 | */ |
| | 811 | function test_cpt_month_name_permalink() { |
| | 812 | register_post_type( 'test-27015', array( |
| | 813 | 'rewrite' => true, |
| | 814 | 'has_archive' => true, |
| | 815 | 'public' => true |
| | 816 | ) ); |
| | 817 | update_option( 'permalink_structure', '/%year%/%monthnum%/%postname%/' ); |
| | 818 | $GLOBALS['wp_rewrite']->init(); |
| | 819 | flush_rewrite_rules(); |
| | 820 | |
| | 821 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-3' ) ); |
| | 822 | |
| | 823 | add_filter( 'parse_query', array( $this, '_cpt_month_name_permalink_query' ) ); |
| | 824 | |
| | 825 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 826 | |
| | 827 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 828 | $this->assertTrue( is_singular( 'test-27015' ) ); |
| | 829 | $this->assertNotEmpty( get_query_var( 'post_type' ) ); |
| | 830 | $this->assertNotEmpty( get_query_var( 'name' ) ); |
| | 831 | $this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) ); |
| | 832 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 833 | |
| | 834 | remove_filter( 'parse_query', array( $this, '_cpt_month_name_permalink_query' ) ); |
| | 835 | _unregister_post_type( 'test-27015' ); |
| | 836 | } |
| | 837 | |
| | 838 | function _cpt_month_name_permalink_query( &$query ) { |
| | 839 | $this->assertTrue( $query->is_single() ); |
| | 840 | $this->assertTrue( $query->is_singular( 'test-27015' ) ); |
| | 841 | $this->assertNotEmpty( $query->get( 'post_type' ) ); |
| | 842 | $this->assertNotEmpty( $query->get( 'name' ) ); |
| | 843 | $this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) ); |
| | 844 | $this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-3', OBJECT, 'test-27015' ) ); |
| | 845 | } |
| | 846 | |
| | 847 | /** |
| | 848 | * @ticket 27015 |
| | 849 | */ |
| | 850 | function test_cpt_numeric_permalink() { |
| | 851 | register_post_type( 'test-27015', array( |
| | 852 | 'rewrite' => true, |
| | 853 | 'has_archive' => true, |
| | 854 | 'public' => true |
| | 855 | ) ); |
| | 856 | update_option( 'permalink_structure', '/archives/%post_id%' ); |
| | 857 | $GLOBALS['wp_rewrite']->init(); |
| | 858 | flush_rewrite_rules(); |
| | 859 | |
| | 860 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-4' ) ); |
| | 861 | |
| | 862 | add_filter( 'parse_query', array( $this, '_cpt_numeric_permalink_query' ) ); |
| | 863 | |
| | 864 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 865 | |
| | 866 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 867 | $this->assertTrue( is_singular( 'test-27015' ) ); |
| | 868 | $this->assertNotEmpty( get_query_var( 'post_type' ) ); |
| | 869 | $this->assertNotEmpty( get_query_var( 'name' ) ); |
| | 870 | $this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) ); |
| | 871 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 872 | |
| | 873 | remove_filter( 'parse_query', array( $this, '_cpt_numeric_permalink_query' ) ); |
| | 874 | _unregister_post_type( 'test-27015' ); |
| | 875 | } |
| | 876 | |
| | 877 | function _cpt_numeric_permalink_query( &$query ) { |
| | 878 | $this->assertTrue( $query->is_single() ); |
| | 879 | $this->assertTrue( $query->is_singular( 'test-27015' ) ); |
| | 880 | $this->assertNotEmpty( $query->get( 'post_type' ) ); |
| | 881 | $this->assertNotEmpty( $query->get( 'name' ) ); |
| | 882 | $this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) ); |
| | 883 | $this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-4', OBJECT, 'test-27015' ) ); |
| | 884 | } |
| | 885 | |
| | 886 | /** |
| | 887 | * @ticket 27015 |
| | 888 | */ |
| | 889 | function test_cpt_postname_permalink() { |
| | 890 | register_post_type( 'test-27015', array( |
| | 891 | 'rewrite' => true, |
| | 892 | 'has_archive' => true, |
| | 893 | 'public' => true |
| | 894 | ) ); |
| | 895 | update_option( 'permalink_structure', '/%postname%/' ); |
| | 896 | $GLOBALS['wp_rewrite']->init(); |
| | 897 | flush_rewrite_rules(); |
| | 898 | |
| | 899 | $post1 = $this->factory->post->create_and_get( array( 'post_type' => 'test-27015', 'post_name' => 'cpt-27015-5' ) ); |
| | 900 | |
| | 901 | add_filter( 'parse_query', array( $this, '_cpt_postname_permalink_query' ) ); |
| | 902 | |
| | 903 | $this->go_to( get_permalink( $post1->ID ) ); |
| | 904 | |
| | 905 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 906 | $this->assertTrue( is_singular( 'test-27015' ) ); |
| | 907 | $this->assertNotEmpty( get_query_var( 'post_type' ) ); |
| | 908 | $this->assertNotEmpty( get_query_var( 'name' ) ); |
| | 909 | $this->assertNotEmpty( get_query_var( get_query_var( 'post_type' ) ) ); |
| | 910 | $this->assertEquals( get_queried_object(), $post1 ); |
| | 911 | |
| | 912 | remove_filter( 'parse_query', array( $this, '_cpt_postname_permalink_query' ) ); |
| | 913 | _unregister_post_type( 'test-27015' ); |
| | 914 | } |
| | 915 | |
| | 916 | function _cpt_postname_permalink_query( &$query ) { |
| | 917 | $this->assertTrue( $query->is_single() ); |
| | 918 | $this->assertTrue( $query->is_singular( 'test-27015' ) ); |
| | 919 | $this->assertNotEmpty( $query->get( 'post_type' ) ); |
| | 920 | $this->assertNotEmpty( $query->get( 'name' ) ); |
| | 921 | $this->assertNotEmpty( $query->get( $query->get( 'post_type' ) ) ); |
| | 922 | $this->assertEquals( $query->get_queried_object(), get_page_by_path( 'cpt-27015-5', OBJECT, 'test-27015' ) ); |
| | 923 | } |