Ticket #36389: 36389.2.diff
| File 36389.2.diff, 6.6 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/class-wp-customize-setting.php
diff --git src/wp-includes/class-wp-customize-setting.php src/wp-includes/class-wp-customize-setting.php index 9f72966..d179999 100644
class WP_Customize_Setting { 207 207 } 208 208 209 209 /** 210 * Reset `$aggregated_multidimensionals` static variable. 211 * 212 * This is used by unit tests. It should not be used generally. 213 * 214 * @since 4.5.0 215 * @access public 216 */ 217 static public function reset_aggregated_multidimensionals() { 218 self::$aggregated_multidimensionals = array(); 219 } 220 221 /** 210 222 * The ID for the current site when the preview() method was called. 211 223 * 212 224 * @since 4.2.0 -
src/wp-includes/class-wp-customize-widgets.php
diff --git src/wp-includes/class-wp-customize-widgets.php src/wp-includes/class-wp-customize-widgets.php index 0b7b7ce..0a73953 100644
final class WP_Customize_Widgets { 99 99 } 100 100 101 101 add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_customize_dynamic_setting_args' ), 10, 2 ); 102 add_action( ' after_setup_theme', array( $this, 'register_settings' ));102 add_action( 'widgets_init', array( $this, 'register_settings' ), 95 ); 103 103 add_action( 'wp_loaded', array( $this, 'override_sidebars_widgets_for_theme_switch' ) ); 104 104 add_action( 'customize_controls_init', array( $this, 'customize_controls_init' ) ); 105 105 add_action( 'customize_register', array( $this, 'schedule_customize_register' ), 1 ); … … final class WP_Customize_Widgets { 376 376 public function customize_register() { 377 377 global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_sidebars; 378 378 379 add_filter( 'sidebars_widgets', array( $this, 'preview_sidebars_widgets' ), 1 ); 380 379 381 $sidebars_widgets = array_merge( 380 382 array( 'wp_inactive_widgets' => array() ), 381 383 array_fill_keys( array_keys( $wp_registered_sidebars ), array() ), … … final class WP_Customize_Widgets { 509 511 $this->manager->get_setting( $new_setting_id )->preview(); 510 512 } 511 513 } 512 513 add_filter( 'sidebars_widgets', array( $this, 'preview_sidebars_widgets' ), 1 );514 514 } 515 515 516 516 /** -
tests/phpunit/tests/customize/widgets.php
diff --git tests/phpunit/tests/customize/widgets.php tests/phpunit/tests/customize/widgets.php index 28392fd..7994cc8 100644
class Tests_WP_Customize_Widgets extends WP_UnitTestCase { 46 46 remove_action( 'customize_register', 'twentysixteen_customize_register', 11 ); 47 47 48 48 $this->backup_registered_sidebars = $GLOBALS['wp_registered_sidebars']; 49 50 // Reset protected static var on class. 51 WP_Customize_Setting::reset_aggregated_multidimensionals(); 49 52 } 50 53 51 54 function clean_up_global_scope() { … … class Tests_WP_Customize_Widgets extends WP_UnitTestCase { 70 73 71 74 function set_customized_post_data( $customized ) { 72 75 $_POST['customized'] = wp_slash( wp_json_encode( $customized ) ); 76 if ( $this->manager ) { 77 foreach ( $customized as $id => $value ) { 78 $this->manager->set_post_value( $id, $value ); 79 } 80 } 73 81 } 74 82 75 83 function do_customize_boot_actions() { … … class Tests_WP_Customize_Widgets extends WP_UnitTestCase { 150 158 } 151 159 152 160 /** 153 * Test WP_Customize_Widgets::register_settings() 161 * Test WP_Customize_Widgets::register_settings() with selective refresh enabled. 154 162 * 155 163 * @ticket 30988 164 * @group trac-36389 156 165 */ 157 166 function test_register_settings() { 167 add_theme_support( 'customize-selective-refresh-widgets' ); 158 168 159 169 $raw_widget_customized = array( 160 170 'widget_categories[2]' => array( … … class Tests_WP_Customize_Widgets extends WP_UnitTestCase { 176 186 $this->do_customize_boot_actions(); 177 187 $this->assertTrue( is_customize_preview() ); 178 188 179 $this->assertNotEmpty( $this->manager->get_setting( 'widget_categories[2]' ), 'Expected setting for pre-existing widget category-2, being customized.' ); 180 $this->assertNotEmpty( $this->manager->get_setting( 'widget_search[2]' ), 'Expected setting for pre-existing widget search-2, not being customized.' ); 181 $this->assertNotEmpty( $this->manager->get_setting( 'widget_search[3]' ), 'Expected dynamic setting for non-existing widget search-3, being customized.' ); 189 if ( current_theme_supports( 'customize-selective-refresh-widgets' ) ) { 190 $expected_transport = 'postMessage'; 191 $this->assertNotEmpty( $this->manager->widgets->get_selective_refreshable_widgets() ); 192 } else { 193 $expected_transport = 'refresh'; 194 $this->assertEmpty( $this->manager->widgets->get_selective_refreshable_widgets() ); 195 } 196 197 $setting = $this->manager->get_setting( 'widget_categories[2]' ); 198 $this->assertNotEmpty( $setting, 'Expected setting for pre-existing widget category-2, being customized.' ); 199 $this->assertEquals( $expected_transport, $setting->transport ); 200 201 $setting = $this->manager->get_setting( 'widget_search[2]' ); 202 $this->assertNotEmpty( $setting, 'Expected setting for pre-existing widget search-2, not being customized.' ); 203 $this->assertEquals( $expected_transport, $setting->transport ); 204 205 $setting = $this->manager->get_setting( 'widget_search[3]' ); 206 $this->assertNotEmpty( $setting, 'Expected dynamic setting for non-existing widget search-3, being customized.' ); 207 $this->assertEquals( $expected_transport, $setting->transport ); 182 208 183 209 $widget_categories = get_option( 'widget_categories' ); 184 210 $this->assertEquals( $raw_widget_customized['widget_categories[2]'], $widget_categories[2], 'Expected $wp_customize->get_setting(widget_categories[2])->preview() to have been called.' ); 185 211 } 186 212 187 213 /** 214 * Test registering settings without selective refresh enabled. 215 * 216 * @ticket 36389 217 * @group trac-36389 218 */ 219 function test_register_settings_without_selective_refresh() { 220 remove_theme_support( 'customize-selective-refresh-widgets' ); 221 $this->test_register_settings(); 222 } 223 224 /** 225 * Test registering settings with selective refresh enabled at a late after_setup_theme action. 226 * 227 * @ticket 36389 228 * @group trac-36389 229 */ 230 function test_register_settings_with_late_theme_support_added() { 231 remove_theme_support( 'customize-selective-refresh-widgets' ); 232 add_action( 'after_setup_theme', array( $this, 'add_customize_selective_refresh_theme_support' ), 100 ); 233 $this->test_register_settings(); 234 } 235 236 /** 237 * Add customize-selective-refresh-widgets theme support. 238 */ 239 function add_customize_selective_refresh_theme_support() { 240 add_theme_support( 'customize-selective-refresh-widgets' ); 241 } 242 243 /** 188 244 * Test WP_Customize_Widgets::get_setting_args() 189 245 */ 190 246 function test_get_setting_args() {