Make WordPress Core

Ticket #36389: 36389.4.diff

File 36389.4.diff, 6.6 KB (added by westonruter, 9 years ago)

Removed extraneous unit test groups: https://github.com/xwp/wordpress-develop/pull/149/commits/31965b0163f269f022e2637dce0958c3da060afa

  • 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..d176d6a 100644
    class WP_Customize_Setting { 
    207207        }
    208208
    209209        /**
     210         * Reset `$aggregated_multidimensionals` static variable.
     211         *
     212         * This is intended only for use by unit tests.
     213         *
     214         * @since 4.5.0
     215         * @access public
     216         * @ignore
     217         */
     218        static public function reset_aggregated_multidimensionals() {
     219                self::$aggregated_multidimensionals = array();
     220        }
     221
     222        /**
    210223         * The ID for the current site when the preview() method was called.
    211224         *
    212225         * @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 { 
    9999                }
    100100
    101101                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 );
    103103                add_action( 'wp_loaded',                               array( $this, 'override_sidebars_widgets_for_theme_switch' ) );
    104104                add_action( 'customize_controls_init',                 array( $this, 'customize_controls_init' ) );
    105105                add_action( 'customize_register',                      array( $this, 'schedule_customize_register' ), 1 );
    final class WP_Customize_Widgets { 
    376376        public function customize_register() {
    377377                global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_sidebars;
    378378
     379                add_filter( 'sidebars_widgets', array( $this, 'preview_sidebars_widgets' ), 1 );
     380
    379381                $sidebars_widgets = array_merge(
    380382                        array( 'wp_inactive_widgets' => array() ),
    381383                        array_fill_keys( array_keys( $wp_registered_sidebars ), array() ),
    final class WP_Customize_Widgets { 
    509511                                $this->manager->get_setting( $new_setting_id )->preview();
    510512                        }
    511513                }
    512 
    513                 add_filter( 'sidebars_widgets', array( $this, 'preview_sidebars_widgets' ), 1 );
    514514        }
    515515
    516516        /**
  • tests/phpunit/tests/customize/widgets.php

    diff --git tests/phpunit/tests/customize/widgets.php tests/phpunit/tests/customize/widgets.php
    index 28392fd..721f804 100644
    class Tests_WP_Customize_Widgets extends WP_UnitTestCase { 
    4646                remove_action( 'customize_register', 'twentysixteen_customize_register', 11 );
    4747
    4848                $this->backup_registered_sidebars = $GLOBALS['wp_registered_sidebars'];
     49
     50                // Reset protected static var on class.
     51                WP_Customize_Setting::reset_aggregated_multidimensionals();
    4952        }
    5053
    5154        function clean_up_global_scope() {
    class Tests_WP_Customize_Widgets extends WP_UnitTestCase { 
    7073
    7174        function set_customized_post_data( $customized ) {
    7275                $_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                }
    7381        }
    7482
    7583        function do_customize_boot_actions() {
    class Tests_WP_Customize_Widgets extends WP_UnitTestCase { 
    150158        }
    151159
    152160        /**
    153          * Test WP_Customize_Widgets::register_settings()
     161         * Test WP_Customize_Widgets::register_settings() with selective refresh enabled.
    154162         *
    155163         * @ticket 30988
     164         * @ticket 36389
    156165         */
    157166        function test_register_settings() {
     167                add_theme_support( 'customize-selective-refresh-widgets' );
    158168
    159169                $raw_widget_customized = array(
    160170                        'widget_categories[2]' => array(
    class Tests_WP_Customize_Widgets extends WP_UnitTestCase { 
    176186                $this->do_customize_boot_actions();
    177187                $this->assertTrue( is_customize_preview() );
    178188
    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 );
    182208
    183209                $widget_categories = get_option( 'widget_categories' );
    184210                $this->assertEquals( $raw_widget_customized['widget_categories[2]'], $widget_categories[2], 'Expected $wp_customize->get_setting(widget_categories[2])->preview() to have been called.' );
    185211        }
    186212
    187213        /**
     214         * Test registering settings without selective refresh enabled.
     215         *
     216         * @ticket 36389
     217         */
     218        function test_register_settings_without_selective_refresh() {
     219                remove_theme_support( 'customize-selective-refresh-widgets' );
     220                $this->test_register_settings();
     221        }
     222
     223        /**
     224         * Test registering settings with selective refresh enabled at a late after_setup_theme action.
     225         *
     226         * @ticket 36389
     227         */
     228        function test_register_settings_with_late_theme_support_added() {
     229                remove_theme_support( 'customize-selective-refresh-widgets' );
     230                add_action( 'after_setup_theme', array( $this, 'add_customize_selective_refresh_theme_support' ), 100 );
     231                $this->test_register_settings();
     232        }
     233
     234        /**
     235         * Add customize-selective-refresh-widgets theme support.
     236         */
     237        function add_customize_selective_refresh_theme_support() {
     238                add_theme_support( 'customize-selective-refresh-widgets' );
     239        }
     240
     241        /**
    188242         * Test WP_Customize_Widgets::get_setting_args()
    189243         */
    190244        function test_get_setting_args() {