Changeset 42343 for trunk/tests/phpunit/tests/customize/widgets.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/customize/widgets.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/widgets.php
r41935 r42343 29 29 wp_set_current_user( $user_id ); 30 30 $GLOBALS['wp_customize'] = new WP_Customize_Manager(); 31 $this->manager = $GLOBALS['wp_customize'];31 $this->manager = $GLOBALS['wp_customize']; 32 32 33 33 unset( $GLOBALS['_wp_sidebars_widgets'] ); // clear out cache set by wp_get_sidebars_widgets() … … 50 50 global $wp_widget_factory, $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates; 51 51 52 $wp_registered_sidebars = array();53 $wp_registered_widgets = array();52 $wp_registered_sidebars = array(); 53 $wp_registered_widgets = array(); 54 54 $wp_registered_widget_controls = array(); 55 $wp_registered_widget_updates = array();56 $wp_widget_factory->widgets = array();55 $wp_registered_widget_updates = array(); 56 $wp_widget_factory->widgets = array(); 57 57 58 58 parent::clean_up_global_scope(); … … 78 78 function do_customize_boot_actions() { 79 79 $_SERVER['REQUEST_METHOD'] = 'POST'; 80 $_REQUEST['nonce'] = wp_create_nonce( 'preview-customize_' . $this->manager->theme()->get_stylesheet() );80 $_REQUEST['nonce'] = wp_create_nonce( 'preview-customize_' . $this->manager->theme()->get_stylesheet() ); 81 81 do_action( 'setup_theme' ); 82 82 do_action( 'after_setup_theme' ); … … 179 179 $raw_widget_customized = array( 180 180 'widget_categories[2]' => array( 181 'title' => 'Taxonomies Brand New Value',182 'count' => 0,181 'title' => 'Taxonomies Brand New Value', 182 'count' => 0, 183 183 'hierarchical' => 0, 184 'dropdown' => 0,184 'dropdown' => 0, 185 185 ), 186 'widget_search[3]' => array(186 'widget_search[3]' => array( 187 187 'title' => 'Not as good as Google!', 188 188 ), 189 189 ); 190 $customized = array();190 $customized = array(); 191 191 foreach ( $raw_widget_customized as $setting_id => $instance ) { 192 192 $customized[ $setting_id ] = $this->manager->widgets->sanitize_widget_js_instance( $instance ); … … 259 259 260 260 $default_args = array( 261 'type' => 'option',262 'capability' => 'edit_theme_options',263 'transport' => 'refresh',264 'default' => array(),265 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_widget_instance' ),261 'type' => 'option', 262 'capability' => 'edit_theme_options', 263 'transport' => 'refresh', 264 'default' => array(), 265 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_widget_instance' ), 266 266 'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_widget_js_instance' ), 267 267 ); 268 $args = $this->manager->widgets->get_setting_args( 'widget_foo[2]' );268 $args = $this->manager->widgets->get_setting_args( 'widget_foo[2]' ); 269 269 foreach ( $default_args as $key => $default_value ) { 270 270 $this->assertEquals( $default_value, $args[ $key ] ); … … 273 273 274 274 $default_args = array( 275 'type' => 'option',276 'capability' => 'edit_theme_options',277 'transport' => 'postMessage',278 'default' => array(),279 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_widget_instance' ),275 'type' => 'option', 276 'capability' => 'edit_theme_options', 277 'transport' => 'postMessage', 278 'default' => array(), 279 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_widget_instance' ), 280 280 'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_widget_js_instance' ), 281 281 ); 282 $args = $this->manager->widgets->get_setting_args( 'widget_search[2]' );282 $args = $this->manager->widgets->get_setting_args( 'widget_search[2]' ); 283 283 foreach ( $default_args as $key => $default_value ) { 284 284 $this->assertEquals( $default_value, $args[ $key ] ); … … 291 291 292 292 $override_args = array( 293 'type' => 'theme_mod',294 'capability' => 'edit_posts',295 'transport' => 'postMessage',296 'default' => array( 'title' => 'asd' ),297 'sanitize_callback' => '__return_empty_array',293 'type' => 'theme_mod', 294 'capability' => 'edit_posts', 295 'transport' => 'postMessage', 296 'default' => array( 'title' => 'asd' ), 297 'sanitize_callback' => '__return_empty_array', 298 298 'sanitize_js_callback' => '__return_empty_array', 299 299 ); 300 $args = $this->manager->widgets->get_setting_args( 'widget_bar[3]', $override_args );300 $args = $this->manager->widgets->get_setting_args( 'widget_bar[3]', $override_args ); 301 301 foreach ( $override_args as $key => $override_value ) { 302 302 $this->assertEquals( $override_value, $args[ $key ] ); … … 305 305 306 306 $default_args = array( 307 'type' => 'option',308 'capability' => 'edit_theme_options',309 'transport' => 'postMessage',310 'default' => array(),311 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets' ),307 'type' => 'option', 308 'capability' => 'edit_theme_options', 309 'transport' => 'postMessage', 310 'default' => array(), 311 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets' ), 312 312 'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets_js_instance' ), 313 313 ); 314 $args = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-1]' );314 $args = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-1]' ); 315 315 foreach ( $default_args as $key => $default_value ) { 316 316 $this->assertEquals( $default_value, $args[ $key ] ); … … 319 319 320 320 $override_args = array( 321 'type' => 'theme_mod',322 'capability' => 'edit_posts',323 'transport' => 'postMessage',324 'default' => array( 'title' => 'asd' ),325 'sanitize_callback' => '__return_empty_array',321 'type' => 'theme_mod', 322 'capability' => 'edit_posts', 323 'transport' => 'postMessage', 324 'default' => array( 'title' => 'asd' ), 325 'sanitize_callback' => '__return_empty_array', 326 326 'sanitize_js_callback' => '__return_empty_array', 327 327 ); 328 $args = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-2]', $override_args );328 $args = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-2]', $override_args ); 329 329 foreach ( $override_args as $key => $override_value ) { 330 330 $this->assertEquals( $override_value, $args[ $key ] ); … … 345 345 346 346 $new_categories_instance = array( 347 'title' => 'Taxonomies Brand New Value',348 'count' => '1',347 'title' => 'Taxonomies Brand New Value', 348 'count' => '1', 349 349 'hierarchical' => '1', 350 'dropdown' => '1',350 'dropdown' => '1', 351 351 ); 352 352 … … 358 358 $this->assertArrayHasKey( 'instance_hash_key', $sanitized_for_js ); 359 359 360 $corrupted_sanitized_for_js = $sanitized_for_js;360 $corrupted_sanitized_for_js = $sanitized_for_js; 361 361 $corrupted_sanitized_for_js['encoded_serialized_instance'] = base64_encode( serialize( array( 'title' => 'EVIL' ) ) ); 362 362 $this->assertNull( $this->manager->widgets->sanitize_widget_instance( $corrupted_sanitized_for_js ), 'Expected sanitize_widget_instance to reject corrupted data.' ); … … 375 375 require_once ABSPATH . '/wp-admin/includes/widgets.php'; 376 376 $widget_id = 'search-2'; 377 $widget = $wp_registered_widgets[ $widget_id ];378 $args = array(379 'widget_id' => $widget['id'],377 $widget = $wp_registered_widgets[ $widget_id ]; 378 $args = array( 379 'widget_id' => $widget['id'], 380 380 'widget_name' => $widget['name'], 381 381 ); 382 $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) ); 382 $args = wp_list_widget_controls_dynamic_sidebar( 383 array( 384 0 => $args, 385 1 => $widget['params'][0], 386 ) 387 ); 383 388 return $args; 384 389 } … … 419 424 $this->do_customize_boot_actions(); 420 425 $control = $this->manager->get_control( 'widget_search[2]' ); 421 $params = $control->json();426 $params = $control->json(); 422 427 423 428 $this->assertEquals( 'widget_form', $params['type'] ); … … 458 463 459 464 $widget_number = 2; 460 $widget_id = "search-{$widget_number}";461 $setting_id = "widget_search[{$widget_number}]";462 $instance = array(465 $widget_id = "search-{$widget_number}"; 466 $setting_id = "widget_search[{$widget_number}]"; 467 $instance = array( 463 468 'title' => 'Buscar', 464 469 ); 465 470 466 $_POST = wp_slash( array( 467 'action' => 'update-widget', 468 'wp_customize' => 'on', 469 'nonce' => wp_create_nonce( 'update-widget' ), 470 'theme' => $this->manager->get_stylesheet(), 471 'customized' => '{}', 472 'widget-search' => array( 473 2 => $instance, 474 ), 475 'widget-id' => $widget_id, 476 'id_base' => 'search', 477 'widget-width' => '250', 478 'widget-height' => '200', 479 'widget_number' => strval( $widget_number ), 480 'multi_number' => '', 481 'add_new' => '', 482 ) ); 471 $_POST = wp_slash( 472 array( 473 'action' => 'update-widget', 474 'wp_customize' => 'on', 475 'nonce' => wp_create_nonce( 'update-widget' ), 476 'theme' => $this->manager->get_stylesheet(), 477 'customized' => '{}', 478 'widget-search' => array( 479 2 => $instance, 480 ), 481 'widget-id' => $widget_id, 482 'id_base' => 'search', 483 'widget-width' => '250', 484 'widget-height' => '200', 485 'widget_number' => strval( $widget_number ), 486 'multi_number' => '', 487 'add_new' => '', 488 ) 489 ); 483 490 484 491 $this->do_customize_boot_actions(); … … 580 587 function test_filter_dynamic_sidebar_params() { 581 588 global $wp_registered_sidebars; 582 register_sidebar( array( 583 'id' => 'foo', 584 ) ); 589 register_sidebar( 590 array( 591 'id' => 'foo', 592 ) 593 ); 585 594 586 595 $this->manager->widgets->selective_refresh_init(); … … 606 615 $this->assertEquals( $bad_params, $this->manager->widgets->filter_dynamic_sidebar_params( $bad_params ) ); 607 616 608 $bad_params = $params;617 $bad_params = $params; 609 618 $bad_params[0]['id'] = 'non-existing'; 610 619 $this->assertEquals( $bad_params, $this->manager->widgets->filter_dynamic_sidebar_params( $bad_params ) ); 611 620 612 $bad_params = $params;621 $bad_params = $params; 613 622 $bad_params[0]['before_widget'] = ' <oops>'; 614 623 $this->assertEquals( $bad_params, $this->manager->widgets->filter_dynamic_sidebar_params( $bad_params ) ); … … 637 646 638 647 $partial_id = 'widget[search-2]'; 639 $partials = $this->manager->selective_refresh->add_dynamic_partials( array( $partial_id ) );648 $partials = $this->manager->selective_refresh->add_dynamic_partials( array( $partial_id ) ); 640 649 $this->assertNotEmpty( $partials ); 641 650 $partial = array_shift( $partials );
Note: See TracChangeset
for help on using the changeset viewer.