| | 473 | * @ticket 5305 |
| | 474 | */ |
| | 475 | function test_permalink_year_segment_collision_without_title() { |
| | 476 | global $wp_rewrite, $wpdb; |
| | 477 | $wp_rewrite->init(); |
| | 478 | $wp_rewrite->set_permalink_structure( '/%postname%/' ); |
| | 479 | $wp_rewrite->flush_rules(); |
| | 480 | |
| | 481 | $id = $this->factory->post->create( array( |
| | 482 | 'post_author' => $this->author_id, |
| | 483 | 'post_status' => 'publish', |
| | 484 | 'post_content' => rand_str(), |
| | 485 | 'post_title' => '', |
| | 486 | 'post_name' => '2015', |
| | 487 | 'post_date' => '2015-02-01 01:00:00' |
| | 488 | ) ); |
| | 489 | |
| | 490 | // Force an ID that resembles a year format |
| | 491 | $wpdb->update( |
| | 492 | $wpdb->posts, |
| | 493 | array( |
| | 494 | 'ID' => '2015', |
| | 495 | 'guid' => 'http://example.org/?p=2015' |
| | 496 | ), |
| | 497 | array( 'ID' => $id ) |
| | 498 | ); |
| | 499 | |
| | 500 | $this->go_to( get_permalink( '2015' ) ); |
| | 501 | |
| | 502 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 503 | |
| | 504 | $wp_rewrite->set_permalink_structure(''); |
| | 505 | } |
| | 506 | |
| | 507 | /** |
| | 508 | * @ticket 5305 |
| | 509 | */ |
| | 510 | function test_permalink_year_segment_collision_with_title() { |
| | 511 | global $wp_rewrite; |
| | 512 | $wp_rewrite->init(); |
| | 513 | $wp_rewrite->set_permalink_structure( '/%postname%/' ); |
| | 514 | $wp_rewrite->flush_rules(); |
| | 515 | |
| | 516 | $id = $this->factory->post->create( array( |
| | 517 | 'post_author' => $this->author_id, |
| | 518 | 'post_status' => 'publish', |
| | 519 | 'post_content' => rand_str(), |
| | 520 | 'post_title' => '2015', |
| | 521 | 'post_date' => '2015-02-01 01:00:00', |
| | 522 | ) ); |
| | 523 | |
| | 524 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 525 | |
| | 526 | $wp_rewrite->set_permalink_structure(''); |
| | 527 | } |
| | 528 | |
| | 529 | /** |
| | 530 | * @ticket 5305 |
| | 531 | */ |
| | 532 | function test_permalink_month_segment_collision_without_title() { |
| | 533 | global $wp_rewrite; |
| | 534 | $wp_rewrite->init(); |
| | 535 | $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' ); |
| | 536 | $wp_rewrite->flush_rules(); |
| | 537 | |
| | 538 | $id = $this->factory->post->create( array( |
| | 539 | 'post_author' => $this->author_id, |
| | 540 | 'post_status' => 'publish', |
| | 541 | 'post_content' => rand_str(), |
| | 542 | 'post_title' => '', |
| | 543 | 'post_name' => '02', |
| | 544 | 'post_date' => '2015-02-01 01:00:00', |
| | 545 | ) ); |
| | 546 | |
| | 547 | $this->go_to( get_permalink( $id ) ); |
| | 548 | |
| | 549 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 550 | |
| | 551 | $wp_rewrite->set_permalink_structure(''); |
| | 552 | } |
| | 553 | |
| | 554 | /** |
| | 555 | * @ticket 5305 |
| | 556 | */ |
| | 557 | function test_permalink_month_segment_collision_with_title() { |
| | 558 | global $wp_rewrite; |
| | 559 | $wp_rewrite->init(); |
| | 560 | $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' ); |
| | 561 | $wp_rewrite->flush_rules(); |
| | 562 | |
| | 563 | $id = $this->factory->post->create( array( |
| | 564 | 'post_author' => $this->author_id, |
| | 565 | 'post_status' => 'publish', |
| | 566 | 'post_content' => rand_str(), |
| | 567 | 'post_title' => '02', |
| | 568 | 'post_date' => '2015-02-01 01:00:00', |
| | 569 | ) ); |
| | 570 | |
| | 571 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 572 | |
| | 573 | $wp_rewrite->set_permalink_structure(''); |
| | 574 | } |
| | 575 | |
| | 576 | /** |
| | 577 | * @ticket 5305 |
| | 578 | */ |
| | 579 | function test_permalink_day_segment_collision_without_title() { |
| | 580 | global $wp_rewrite; |
| | 581 | $wp_rewrite->init(); |
| | 582 | $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' ); |
| | 583 | $wp_rewrite->flush_rules(); |
| | 584 | |
| | 585 | $id = $this->factory->post->create( array( |
| | 586 | 'post_author' => $this->author_id, |
| | 587 | 'post_status' => 'publish', |
| | 588 | 'post_content' => rand_str(), |
| | 589 | 'post_title' => '', |
| | 590 | 'post_name' => '01', |
| | 591 | 'post_date' => '2015-02-01 01:00:00', |
| | 592 | ) ); |
| | 593 | |
| | 594 | $this->go_to( get_permalink( $id ) ); |
| | 595 | |
| | 596 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 597 | |
| | 598 | $wp_rewrite->set_permalink_structure(''); |
| | 599 | } |
| | 600 | |
| | 601 | /** |
| | 602 | * @ticket 5305 |
| | 603 | */ |
| | 604 | function test_permalink_day_segment_collision_with_title() { |
| | 605 | global $wp_rewrite; |
| | 606 | $wp_rewrite->init(); |
| | 607 | $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' ); |
| | 608 | $wp_rewrite->flush_rules(); |
| | 609 | |
| | 610 | $id = $this->factory->post->create( array( |
| | 611 | 'post_author' => $this->author_id, |
| | 612 | 'post_status' => 'publish', |
| | 613 | 'post_content' => rand_str(), |
| | 614 | 'post_title' => '01', |
| | 615 | 'post_date' => '2015-02-01 01:00:00', |
| | 616 | ) ); |
| | 617 | |
| | 618 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 619 | |
| | 620 | $wp_rewrite->set_permalink_structure(''); |
| | 621 | } |
| | 622 | |
| | 623 | /** |
| | 624 | * @ticket 5305 |
| | 625 | */ |
| | 626 | public function test_date_slug_collision_should_distinguish_pagination_from_date() { |
| | 627 | global $wp_rewrite; |
| | 628 | $wp_rewrite->init(); |
| | 629 | $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' ); |
| | 630 | $wp_rewrite->flush_rules(); |
| | 631 | |
| | 632 | $id = $this->factory->post->create( array( |
| | 633 | 'post_author' => $this->author_id, |
| | 634 | 'post_status' => 'publish', |
| | 635 | 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3', |
| | 636 | 'post_title' => '02', |
| | 637 | 'post_date' => '2015-02-01 01:00:00', |
| | 638 | ) ); |
| | 639 | |
| | 640 | $this->go_to( get_permalink( $id ) . '1' ); |
| | 641 | |
| | 642 | $this->assertFalse( is_day() ); |
| | 643 | } |
| | 644 | |
| | 645 | /** |