You appear to be a bot. Output may be restricted
Description
Test save_nav_menus_created_posts.
Usage
Test_WP_Customize_Nav_Menus::test_save_nav_menus_created_posts();
Parameters
Returns
void
Source
File name: wordpress-develop-tests/phpunit/tests/customize/nav-menus.php
Lines:
1 to 100 of 103
public function test_save_nav_menus_created_posts() { $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); do_action( 'customize_register', $this->wp_customize ); $post_ids = array(); // Auto-draft. $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Auto Draft', 'post_type' => 'post', 'post_name' => 'auto-draft-1', ) ); $this->assertInstanceOf( 'WP_Post', $r ); $post_ids[] = $r->ID; // Draft. $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Draft', 'post_type' => 'post', 'post_name' => 'auto-draft-2', ) ); $this->assertInstanceOf( 'WP_Post', $r ); wp_update_post( array( 'ID' => $r->ID, 'post_status' => 'draft', ) ); $post_ids[] = $r->ID; $drafted_post_ids = $post_ids; // Private (this will exclude it from being considered a stub). $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Private', 'post_type' => 'post', 'post_name' => 'auto-draft-3', ) ); $this->assertInstanceOf( 'WP_Post', $r ); wp_update_post( array( 'ID' => $r->ID, 'post_status' => 'private', ) ); $post_ids[] = $r->ID; $private_post_id = $r->ID; // Trashed (this will exclude it from being considered a stub). $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Trash', 'post_type' => 'post', 'post_name' => 'auto-draft-4', ) ); $this->assertInstanceOf( 'WP_Post', $r ); wp_trash_post( $r->ID ); $post_ids[] = $r->ID; $trashed_post_id = $r->ID; $pre_published_post_id = $this->factory()->post->create( array( 'post_status' => 'publish' ) ); $setting_id = 'nav_menus_created_posts'; $this->wp_customize->set_post_value( $setting_id, array_merge( $post_ids, array( $pre_published_post_id ) ) ); $setting = $this->wp_customize->get_setting( $setting_id ); $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $setting ); $this->assertSame( array( $menus, 'sanitize_nav_menus_created_posts' ), $setting->sanitize_callback ); $this->assertSame( $drafted_post_ids, $setting->post_value() ); $this->assertArrayNotHasKey( $private_post_id, $post_ids ); $this->assertArrayNotHasKey( $trashed_post_id, $post_ids ); $this->assertSame( 'auto-draft', get_post_status( $drafted_post_ids[0] ) ); $this->assertSame( 'draft', get_post_status( $drafted_post_ids[1] ) ); foreach ( $drafted_post_ids as $post_id ) { $this->assertEmpty( get_post( $post_id )->post_name ); $this->assertNotEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) ); } $save_action_count = did_action( 'customize_save_nav_menus_created_posts' ); $setting->save(); $this->assertSame( $save_action_count + 1, did_action( 'customize_save_nav_menus_created_posts' ) ); foreach ( $drafted_post_ids as $post_id ) { $this->assertSame( 'publish', get_post_status( $post_id ) ); $this->assertMatchesRegularExpression( '/^auto-draft-\d+$/', get_post( $post_id )->post_name ); $this->assertEmpty( get_post_meta( $post_id, '_customize_draft_post_name', true ) ); } $this->assertSame( 'private', get_post_status( $private_post_id ) ); $this->assertSame( 'trash', get_post_status( $trashed_post_id ) ); // Ensure that unique slugs were assigned. $posts = array_map( 'get_post', $drafted_post_ids ); $post_names = wp_list_pluck( $posts, 'post_name' );