Changeset 41887 for trunk/tests/phpunit/tests/customize/nav-menus.php
- Timestamp:
- 10/17/2017 08:14:56 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/nav-menus.php
r41204 r41887 542 542 $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Non-existent', 'post_type' => 'nonexistent' ) ); 543 543 $this->assertInstanceOf( 'WP_Post', $r ); 544 $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) ); 544 545 545 546 $r = $menus->insert_auto_draft_post( array( 'post_type' => 'post' ) ); … … 556 557 $this->assertEquals( '', $r->post_name ); 557 558 $this->assertEquals( 'hello-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) ); 559 $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) ); 558 560 $this->assertEquals( 'post', $r->post_type ); 559 561 … … 564 566 $this->assertEquals( '', $r->post_name ); 565 567 $this->assertEquals( 'greetings-world', get_post_meta( $r->ID, '_customize_draft_post_name', true ) ); 568 $this->assertEquals( $this->wp_customize->changeset_uuid(), get_post_meta( $r->ID, '_customize_changeset_uuid', true ) ); 566 569 $this->assertEquals( 'Hi World', $r->post_content ); 567 570 } … … 717 720 ) ); 718 721 722 $draft_post_id = $this->factory()->post->create( array( 723 'post_status' => 'draft', 724 'post_title' => 'Draft', 725 'post_author' => $administrator_user_id, 726 ) ); 727 728 $private_post_id = $this->factory()->post->create( array( 729 'post_status' => 'private', 730 'post_title' => 'Private', 731 'post_author' => $administrator_user_id, 732 ) ); 733 719 734 $value = array( 720 735 'bad', … … 722 737 $author_post_id, 723 738 $administrator_post_id, 739 $draft_post_id, 740 $private_post_id, 724 741 ); 725 742 … … 734 751 wp_set_current_user( $administrator_user_id ); 735 752 $sanitized = $menus->sanitize_nav_menus_created_posts( $value ); 736 $this->assertEquals( array( $contributor_post_id, $author_post_id, $administrator_post_id ), $sanitized );753 $this->assertEquals( array( $contributor_post_id, $author_post_id, $administrator_post_id, $draft_post_id ), $sanitized ); 737 754 } 738 755 … … 747 764 748 765 $post_ids = array(); 749 for ( $i = 0; $i < 3; $i += 1 ) { 750 $r = $menus->insert_auto_draft_post( array( 751 'post_title' => 'Auto Draft ' . $i, 752 'post_type' => 'post', 753 'post_name' => 'auto-draft-' . $i, 754 ) ); 755 $this->assertInstanceOf( 'WP_Post', $r ); 756 $post_ids[] = $r->ID; 757 } 766 767 // Auto-draft. 768 $r = $menus->insert_auto_draft_post( array( 769 'post_title' => 'Auto Draft', 770 'post_type' => 'post', 771 'post_name' => 'auto-draft-1', 772 ) ); 773 $this->assertInstanceOf( 'WP_Post', $r ); 774 $post_ids[] = $r->ID; 775 776 // Draft. 777 $r = $menus->insert_auto_draft_post( array( 778 'post_title' => 'Draft', 779 'post_type' => 'post', 780 'post_name' => 'auto-draft-2', 781 ) ); 782 $this->assertInstanceOf( 'WP_Post', $r ); 783 wp_update_post( array( 784 'ID' => $r->ID, 785 'post_status' => 'draft', 786 ) ); 787 $post_ids[] = $r->ID; 788 789 $drafted_post_ids = $post_ids; 790 791 // Private (this will exclude it from being considered a stub). 792 $r = $menus->insert_auto_draft_post( array( 793 'post_title' => 'Private', 794 'post_type' => 'post', 795 'post_name' => 'auto-draft-3', 796 ) ); 797 $this->assertInstanceOf( 'WP_Post', $r ); 798 wp_update_post( array( 799 'ID' => $r->ID, 800 'post_status' => 'private', 801 ) ); 802 $post_ids[] = $r->ID; 803 $private_post_id = $r->ID; 804 805 // Trashed (this will exclude it from being considered a stub). 806 $r = $menus->insert_auto_draft_post( array( 807 'post_title' => 'Trash', 808 'post_type' => 'post', 809 'post_name' => 'auto-draft-4', 810 ) ); 811 $this->assertInstanceOf( 'WP_Post', $r ); 812 wp_trash_post( $r->ID ); 813 $post_ids[] = $r->ID; 814 $trashed_post_id = $r->ID; 758 815 759 816 $pre_published_post_id = $this->factory()->post->create( array( 'post_status' => 'publish' ) ); … … 764 821 $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $setting ); 765 822 $this->assertEquals( array( $menus, 'sanitize_nav_menus_created_posts' ), $setting->sanitize_callback ); 766 $this->assertEquals( $post_ids, $setting->post_value() ); 767 foreach ( $post_ids as $post_id ) { 768 $this->assertEquals( 'auto-draft', get_post_status( $post_id ) ); 823 $this->assertEquals( $drafted_post_ids, $setting->post_value() ); 824 $this->assertArrayNotHasKey( $private_post_id, $post_ids ); 825 $this->assertArrayNotHasKey( $trashed_post_id, $post_ids ); 826 827 $this->assertEquals( 'auto-draft', get_post_status( $drafted_post_ids[0] ) ); 828 $this->assertEquals( 'draft', get_post_status( $drafted_post_ids[1] ) ); 829 foreach ( $drafted_post_ids as $post_id ) { 769 830 $this->assertEmpty( get_post( $post_id )->post_name ); 770 831 $this->assertNotEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) ); … … 774 835 $setting->save(); 775 836 $this->assertEquals( $save_action_count + 1, did_action( 'customize_save_nav_menus_created_posts' ) ); 776 foreach ( $ post_ids as $post_id ) {837 foreach ( $drafted_post_ids as $post_id ) { 777 838 $this->assertEquals( 'publish', get_post_status( $post_id ) ); 778 839 $this->assertRegExp( '/^auto-draft-\d+$/', get_post( $post_id )->post_name ); … … 780 841 } 781 842 843 $this->assertEquals( 'private', get_post_status( $private_post_id ) ); 844 $this->assertEquals( 'trash', get_post_status( $trashed_post_id ) ); 845 782 846 // Ensure that unique slugs were assigned. 783 $posts = array_map( 'get_post', $ post_ids );847 $posts = array_map( 'get_post', $drafted_post_ids ); 784 848 $post_names = wp_list_pluck( $posts, 'post_name' ); 785 849 $this->assertEqualSets( $post_names, array_unique( $post_names ) );
Note: See TracChangeset
for help on using the changeset viewer.