Changeset 35724
- Timestamp:
- 11/21/2015 02:51:57 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-manager.php
r35718 r35724 660 660 $this->unsanitized_post_values(); 661 661 $this->_post_values[ $setting_id ] = $value; 662 663 /** 664 * Announce when a specific setting's unsanitized post value has been set. 665 * 666 * Fires when the {@see WP_Customize_Manager::set_post_value()} method is called. 667 * 668 * The dynamic portion of the hook name, `$setting_id`, refers to the setting ID. 669 * 670 * @since 4.4.0 671 * 672 * @param mixed $value Unsanitized setting post value. 673 * @param WP_Customize_Manager $this WP_Customize_Manager instance. 674 */ 675 do_action( "customize_post_value_set_{$setting_id}", $value, $this ); 676 677 /** 678 * Announce when any setting's unsanitized post value has been set. 679 * 680 * Fires when the {@see WP_Customize_Manager::set_post_value()} method is called. 681 * 682 * This is useful for <code>WP_Customize_Setting</code> instances to watch 683 * in order to update a cached previewed value. 684 * 685 * @since 4.4.0 686 * 687 * @param string $setting_id Setting ID. 688 * @param mixed $value Unsanitized setting post value. 689 * @param WP_Customize_Manager $this WP_Customize_Manager instance. 690 */ 691 do_action( 'customize_post_value_set', $setting_id, $value, $this ); 662 692 } 663 693 -
trunk/src/wp-includes/class-wp-customize-setting.php
r35383 r35724 83 83 84 84 /** 85 * Whether or not preview() was called. 86 * 87 * @since 4.4.0 88 * @access protected 89 * @var bool 90 */ 91 protected $is_previewed = false; 92 93 /** 85 94 * Cache of multidimensional values to improve performance. 86 95 * … … 192 201 193 202 if ( ! empty( $this->id_data['keys'] ) ) { 203 // Note the preview-applied flag is cleared at priority 9 to ensure it is cleared before a deferred-preview runs. 204 add_action( "customize_post_value_set_{$this->id}", array( $this, '_clear_aggregated_multidimensional_preview_applied_flag' ), 9 ); 194 205 $this->is_multidimensional_aggregated = true; 195 206 } … … 246 257 $this->_previewed_blog_id = get_current_blog_id(); 247 258 } 259 260 // Prevent re-previewing an already-previewed setting. 261 if ( $this->is_previewed ) { 262 return true; 263 } 264 248 265 $id_base = $this->id_data['base']; 249 266 $is_multidimensional = ! empty( $this->id_data['keys'] ); … … 274 291 } 275 292 293 // If the setting does not need previewing now, defer to when it has a value to preview. 276 294 if ( ! $needs_preview ) { 295 if ( ! has_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) ) ) { 296 add_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) ); 297 } 277 298 return false; 278 299 } … … 328 349 do_action( "customize_preview_{$this->type}", $this ); 329 350 } 351 352 $this->is_previewed = true; 353 330 354 return true; 355 } 356 357 /** 358 * Clear out the previewed-applied flag for a multidimensional-aggregated value whenever its post value is updated. 359 * 360 * This ensures that the new value will get sanitized and used the next time 361 * that <code>WP_Customize_Setting::_multidimensional_preview_filter()</code> 362 * is called for this setting. 363 * 364 * @since 4.4.0 365 * @access private 366 * @see WP_Customize_Manager::set_post_value() 367 * @see WP_Customize_Setting::_multidimensional_preview_filter() 368 */ 369 final public function _clear_aggregated_multidimensional_preview_applied_flag() { 370 unset( self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['preview_applied_instances'][ $this->id ] ); 331 371 } 332 372 … … 370 410 * 371 411 * @since 4.4.0 372 * @access p ublic412 * @access private 373 413 * 374 414 * @see WP_Customize_Setting::$aggregated_multidimensionals … … 376 416 * @return mixed New or old value. 377 417 */ 378 public function _multidimensional_preview_filter( $original ) {418 final public function _multidimensional_preview_filter( $original ) { 379 419 if ( ! $this->is_current_blog_previewed() ) { 380 420 return $original; -
trunk/src/wp-includes/class-wp-customize-widgets.php
r35381 r35724 1381 1381 * instead of the default widget instance value (an empty array). 1382 1382 */ 1383 $this->manager->set_post_value( $setting_id, $ instance);1383 $this->manager->set_post_value( $setting_id, $this->sanitize_widget_js_instance( $instance ) ); 1384 1384 1385 1385 // Obtain the widget control with the updated instance in place. -
trunk/src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php
r35580 r35724 119 119 */ 120 120 public $original_nav_menu_term_id; 121 122 /**123 * Whether or not preview() was called.124 *125 * @since 4.3.0126 * @access protected127 * @var bool128 */129 protected $is_previewed = false;130 121 131 122 /** -
trunk/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php
r35385 r35724 90 90 91 91 /** 92 * Whether or not preview() was called.93 *94 * @since 4.3.095 * @access protected96 * @var bool97 */98 protected $is_previewed = false;99 100 /**101 92 * Whether or not update() was called. 102 93 * -
trunk/tests/phpunit/tests/customize/manager.php
r35635 r35724 33 33 parent::setUp(); 34 34 require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); 35 $GLOBALS['wp_customize'] = new WP_Customize_Manager(); 36 $this->manager = $GLOBALS['wp_customize']; 35 $this->manager = $this->instantiate(); 37 36 $this->undefined = new stdClass(); 38 37 } … … 67 66 } 68 67 69 $manager = $this-> instantiate();68 $manager = $this->manager; 70 69 $this->assertTrue( $manager->doing_ajax() ); 71 70 … … 83 82 } 84 83 85 $manager = $this-> instantiate();84 $manager = $this->manager; 86 85 $this->assertFalse( $manager->doing_ajax() ); 87 86 } … … 93 92 */ 94 93 function test_unsanitized_post_values() { 95 $manager = $this-> instantiate();94 $manager = $this->manager; 96 95 97 96 $customized = array( … … 115 114 $_POST['customized'] = wp_slash( wp_json_encode( $posted_settings ) ); 116 115 117 $manager = $this-> instantiate();116 $manager = $this->manager; 118 117 119 118 $manager->add_setting( 'foo', array( 'default' => 'foo_default' ) ); … … 128 127 129 128 /** 129 * Test WP_Customize_Manager::set_post_value(). 130 * 131 * @see WP_Customize_Manager::set_post_value() 132 */ 133 function test_set_post_value() { 134 $this->manager->add_setting( 'foo', array( 135 'sanitize_callback' => array( $this, 'sanitize_foo_for_test_set_post_value' ), 136 ) ); 137 $setting = $this->manager->get_setting( 'foo' ); 138 139 $this->assertEmpty( $this->captured_customize_post_value_set_actions ); 140 add_action( 'customize_post_value_set', array( $this, 'capture_customize_post_value_set_actions' ), 10, 3 ); 141 add_action( 'customize_post_value_set_foo', array( $this, 'capture_customize_post_value_set_actions' ), 10, 2 ); 142 $this->manager->set_post_value( $setting->id, '123abc' ); 143 $this->assertCount( 2, $this->captured_customize_post_value_set_actions ); 144 $this->assertEquals( 'customize_post_value_set_foo', $this->captured_customize_post_value_set_actions[0]['action'] ); 145 $this->assertEquals( 'customize_post_value_set', $this->captured_customize_post_value_set_actions[1]['action'] ); 146 $this->assertEquals( array( '123abc', $this->manager ), $this->captured_customize_post_value_set_actions[0]['args'] ); 147 $this->assertEquals( array( $setting->id, '123abc', $this->manager ), $this->captured_customize_post_value_set_actions[1]['args'] ); 148 149 $unsanitized = $this->manager->unsanitized_post_values(); 150 $this->assertArrayHasKey( $setting->id, $unsanitized ); 151 152 $this->assertEquals( '123abc', $unsanitized[ $setting->id ] ); 153 $this->assertEquals( 123, $setting->post_value() ); 154 } 155 156 /** 157 * Sanitize a value for Tests_WP_Customize_Manager::test_set_post_value(). 158 * 159 * @see Tests_WP_Customize_Manager::test_set_post_value() 160 * 161 * @param mixed $value Value. 162 * @return int Value. 163 */ 164 function sanitize_foo_for_test_set_post_value( $value ) { 165 return intval( $value ); 166 } 167 168 /** 169 * Store data coming from customize_post_value_set action calls. 170 * 171 * @see Tests_WP_Customize_Manager::capture_customize_post_value_set_actions() 172 * @var array 173 */ 174 protected $captured_customize_post_value_set_actions = array(); 175 176 /** 177 * Capture the actions fired when calling WP_Customize_Manager::set_post_value(). 178 * 179 * @see Tests_WP_Customize_Manager::test_set_post_value() 180 */ 181 function capture_customize_post_value_set_actions() { 182 $action = current_action(); 183 $args = func_get_args(); 184 $this->captured_customize_post_value_set_actions[] = compact( 'action', 'args' ); 185 } 186 187 /** 130 188 * Test the WP_Customize_Manager::add_dynamic_settings() method. 131 189 * … … 133 191 */ 134 192 function test_add_dynamic_settings() { 135 $manager = $this-> instantiate();193 $manager = $this->manager; 136 194 $setting_ids = array( 'foo', 'bar' ); 137 195 $manager->add_setting( 'foo', array( 'default' => 'foo_default' ) ); … … 163 221 add_action( 'customize_register', array( $this, 'action_customize_register_for_dynamic_settings' ) ); 164 222 165 $manager = $this-> instantiate();223 $manager = $this->manager; 166 224 $manager->add_setting( 'foo', array( 'default' => 'foo_default' ) ); 167 225 -
trunk/tests/phpunit/tests/customize/setting.php
r35305 r35724 95 95 $_POST['customized'] = wp_slash( wp_json_encode( $this->post_data_overrides ) ); 96 96 97 // Try non-multidimensional settings 97 // Try non-multidimensional settings. 98 98 foreach ( $this->standard_type_configs as $type => $type_options ) { 99 // Non-multidimensional: See what effect the preview filter has on a non-existent setting (default value should be seen) 99 // Non-multidimensional: See what effect the preview filter has on a non-existent setting (default value should be seen). 100 100 $name = "unset_{$type}_without_post_value"; 101 101 $default = "default_value_{$name}"; … … 107 107 $this->assertEquals( $default, $setting->value() ); 108 108 109 // Non-multidimensional: See what effect the preview has on an extant setting (default value should not be seen) 109 // Non-multidimensional: See what effect the preview has on an extant setting (default value should not be seen). 110 110 $name = "set_{$type}_without_post_value"; 111 111 $default = "default_value_{$name}"; … … 116 116 $this->assertEquals( $initial_value, $setting->value() ); 117 117 $this->assertFalse( $setting->preview(), 'Preview should no-op since setting value was extant and no post value was present.' ); 118 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // only applicable for custom types (not options or theme_mods)119 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // only applicable for custom types (not options or theme_mods)118 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // Only applicable for custom types (not options or theme_mods). 119 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // Only applicable for custom types (not options or theme_mods). 120 120 $this->assertEquals( $initial_value, call_user_func( $type_options['getter'], $name ) ); 121 121 $this->assertEquals( $initial_value, $setting->value() ); 122 122 123 // Non-multidimensional: Try updating a value that had a no-op preview. 123 124 $overridden_value = "overridden_value_$name"; 124 125 call_user_func( $type_options['setter'], $name, $overridden_value ); … … 128 129 $this->assertNotEquals( $initial_value, $setting->value(), $message ); 129 130 130 // Non-multidimensional: Test unset setting being overridden by a post value 131 // Non-multidimensional: Ensure that setting a post value *after* preview() is called results in the post value being seen (deferred preview). 132 $post_value = "post_value_for_{$setting->id}_set_after_preview_called"; 133 $this->assertEquals( 0, did_action( "customize_post_value_set_{$setting->id}" ) ); 134 $this->manager->set_post_value( $setting->id, $post_value ); 135 $this->assertEquals( 1, did_action( "customize_post_value_set_{$setting->id}" ) ); 136 $this->assertNotEquals( $overridden_value, $setting->value() ); 137 $this->assertEquals( $post_value, call_user_func( $type_options['getter'], $name ) ); 138 $this->assertEquals( $post_value, $setting->value() ); 139 140 // Non-multidimensional: Test unset setting being overridden by a post value. 131 141 $name = "unset_{$type}_overridden"; 132 142 $default = "default_value_{$name}"; … … 134 144 $this->assertEquals( $this->undefined, call_user_func( $type_options['getter'], $name, $this->undefined ) ); 135 145 $this->assertEquals( $default, $setting->value() ); 136 $this->assertTrue( $setting->preview(), 'Preview applies because setting has post_data_overrides.' ); // activate post_data146 $this->assertTrue( $setting->preview(), 'Preview applies because setting has post_data_overrides.' ); // Activate post_data. 137 147 $this->assertEquals( $this->post_data_overrides[ $name ], call_user_func( $type_options['getter'], $name, $this->undefined ) ); 138 148 $this->assertEquals( $this->post_data_overrides[ $name ], $setting->value() ); 139 149 140 // Non-multidimensional: Test set setting being overridden by a post value 150 // Non-multidimensional: Test set setting being overridden by a post value. 141 151 $name = "set_{$type}_overridden"; 142 152 $default = "default_value_{$name}"; … … 146 156 $this->assertEquals( $initial_value, call_user_func( $type_options['getter'], $name, $this->undefined ) ); 147 157 $this->assertEquals( $initial_value, $setting->value() ); 148 $this->assertTrue( $setting->preview(), 'Preview applies because setting has post_data_overrides.' ); // activate post_data149 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // only applicable for custom types (not options or theme_mods)150 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // only applicable for custom types (not options or theme_mods)158 $this->assertTrue( $setting->preview(), 'Preview applies because setting has post_data_overrides.' ); // Activate post_data. 159 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // Only applicable for custom types (not options or theme_mods). 160 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // Only applicable for custom types (not options or theme_mods). 151 161 $this->assertEquals( $this->post_data_overrides[ $name ], call_user_func( $type_options['getter'], $name, $this->undefined ) ); 152 162 $this->assertEquals( $this->post_data_overrides[ $name ], $setting->value() ); … … 156 166 /** 157 167 * Run assertions on multidimensional standard settings. 168 * 169 * @see WP_Customize_Setting::preview() 158 170 */ 159 171 function test_preview_standard_types_multidimensional() { … … 161 173 162 174 foreach ( $this->standard_type_configs as $type => $type_options ) { 163 // Multidimensional: See what effect the preview filter has on a non-existent setting (default value should be seen) 175 // Multidimensional: See what effect the preview filter has on a non-existent setting (default value should be seen). 164 176 $base_name = "unset_{$type}_multi"; 165 177 $name = $base_name . '[foo]'; … … 168 180 $this->assertEquals( $this->undefined, call_user_func( $type_options['getter'], $base_name, $this->undefined ) ); 169 181 $this->assertEquals( $default, $setting->value() ); 170 $this->assertTrue( $setting->preview() );182 $this->assertTrue( $setting->preview(), "Preview for $setting->id should apply because setting is not in DB." ); 171 183 $base_value = call_user_func( $type_options['getter'], $base_name, $this->undefined ); 172 184 $this->assertArrayHasKey( 'foo', $base_value ); 173 185 $this->assertEquals( $default, $base_value['foo'] ); 174 186 175 // Multidimensional: See what effect the preview has on an extant setting (default value should not be seen) 187 // Multidimensional: See what effect the preview has on an extant setting (default value should not be seen) without post value. 176 188 $base_name = "set_{$type}_multi"; 177 189 $name = $base_name . '[foo]'; … … 184 196 $this->assertEquals( $initial_value, $base_value['foo'] ); 185 197 $this->assertEquals( $initial_value, $setting->value() ); 186 $ setting->preview();187 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // only applicable for custom types (not options or theme_mods)188 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // only applicable for custom types (not options or theme_mods)198 $this->assertFalse( $setting->preview(), "Preview for $setting->id should no-op because setting is in DB and post value is absent." ); 199 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // Only applicable for custom types (not options or theme_mods). 200 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // Only applicable for custom types (not options or theme_mods). 189 201 $base_value = call_user_func( $type_options['getter'], $base_name, array() ); 190 202 $this->assertEquals( $initial_value, $base_value['foo'] ); 191 203 $this->assertEquals( $initial_value, $setting->value() ); 192 204 193 // Multidimensional: Test unset setting being overridden by a post value 205 // Multidimensional: Ensure that setting a post value *after* preview() is called results in the post value being seen (deferred preview). 206 $override_value = "post_value_for_{$setting->id}_set_after_preview_called"; 207 $this->manager->set_post_value( $setting->id, $override_value ); 208 $base_value = call_user_func( $type_options['getter'], $base_name, array() ); 209 $this->assertEquals( $override_value, $base_value['foo'] ); 210 $this->assertEquals( $override_value, $setting->value() ); 211 212 // Multidimensional: Test unset setting being overridden by a post value. 194 213 $base_name = "unset_{$type}_multi_overridden"; 195 214 $name = $base_name . '[foo]'; … … 198 217 $this->assertEquals( $this->undefined, call_user_func( $type_options['getter'], $base_name, $this->undefined ) ); 199 218 $this->assertEquals( $default, $setting->value() ); 200 $ setting->preview();201 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // only applicable for custom types (not options or theme_mods)202 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // only applicable for custom types (not options or theme_mods)219 $this->assertTrue( $setting->preview(), "Preview for $setting->id should apply because a post value is present." ); 220 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // Only applicable for custom types (not options or theme_mods). 221 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // Only applicable for custom types (not options or theme_mods). 203 222 $base_value = call_user_func( $type_options['getter'], $base_name, $this->undefined ); 204 223 $this->assertArrayHasKey( 'foo', $base_value ); 205 224 $this->assertEquals( $this->post_data_overrides[ $name ], $base_value['foo'] ); 206 225 207 // Multidime msional: Test set setting being overridden by a post value226 // Multidimensional: Test set setting being overridden by a post value. 208 227 $base_name = "set_{$type}_multi_overridden"; 209 228 $name = $base_name . '[foo]'; … … 214 233 $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) ); 215 234 $base_value = call_user_func( $type_options['getter'], $base_name, $this->undefined ); 216 $this->a rrayHasKey( 'foo', $base_value );217 $this->a rrayHasKey( 'bar', $base_value );235 $this->assertArrayHasKey( 'foo', $base_value ); 236 $this->assertArrayHasKey( 'bar', $base_value ); 218 237 $this->assertEquals( $base_initial_value['foo'], $base_value['foo'] ); 219 238 … … 221 240 $this->assertEquals( $base_initial_value['bar'], $getter['bar'] ); 222 241 $this->assertEquals( $initial_value, $setting->value() ); 223 $ setting->preview();224 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // only applicable for custom types (not options or theme_mods)225 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // only applicable for custom types (not options or theme_mods)242 $this->assertTrue( $setting->preview(), "Preview for $setting->id should apply because post value is present." ); 243 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ) ); // Only applicable for custom types (not options or theme_mods). 244 $this->assertEquals( 0, did_action( "customize_preview_{$setting->type}" ) ); // Only applicable for custom types (not options or theme_mods). 226 245 $base_value = call_user_func( $type_options['getter'], $base_name, $this->undefined ); 227 246 $this->assertArrayHasKey( 'foo', $base_value ); 228 247 $this->assertEquals( $this->post_data_overrides[ $name ], $base_value['foo'] ); 229 $this->a rrayHasKey( 'bar', call_user_func( $type_options['getter'], $base_name, $this->undefined ) );248 $this->assertArrayHasKey( 'bar', call_user_func( $type_options['getter'], $base_name, $this->undefined ) ); 230 249 231 250 $getter = call_user_func( $type_options['getter'], $base_name, $this->undefined ); … … 273 292 } 274 293 } 275 294 /** 295 * Run assertions on custom settings. 296 * 297 * @see WP_Customize_Setting::preview() 298 */ 276 299 function test_preview_custom_type() { 277 300 $type = 'custom_type'; … … 287 310 add_action( "customize_preview_{$type}", array( $this, 'custom_type_preview' ) ); 288 311 289 // Custom type not existing and no post value override 312 // Custom type not existing and no post value override. 290 313 $name = "unset_{$type}_without_post_value"; 291 314 $default = "default_value_{$name}"; 292 315 $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) ); 293 // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need 316 // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need. 294 317 add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) ); 295 318 $this->assertEquals( $this->undefined, $this->custom_type_getter( $name, $this->undefined ) ); 296 319 $this->assertEquals( $default, $setting->value() ); 297 $ setting->preview();320 $this->assertTrue( $setting->preview() ); 298 321 $this->assertEquals( 1, did_action( "customize_preview_{$setting->id}" ) ); 299 322 $this->assertEquals( 1, did_action( "customize_preview_{$setting->type}" ) ); 300 323 $this->assertEquals( $this->undefined, $this->custom_type_getter( $name, $this->undefined ) ); // Note: for a non-custom type this is $default 301 $this->assertEquals( $default, $setting->value() ); // should be same as above302 303 // Custom type existing and no post value override 324 $this->assertEquals( $default, $setting->value() ); // Should be same as above. 325 326 // Custom type existing and no post value override. 304 327 $name = "set_{$type}_without_post_value"; 305 328 $default = "default_value_{$name}"; … … 307 330 $this->custom_type_setter( $name, $initial_value ); 308 331 $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) ); 309 // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need 332 // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need. 310 333 add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) ); 311 334 $this->assertEquals( $initial_value, $this->custom_type_getter( $name, $this->undefined ) ); 312 335 $this->assertEquals( $initial_value, $setting->value() ); 313 $ setting->preview();336 $this->assertFalse( $setting->preview(), "Preview for $setting->id should not apply because existing type without an override." ); 314 337 $this->assertEquals( 0, did_action( "customize_preview_{$setting->id}" ), 'Zero preview actions because initial value is set with no incoming post value, so there is no preview to apply.' ); 315 338 $this->assertEquals( 1, did_action( "customize_preview_{$setting->type}" ) ); 316 $this->assertEquals( $initial_value, $this->custom_type_getter( $name, $this->undefined ) ); // should be same as above 317 $this->assertEquals( $initial_value, $setting->value() ); // should be same as above 318 319 // Custom type not existing and with a post value override 339 $this->assertEquals( $initial_value, $this->custom_type_getter( $name, $this->undefined ) ); // Should be same as above. 340 $this->assertEquals( $initial_value, $setting->value() ); // Should be same as above. 341 342 // Custom type deferred preview (setting post value after preview ran). 343 $override_value = "custom_type_value_{$name}_override_deferred_preview"; 344 $this->manager->set_post_value( $setting->id, $override_value ); 345 $this->assertEquals( $override_value, $this->custom_type_getter( $name, $this->undefined ) ); // Should be same as above. 346 $this->assertEquals( $override_value, $setting->value() ); // Should be same as above. 347 348 // Custom type not existing and with a post value override. 320 349 $name = "unset_{$type}_with_post_value"; 321 350 $default = "default_value_{$name}"; 322 351 $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) ); 323 // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need 352 // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need. 324 353 add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) ); 325 354 $this->assertEquals( $this->undefined, $this->custom_type_getter( $name, $this->undefined ) ); 326 355 $this->assertEquals( $default, $setting->value() ); 327 $ setting->preview();356 $this->assertTrue( $setting->preview() ); 328 357 $this->assertEquals( 1, did_action( "customize_preview_{$setting->id}" ), 'One preview action now because initial value was not set and/or there is no incoming post value, so there is is a preview to apply.' ); 329 $this->assertEquals( 2, did_action( "customize_preview_{$setting->type}" ) );358 $this->assertEquals( 3, did_action( "customize_preview_{$setting->type}" ) ); 330 359 $this->assertEquals( $post_data_overrides[ $name ], $this->custom_type_getter( $name, $this->undefined ) ); 331 360 $this->assertEquals( $post_data_overrides[ $name ], $setting->value() ); 332 361 333 // Custom type not existing and with a post value override 362 // Custom type not existing and with a post value override. 334 363 $name = "set_{$type}_with_post_value"; 335 364 $default = "default_value_{$name}"; … … 337 366 $this->custom_type_setter( $name, $initial_value ); 338 367 $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type', 'default' ) ); 339 // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need 368 // Note: #29316 will allow us to have one filter for all settings of a given type, which is what we need. 340 369 add_filter( "customize_value_{$name}", array( $this, 'custom_type_value_filter' ) ); 341 370 $this->assertEquals( $initial_value, $this->custom_type_getter( $name, $this->undefined ) ); 342 371 $this->assertEquals( $initial_value, $setting->value() ); 343 $ setting->preview();372 $this->assertTrue( $setting->preview() ); 344 373 $this->assertEquals( 1, did_action( "customize_preview_{$setting->id}" ) ); 345 $this->assertEquals( 3, did_action( "customize_preview_{$setting->type}" ) );374 $this->assertEquals( 4, did_action( "customize_preview_{$setting->type}" ) ); 346 375 $this->assertEquals( $post_data_overrides[ $name ], $this->custom_type_getter( $name, $this->undefined ) ); 347 376 $this->assertEquals( $post_data_overrides[ $name ], $setting->value() ); … … 362 391 $this->assertEquals( $this->undefined, get_option( $name, $this->undefined ) ); 363 392 $this->assertEquals( $default, $setting->value() ); 364 $ setting->preview();393 $this->assertTrue( $setting->preview() ); 365 394 $this->assertEquals( $default, get_option( $name, $this->undefined ), sprintf( 'Expected get_option(%s) to return setting default: %s.', $name, $default ) ); 366 395 $this->assertEquals( $default, $setting->value() ); … … 439 468 $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) ); 440 469 $this->assertFalse( $setting->is_current_blog_previewed() ); 441 $ setting->preview();470 $this->assertTrue( $setting->preview() ); 442 471 $this->assertTrue( $setting->is_current_blog_previewed() ); 443 472 … … 463 492 $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) ); 464 493 $this->assertFalse( $setting->is_current_blog_previewed() ); 465 $ setting->preview();494 $this->assertTrue( $setting->preview() ); 466 495 $this->assertTrue( $setting->is_current_blog_previewed() ); 467 496 -
trunk/tests/phpunit/tests/customize/widgets.php
r35242 r35724 292 292 $this->assertFalse( $this->manager->get_panel( 'widgets' )->active() ); 293 293 } 294 295 /** 296 * @ticket 34738 297 * @see WP_Customize_Widgets::call_widget_update() 298 */ 299 function test_call_widget_update() { 300 301 $widget_number = 2; 302 $widget_id = "search-{$widget_number}"; 303 $setting_id = "widget_search[{$widget_number}]"; 304 $instance = array( 305 'title' => 'Buscar', 306 ); 307 308 $_POST = wp_slash( array( 309 'action' => 'update-widget', 310 'wp_customize' => 'on', 311 'nonce' => wp_create_nonce( 'update-widget' ), 312 'theme' => $this->manager->get_stylesheet(), 313 'customized' => '{}', 314 'widget-search' => array( 315 2 => $instance, 316 ), 317 'widget-id' => $widget_id, 318 'id_base' => 'search', 319 'widget-width' => '250', 320 'widget-height' => '200', 321 'widget_number' => strval( $widget_number ), 322 'multi_number' => '', 323 'add_new' => '', 324 ) ); 325 326 $this->do_customize_boot_actions(); 327 328 $this->assertArrayNotHasKey( $setting_id, $this->manager->unsanitized_post_values() ); 329 $result = $this->manager->widgets->call_widget_update( $widget_id ); 330 331 $this->assertInternalType( 'array', $result ); 332 $this->assertArrayHasKey( 'instance', $result ); 333 $this->assertArrayHasKey( 'form', $result ); 334 $this->assertEquals( $instance, $result['instance'] ); 335 $this->assertContains( sprintf( 'value="%s"', esc_attr( $instance['title'] ) ), $result['form'] ); 336 337 $post_values = $this->manager->unsanitized_post_values(); 338 $this->assertArrayHasKey( $setting_id, $post_values ); 339 $post_value = $post_values[ $setting_id ]; 340 $this->assertInternalType( 'array', $post_value ); 341 $this->assertArrayHasKey( 'title', $post_value ); 342 $this->assertArrayHasKey( 'encoded_serialized_instance', $post_value ); 343 $this->assertArrayHasKey( 'instance_hash_key', $post_value ); 344 $this->assertArrayHasKey( 'is_widget_customizer_js_value', $post_value ); 345 $this->assertEquals( $post_value, $this->manager->widgets->sanitize_widget_js_instance( $instance ) ); 346 } 294 347 }
Note: See TracChangeset
for help on using the changeset viewer.