Make WordPress Core

Ticket #34596: 34596.2.diff

File 34596.2.diff, 5.7 KB (added by fusillicode, 9 years ago)
  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index fcc9697..862e65d 100644
    final class WP_Customize_Manager { 
    980980         * @param WP_Customize_Setting|string $id Customize Setting object, or ID.
    981981         * @param array $args                     Setting arguments; passed to WP_Customize_Setting
    982982         *                                        constructor.
     983         * @return WP_Customize_Setting           The instance of the setting that was added
    983984         */
    984985        public function add_setting( $id, $args = array() ) {
    985986                if ( $id instanceof WP_Customize_Setting ) {
    final class WP_Customize_Manager { 
    987988                } else {
    988989                        $setting = new WP_Customize_Setting( $this, $id, $args );
    989990                }
    990                 $this->settings[ $setting->id ] = $setting;
     991                return $this->settings[ $setting->id ] = $setting;
    991992        }
    992993
    993994        /**
    final class WP_Customize_Manager { 
    10841085         *
    10851086         * @param WP_Customize_Panel|string $id   Customize Panel object, or Panel ID.
    10861087         * @param array                     $args Optional. Panel arguments. Default empty array.
     1088         * @return WP_Customize_Panel             The instance of the panel that was added
    10871089         */
    10881090        public function add_panel( $id, $args = array() ) {
    10891091                if ( $id instanceof WP_Customize_Panel ) {
    final class WP_Customize_Manager { 
    10911093                } else {
    10921094                        $panel = new WP_Customize_Panel( $this, $id, $args );
    10931095                }
    1094 
    1095                 $this->panels[ $panel->id ] = $panel;
     1096                return $this->panels[ $panel->id ] = $panel;
    10961097        }
    10971098
    10981099        /**
    final class WP_Customize_Manager { 
    11581159         *
    11591160         * @param WP_Customize_Section|string $id   Customize Section object, or Section ID.
    11601161         * @param array                       $args Section arguments.
     1162         * @return WP_Customize_Section             The instance of the section that was added
    11611163         */
    11621164        public function add_section( $id, $args = array() ) {
    11631165                if ( $id instanceof WP_Customize_Section ) {
    final class WP_Customize_Manager { 
    11651167                } else {
    11661168                        $section = new WP_Customize_Section( $this, $id, $args );
    11671169                }
    1168                 $this->sections[ $section->id ] = $section;
     1170                return $this->sections[ $section->id ] = $section;
    11691171        }
    11701172
    11711173        /**
    final class WP_Customize_Manager { 
    12291231         * @param WP_Customize_Control|string $id   Customize Control object, or ID.
    12301232         * @param array                       $args Control arguments; passed to WP_Customize_Control
    12311233         *                                          constructor.
     1234         * @return WP_Customize_Control             The instance of the control that was added
    12321235         */
    12331236        public function add_control( $id, $args = array() ) {
    12341237                if ( $id instanceof WP_Customize_Control ) {
    final class WP_Customize_Manager { 
    12361239                } else {
    12371240                        $control = new WP_Customize_Control( $this, $id, $args );
    12381241                }
    1239                 $this->controls[ $control->id ] = $control;
     1242                return $this->controls[ $control->id ] = $control;
    12401243        }
    12411244
    12421245        /**
  • tests/phpunit/tests/customize/manager.php

    diff --git tests/phpunit/tests/customize/manager.php tests/phpunit/tests/customize/manager.php
    index 247f765..2fc06ca 100644
    class Tests_WP_Customize_Manager extends WP_UnitTestCase { 
    431431                $sorted_control_ids = wp_list_pluck( $manager->get_section( $section_id )->controls, 'id' );
    432432                $this->assertEquals( $added_control_ids, $sorted_control_ids );
    433433        }
     434
     435        /**
     436         * @ticket 34596
     437         */
     438        function test_add_setting_returns_same_setting_instance_as_the_one_passed_in_as_argument() {
     439                $setting = new WP_Customize_Setting( $this->manager, 'foo' );
     440                $this->assertSame( $setting, $this->manager->add_setting( $setting ) );
     441        }
     442
     443        /**
     444         * @ticket 34596
     445         */
     446        function test_add_setting_returns_a_new_setting_instance_created_with_the_arguments_passed_in() {
     447                $setting = new WP_Customize_Setting( $this->manager, 'foo' );
     448                $this->assertEquals( $setting, $this->manager->add_setting( 'foo' ) );
     449        }
     450
     451        /**
     452         * @ticket 34596
     453         */
     454        function test_add_control_returns_same_control_instance_as_the_one_passed_in_as_argument() {
     455                $control = new WP_Customize_Control( $this->manager, 'foo' );
     456                $this->assertSame( $control, $this->manager->add_control( $control ) );
     457        }
     458
     459        /**
     460         * @ticket 34596
     461         */
     462        function test_add_control_returns_a_new_control_instance_created_with_the_arguments_passed_in() {
     463                $control = new WP_Customize_Control( $this->manager, 'foo' );
     464                $inside_control = $this->manager->add_control( 'foo' );
     465                $this->assertEquals( $control->id, $inside_control->id );
     466        }
     467
     468        /**
     469         * @ticket 34596
     470         */
     471        function test_add_section_returns_same_section_instance_as_the_one_passed_in_as_argument() {
     472                $section = new WP_Customize_Section( $this->manager, 'foo' );
     473                $this->assertSame( $section, $this->manager->add_section( $section ) );
     474        }
     475
     476        /**
     477         * @ticket 34596
     478         */
     479        function test_add_section_returns_a_new_section_instance_created_with_the_arguments_passed_in() {
     480                $section = new WP_Customize_Section( $this->manager, 'foo' );
     481                $inside_section = $this->manager->add_section( 'foo' );
     482                $this->assertEquals( $section->id, $inside_section->id );
     483        }
     484
     485        /**
     486         * @ticket 34596
     487         */
     488        function test_add_panel_returns_same_panel_instance_as_the_one_passed_in_as_argument() {
     489                $panel = new WP_Customize_Panel( $this->manager, 'foo' );
     490                $this->assertSame( $panel, $this->manager->add_panel( $panel ) );
     491        }
     492
     493        /**
     494         * @ticket 34596
     495         */
     496        function test_add_panel_returns_a_new_panel_instance_created_with_the_arguments_passed_in() {
     497                $panel = new WP_Customize_Panel( $this->manager, 'foo' );
     498                $inside_panel = $this->manager->add_panel( 'foo' );
     499                $this->assertEquals( $panel->id, $inside_panel->id );
     500        }
    434501}