Changeset 52095 for trunk/tests/phpunit/tests/post/revisions.php
- Timestamp:
- 11/10/2021 01:25:09 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/revisions.php
r52010 r52095 655 655 $this->assertWPError( $revision ); 656 656 } 657 658 /** 659 * Tests that wp_get_post_revisions_url() returns the revisions URL. 660 * 661 * @ticket 39062 662 * 663 * @dataProvider data_wp_get_post_revisions_url 664 * 665 * @covers ::wp_get_post_revisions_url 666 * 667 * @param int $revisions The number of revisions to create. 668 */ 669 public function test_wp_get_post_revisions_url( $revisions ) { 670 wp_set_current_user( self::$admin_user_id ); 671 672 $post_id = self::factory()->post->create( array( 'post_title' => 'Some Post' ) ); 673 $latest_revision_id = null; 674 675 if ( 0 !== $revisions ) { 676 $latest_revision_id = $post_id; 677 678 for ( $i = 0; $i < $revisions; ++$i ) { 679 wp_update_post( 680 array( 681 'ID' => $post_id, 682 'post_title' => 'Some Post ' . $i, 683 ) 684 ); 685 686 $latest_revision_id++; 687 } 688 } 689 690 $expected = admin_url( 'revision.php?revision=' . $latest_revision_id ); 691 692 $this->assertSame( 693 $expected, 694 wp_get_post_revisions_url( $post_id ), 695 'Failed when passed the Post ID' 696 ); 697 698 $this->assertSame( 699 $expected, 700 wp_get_post_revisions_url( $latest_revision_id ), 701 'Failed when passed the latest revision ID' 702 ); 703 } 704 705 /** 706 * Tests that wp_get_post_revisions_url() returns the revisions URL 707 * when passed a WP_Post object. 708 * 709 * @ticket 39062 710 * 711 * @dataProvider data_wp_get_post_revisions_url 712 * 713 * @covers ::wp_get_post_revisions_url 714 * 715 * @param int $revisions The number of revisions to create. 716 */ 717 public function test_wp_get_post_revisions_url_with_post_object( $revisions ) { 718 wp_set_current_user( self::$admin_user_id ); 719 720 $post = self::factory()->post->create_and_get( array( 'post_title' => 'Some Post' ) ); 721 $latest_revision_id = null; 722 723 if ( 0 !== $revisions ) { 724 $latest_revision_id = $post->ID; 725 726 for ( $i = 0; $i < $revisions; ++$i ) { 727 wp_update_post( 728 array( 729 'ID' => $post->ID, 730 'post_title' => 'Some Post ' . $i, 731 ) 732 ); 733 734 $latest_revision_id++; 735 } 736 } 737 738 $expected = admin_url( 'revision.php?revision=' . $latest_revision_id ); 739 740 $this->assertSame( 741 $expected, 742 wp_get_post_revisions_url( $post ), 743 'Failed when passed the Post Object' 744 ); 745 746 $this->assertSame( 747 $expected, 748 wp_get_post_revisions_url( $latest_revision_id ), 749 'Failed when passed the latest revision ID' 750 ); 751 } 752 753 /** 754 * Data provider. 755 * 756 * @return array 757 */ 758 public function data_wp_get_post_revisions_url() { 759 return array( 760 'one revision' => array( 'revisions' => 1 ), 761 'multiple revisions' => array( 'revisions' => 2 ), 762 ); 763 } 764 765 /** 766 * Tests that wp_get_post_revisions_url() returns NULL when a post does not exist. 767 * 768 * @ticket 39062 769 * 770 * @covers ::wp_get_post_revisions_url 771 */ 772 public function test_wp_get_post_revisions_url_returns_null_when_post_does_not_exist() { 773 wp_set_current_user( self::$admin_user_id ); 774 $post_id = 99999; 775 $this->assertNull( wp_get_post_revisions_url( $post_id ) ); 776 } 777 778 /** 779 * Tests that wp_get_post_revisions_url() returns NULL when there are no revisions. 780 * 781 * @ticket 39062 782 * 783 * @covers ::wp_get_post_revisions_url 784 */ 785 public function test_wp_get_post_revisions_url_returns_null_with_no_revisions() { 786 wp_set_current_user( self::$admin_user_id ); 787 $post_id = self::factory()->post->create( array( 'post_title' => 'Some Post' ) ); 788 $this->assertNull( wp_get_post_revisions_url( $post_id ) ); 789 } 790 791 /** 792 * Tests that wp_get_post_revisions_url() returns NULL when revisions are disabled. 793 * 794 * @ticket 39062 795 * 796 * @covers ::wp_get_post_revisions_url 797 */ 798 public function test_wp_get_post_revisions_url_returns_null_with_revisions_disabled() { 799 wp_set_current_user( self::$admin_user_id ); 800 801 remove_post_type_support( 'post', 'revisions' ); 802 803 $post_id = self::factory()->post->create( array( 'post_title' => 'Some Post' ) ); 804 805 wp_update_post( 806 array( 807 'ID' => $post_id, 808 'post_title' => 'Some Post 2', 809 ) 810 ); 811 812 $this->assertNull( wp_get_post_revisions_url( $post_id ) ); 813 814 add_post_type_support( 'post', 'revisions' ); 815 } 657 816 }
Note: See TracChangeset
for help on using the changeset viewer.