@@ -541,6 +541,7 @@ public function test_insert_auto_draft_post() {
541541 // Non-existent post types allowed as of #39610.
542542 $ r = $ menus ->insert_auto_draft_post ( array ( 'post_title ' => 'Non-existent ' , 'post_type ' => 'nonexistent ' ) );
543543 $ this ->assertInstanceOf ( 'WP_Post ' , $ r );
544+ $ this ->assertEquals ( $ this ->wp_customize ->changeset_uuid (), get_post_meta ( $ r ->ID , '_customize_changeset_uuid ' , true ) );
544545
545546 $ r = $ menus ->insert_auto_draft_post ( array ( 'post_type ' => 'post ' ) );
546547 $ this ->assertInstanceOf ( 'WP_Error ' , $ r );
@@ -555,6 +556,7 @@ public function test_insert_auto_draft_post() {
555556 $ this ->assertEquals ( 'Hello World ' , $ r ->post_title );
556557 $ this ->assertEquals ( '' , $ r ->post_name );
557558 $ 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 ) );
558560 $ this ->assertEquals ( 'post ' , $ r ->post_type );
559561
560562 $ r = $ menus ->insert_auto_draft_post ( array ( 'post_title ' => 'Hello World ' , 'post_type ' => 'post ' , 'post_name ' => 'greetings-world ' , 'post_content ' => 'Hi World ' ) );
@@ -563,6 +565,7 @@ public function test_insert_auto_draft_post() {
563565 $ this ->assertEquals ( 'post ' , $ r ->post_type );
564566 $ this ->assertEquals ( '' , $ r ->post_name );
565567 $ 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 ) );
566569 $ this ->assertEquals ( 'Hi World ' , $ r ->post_content );
567570 }
568571
@@ -716,11 +719,25 @@ function test_sanitize_nav_menus_created_posts() {
716719 'post_author ' => $ administrator_user_id ,
717720 ) );
718721
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+
719734 $ value = array (
720735 'bad ' ,
721736 $ contributor_post_id ,
722737 $ author_post_id ,
723738 $ administrator_post_id ,
739+ $ draft_post_id ,
740+ $ private_post_id ,
724741 );
725742
726743 wp_set_current_user ( $ contributor_user_id );
@@ -733,7 +750,7 @@ function test_sanitize_nav_menus_created_posts() {
733750
734751 wp_set_current_user ( $ administrator_user_id );
735752 $ 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 );
737754 }
738755
739756 /**
@@ -746,15 +763,55 @@ function test_save_nav_menus_created_posts() {
746763 do_action ( 'customize_register ' , $ this ->wp_customize );
747764
748765 $ 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 ;
758815
759816 $ pre_published_post_id = $ this ->factory ()->post ->create ( array ( 'post_status ' => 'publish ' ) );
760817
@@ -763,24 +820,31 @@ function test_save_nav_menus_created_posts() {
763820 $ setting = $ this ->wp_customize ->get_setting ( $ setting_id );
764821 $ this ->assertInstanceOf ( 'WP_Customize_Filter_Setting ' , $ setting );
765822 $ 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 ) {
769830 $ this ->assertEmpty ( get_post ( $ post_id )->post_name );
770831 $ this ->assertNotEmpty ( get_post_meta ( $ post_id , '_customize_draft_post_name ' , true ) );
771832 }
772833
773834 $ save_action_count = did_action ( 'customize_save_nav_menus_created_posts ' );
774835 $ setting ->save ();
775836 $ 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 ) {
777838 $ this ->assertEquals ( 'publish ' , get_post_status ( $ post_id ) );
778839 $ this ->assertRegExp ( '/^auto-draft-\d+$/ ' , get_post ( $ post_id )->post_name );
779840 $ this ->assertEmpty ( get_post_meta ( $ post_id , '_customize_draft_post_name ' , true ) );
780841 }
781842
843+ $ this ->assertEquals ( 'private ' , get_post_status ( $ private_post_id ) );
844+ $ this ->assertEquals ( 'trash ' , get_post_status ( $ trashed_post_id ) );
845+
782846 // Ensure that unique slugs were assigned.
783- $ posts = array_map ( 'get_post ' , $ post_ids );
847+ $ posts = array_map ( 'get_post ' , $ drafted_post_ids );
784848 $ post_names = wp_list_pluck ( $ posts , 'post_name ' );
785849 $ this ->assertEqualSets ( $ post_names , array_unique ( $ post_names ) );
786850 }
0 commit comments