| | 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_without_title_no_leading_zero() { |
| | 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' => '', |
| | 568 | 'post_name' => '2', |
| | 569 | 'post_date' => '2015-02-01 01:00:00', |
| | 570 | ) ); |
| | 571 | |
| | 572 | $this->go_to( get_permalink( $id ) ); |
| | 573 | |
| | 574 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 575 | |
| | 576 | $wp_rewrite->set_permalink_structure(''); |
| | 577 | } |
| | 578 | |
| | 579 | /** |
| | 580 | * @ticket 5305 |
| | 581 | */ |
| | 582 | function test_permalink_month_segment_collision_with_title() { |
| | 583 | global $wp_rewrite; |
| | 584 | $wp_rewrite->init(); |
| | 585 | $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' ); |
| | 586 | $wp_rewrite->flush_rules(); |
| | 587 | |
| | 588 | $id = $this->factory->post->create( array( |
| | 589 | 'post_author' => $this->author_id, |
| | 590 | 'post_status' => 'publish', |
| | 591 | 'post_content' => rand_str(), |
| | 592 | 'post_title' => '02', |
| | 593 | 'post_date' => '2015-02-01 01:00:00', |
| | 594 | ) ); |
| | 595 | |
| | 596 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 597 | |
| | 598 | $wp_rewrite->set_permalink_structure(''); |
| | 599 | } |
| | 600 | |
| | 601 | /** |
| | 602 | * @ticket 5305 |
| | 603 | */ |
| | 604 | function test_permalink_month_segment_collision_with_title_no_leading_zero() { |
| | 605 | global $wp_rewrite; |
| | 606 | $wp_rewrite->init(); |
| | 607 | $wp_rewrite->set_permalink_structure( '/%year%/%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' => '2', |
| | 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 | function test_permalink_day_segment_collision_without_title() { |
| | 627 | global $wp_rewrite; |
| | 628 | $wp_rewrite->init(); |
| | 629 | $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%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' => rand_str(), |
| | 636 | 'post_title' => '', |
| | 637 | 'post_name' => '01', |
| | 638 | 'post_date' => '2015-02-01 01:00:00', |
| | 639 | ) ); |
| | 640 | |
| | 641 | $this->go_to( get_permalink( $id ) ); |
| | 642 | |
| | 643 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 644 | |
| | 645 | $wp_rewrite->set_permalink_structure(''); |
| | 646 | } |
| | 647 | |
| | 648 | /** |
| | 649 | * @ticket 5305 |
| | 650 | */ |
| | 651 | function test_permalink_day_segment_collision_with_title() { |
| | 652 | global $wp_rewrite; |
| | 653 | $wp_rewrite->init(); |
| | 654 | $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' ); |
| | 655 | $wp_rewrite->flush_rules(); |
| | 656 | |
| | 657 | $id = $this->factory->post->create( array( |
| | 658 | 'post_author' => $this->author_id, |
| | 659 | 'post_status' => 'publish', |
| | 660 | 'post_content' => rand_str(), |
| | 661 | 'post_title' => '01', |
| | 662 | 'post_date' => '2015-02-01 01:00:00', |
| | 663 | ) ); |
| | 664 | |
| | 665 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 666 | |
| | 667 | $wp_rewrite->set_permalink_structure(''); |
| | 668 | } |
| | 669 | |
| | 670 | /** |
| | 671 | * @ticket 5305 |
| | 672 | */ |
| | 673 | public function test_date_slug_collision_should_distinguish_valid_pagination_from_date() { |
| | 674 | global $wp_rewrite; |
| | 675 | $wp_rewrite->init(); |
| | 676 | $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' ); |
| | 677 | $wp_rewrite->flush_rules(); |
| | 678 | |
| | 679 | $id = $this->factory->post->create( array( |
| | 680 | 'post_author' => $this->author_id, |
| | 681 | 'post_status' => 'publish', |
| | 682 | 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3', |
| | 683 | 'post_title' => '02', |
| | 684 | 'post_date' => '2015-02-01 01:00:00', |
| | 685 | ) ); |
| | 686 | |
| | 687 | $this->go_to( get_permalink( $id ) . '1' ); |
| | 688 | |
| | 689 | $this->assertFalse( is_day() ); |
| | 690 | } |
| | 691 | |
| | 692 | /** |
| | 693 | * @ticket 5305 |
| | 694 | */ |
| | 695 | public function test_date_slug_collision_should_distinguish_too_high_pagination_from_date() { |
| | 696 | global $wp_rewrite; |
| | 697 | $wp_rewrite->init(); |
| | 698 | $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' ); |
| | 699 | $wp_rewrite->flush_rules(); |
| | 700 | |
| | 701 | $id = $this->factory->post->create( array( |
| | 702 | 'post_author' => $this->author_id, |
| | 703 | 'post_status' => 'publish', |
| | 704 | 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3', |
| | 705 | 'post_title' => '02', |
| | 706 | 'post_date' => '2015-02-05 01:00:00', |
| | 707 | ) ); |
| | 708 | |
| | 709 | $this->go_to( get_permalink( $id ) . '5' ); |
| | 710 | |
| | 711 | $this->assertTrue( is_day() ); |
| | 712 | } |
| | 713 | |
| | 714 | /** |
| | 715 | * @ticket 5305 |
| | 716 | */ |
| | 717 | public function test_date_slug_collision_should_not_require_pagination_query_var() { |
| | 718 | global $wp_rewrite; |
| | 719 | $wp_rewrite->init(); |
| | 720 | $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' ); |
| | 721 | $wp_rewrite->flush_rules(); |
| | 722 | |
| | 723 | $id = $this->factory->post->create( array( |
| | 724 | 'post_author' => $this->author_id, |
| | 725 | 'post_status' => 'publish', |
| | 726 | 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3', |
| | 727 | 'post_title' => '02', |
| | 728 | 'post_date' => '2015-02-05 01:00:00', |
| | 729 | ) ); |
| | 730 | |
| | 731 | $this->go_to( get_permalink( $id ) ); |
| | 732 | |
| | 733 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 734 | $this->assertFalse( is_date() ); |
| | 735 | } |
| | 736 | |
| | 737 | /** |
| | 738 | * @ticket 5305 |
| | 739 | */ |
| | 740 | public function test_date_slug_collision_should_be_ignored_when_pagination_var_is_present_but_post_does_not_have_multiple_pages() { |
| | 741 | global $wp_rewrite; |
| | 742 | $wp_rewrite->init(); |
| | 743 | $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' ); |
| | 744 | $wp_rewrite->flush_rules(); |
| | 745 | |
| | 746 | $id = $this->factory->post->create( array( |
| | 747 | 'post_author' => $this->author_id, |
| | 748 | 'post_status' => 'publish', |
| | 749 | 'post_content' => 'This post does not have pagination.', |
| | 750 | 'post_title' => '02', |
| | 751 | 'post_date' => '2015-02-05 01:00:00', |
| | 752 | ) ); |
| | 753 | |
| | 754 | $this->go_to( get_permalink( $id ) . '5' ); |
| | 755 | |
| | 756 | $this->assertTrue( is_day() ); |
| | 757 | } |
| | 758 | |
| | 759 | /** |