mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Customize: Ensure that WP_Customize_Manager::import_theme_starter_content() properly handles starter content with (nested) arrays as values.
Previously, searching for symbol references to replace with post or attachment IDs in array values resulted in a PHP warning. Props timph, JarretC, SergeyBiryukov. Fixes #45484. git-svn-id: https://develop.svn.wordpress.org/trunk@46548 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -741,7 +741,8 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
// Ensure that re-importing doesn't cause auto-drafts to balloon.
|
||||
$wp_customize->import_theme_starter_content();
|
||||
$changeset_data = $wp_customize->changeset_data();
|
||||
$this->assertEqualSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'] ); // Auto-drafts should not get re-created and amended with each import.
|
||||
// Auto-drafts should not get re-created and amended with each import.
|
||||
$this->assertEqualSets( array_values( $posts_by_name ), $changeset_data['nav_menus_created_posts']['value'] );
|
||||
|
||||
// Test that saving non-starter content on top of the changeset clears the starter_content flag.
|
||||
$wp_customize->save_changeset_post(
|
||||
@@ -755,7 +756,10 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
$this->assertArrayNotHasKey( 'starter_content', $changeset_data['blogname'] );
|
||||
$this->assertArrayHasKey( 'starter_content', $changeset_data['blogdescription'] );
|
||||
|
||||
// Test that adding blogname starter content is ignored now that it is modified, but updating a non-modified starter content blog description passes.
|
||||
/*
|
||||
* Test that adding blogname starter content is ignored now that it is modified,
|
||||
* but updating a non-modified starter content blog description passes.
|
||||
*/
|
||||
$previous_blogname = $changeset_data['blogname']['value'];
|
||||
$previous_blogdescription = $changeset_data['blogdescription']['value'];
|
||||
$wp_customize->import_theme_starter_content(
|
||||
@@ -800,6 +804,80 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
$this->assertEmpty( get_post_meta( $posts_by_name['waffles'], '_customize_draft_post_name', true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test WP_Customize_Manager::import_theme_starter_content() with nested arrays.
|
||||
*
|
||||
* @ticket 45484
|
||||
* @covers WP_Customize_Manager::import_theme_starter_content()
|
||||
*/
|
||||
function test_import_theme_starter_content_with_nested_arrays() {
|
||||
wp_set_current_user( self::$admin_user_id );
|
||||
|
||||
$existing_published_home_page_id = $this->factory()->post->create(
|
||||
array(
|
||||
'post_name' => 'home',
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
)
|
||||
);
|
||||
|
||||
global $wp_customize;
|
||||
$wp_customize = new WP_Customize_Manager();
|
||||
$starter_content_config = array(
|
||||
'posts' => array(
|
||||
'home',
|
||||
),
|
||||
'options' => array(
|
||||
'array_option' => array(
|
||||
0,
|
||||
1,
|
||||
'home_page_id' => '{{home}}',
|
||||
),
|
||||
'nested_array_option' => array(
|
||||
0,
|
||||
1,
|
||||
array(
|
||||
2,
|
||||
'home_page_id' => '{{home}}',
|
||||
),
|
||||
),
|
||||
),
|
||||
'theme_mods' => array(
|
||||
'array_theme_mod' => array(
|
||||
0,
|
||||
1,
|
||||
'home_page_id' => '{{home}}',
|
||||
),
|
||||
'nested_array_theme_mod' => array(
|
||||
0,
|
||||
1,
|
||||
array(
|
||||
2,
|
||||
'home_page_id' => '{{home}}',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
add_theme_support( 'starter-content', $starter_content_config );
|
||||
$this->assertEmpty( $wp_customize->unsanitized_post_values() );
|
||||
$wp_customize->import_theme_starter_content();
|
||||
$changeset_values = $wp_customize->unsanitized_post_values();
|
||||
$expected_setting_ids = array(
|
||||
'array_option',
|
||||
'array_theme_mod',
|
||||
'nav_menus_created_posts',
|
||||
'nested_array_option',
|
||||
'nested_array_theme_mod',
|
||||
);
|
||||
$this->assertEqualSets( $expected_setting_ids, array_keys( $changeset_values ) );
|
||||
|
||||
$this->assertSame( $existing_published_home_page_id, $changeset_values['array_option']['home_page_id'] );
|
||||
$this->assertSame( $existing_published_home_page_id, $changeset_values['nested_array_option'][2]['home_page_id'] );
|
||||
$this->assertSame( $existing_published_home_page_id, $changeset_values['array_theme_mod']['home_page_id'] );
|
||||
$this->assertSame( $existing_published_home_page_id, $changeset_values['nested_array_theme_mod'][2]['home_page_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test WP_Customize_Manager::customize_preview_init().
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user