| | 744 | * Test import_theme_starter_content() should support post_parent. |
| | 745 | * |
| | 746 | * @covers WP_Customize_Manager::import_theme_starter_content() |
| | 747 | * @ticket 40807 |
| | 748 | */ |
| | 749 | public function test_import_theme_starter_content_should_support_post_parent() { |
| | 750 | wp_set_current_user( self::$admin_user_id ); |
| | 751 | |
| | 752 | global $wp_customize; |
| | 753 | $wp_customize = new WP_Customize_Manager(); |
| | 754 | |
| | 755 | $starter_content_config = array( |
| | 756 | 'posts' => array( |
| | 757 | 'animal' => array( |
| | 758 | 'post_type' => 'page', |
| | 759 | 'post_title' => 'Animal', |
| | 760 | ), |
| | 761 | 'bird' => array( |
| | 762 | 'post_type' => 'page', |
| | 763 | 'post_title' => 'Bird', |
| | 764 | 'parent' => '{{animal}}', |
| | 765 | ), |
| | 766 | 'owl' => array( |
| | 767 | 'post_type' => 'page', |
| | 768 | 'post_title' => 'Owl', |
| | 769 | 'parent' => '{{birds}}', // Non-existing post symbol that should result in post_parent as 0. |
| | 770 | ), |
| | 771 | 'salmon' => array( |
| | 772 | 'post_type' => 'page', |
| | 773 | 'post_title' => 'Salmon', |
| | 774 | 'parent' => '{{fish}}', |
| | 775 | ), |
| | 776 | /* It shouldn't matter if the parent is defined after the child */ |
| | 777 | 'fish' => array( |
| | 778 | 'post_type' => 'page', |
| | 779 | 'post_title' => 'Fish', |
| | 780 | 'parent' => '{{animal}}', |
| | 781 | ), |
| | 782 | ), |
| | 783 | ); |
| | 784 | |
| | 785 | add_theme_support( 'starter-content', $starter_content_config ); |
| | 786 | $this->assertEmpty( $wp_customize->unsanitized_post_values() ); |
| | 787 | $wp_customize->import_theme_starter_content(); |
| | 788 | $changeset_values = $wp_customize->unsanitized_post_values(); |
| | 789 | |
| | 790 | $posts_by_name = array(); |
| | 791 | foreach ( $changeset_values['nav_menus_created_posts'] as $post_id ) { |
| | 792 | $post = get_post( $post_id ); |
| | 793 | $post_name = $post->post_name; |
| | 794 | if ( empty( $post_name ) ) { |
| | 795 | $post_name = get_post_meta( $post->ID, '_customize_draft_post_name', true ); |
| | 796 | } |
| | 797 | $posts_by_name[ $post_name ] = $post->ID; |
| | 798 | } |
| | 799 | |
| | 800 | $this->assertSame( $posts_by_name['animal'], get_post_field( 'post_parent', $posts_by_name['bird'] ) ); |
| | 801 | $this->assertSame( $posts_by_name['animal'], get_post_field( 'post_parent', $posts_by_name['fish'] ) ); |
| | 802 | $this->assertSame( $posts_by_name['fish'], get_post_field( 'post_parent', $posts_by_name['salmon'] ) ); |
| | 803 | $this->assertSame( 0, get_post_field( 'post_parent', $posts_by_name['animal'] ) ); |
| | 804 | $this->assertSame( 0, get_post_field( 'post_parent', $posts_by_name['owl'] ) ); |
| | 805 | } |
| | 806 | |
| | 807 | /** |