Make WordPress Core


Ignore:
Timestamp:
12/06/2015 06:09:42 PM (11 years ago)
Author:
westonruter
Message:

Customizer: Return added instances for panels, sections, controls, and settings when calling WP_Customize_Manager::add_*() methods.

Add missing phpDoc.

Props fusillicode, jubstuff.
Fixes #34596.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r35724 r35781  
    493493                $this->assertEquals( $added_control_ids, $sorted_control_ids );
    494494        }
     495
     496        /**
     497         * @ticket 34596
     498         */
     499        function test_add_section_return_instance() {
     500                $manager = new WP_Customize_Manager();
     501                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     502
     503                $section_id = 'foo-section';
     504                $result_section = $manager->add_section( $section_id, array(
     505                        'title'    => 'Section',
     506                        'priority' => 1,
     507                ) );
     508
     509                $this->assertInstanceOf( 'WP_Customize_Section', $result_section );
     510                $this->assertEquals( $section_id, $result_section->id );
     511
     512                $section = new WP_Customize_Section( $manager, $section_id, array(
     513                        'title'    => 'Section 2',
     514                        'priority' => 2,
     515                ) );
     516                $result_section = $manager->add_section( $section );
     517
     518                $this->assertInstanceOf( 'WP_Customize_Section', $result_section );
     519                $this->assertEquals( $section_id, $result_section->id );
     520                $this->assertEquals( $section, $result_section );
     521        }
     522
     523        /**
     524         * @ticket 34596
     525         */
     526        function test_add_setting_return_instance() {
     527                $manager = new WP_Customize_Manager();
     528                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     529
     530                $setting_id = 'foo-setting';
     531                $result_setting = $manager->add_setting( $setting_id );
     532
     533                $this->assertInstanceOf( 'WP_Customize_Setting', $result_setting );
     534                $this->assertEquals( $setting_id, $result_setting->id );
     535
     536                $setting = new WP_Customize_Setting( $manager, $setting_id );
     537                $result_setting = $manager->add_setting( $setting );
     538
     539                $this->assertInstanceOf( 'WP_Customize_Setting', $result_setting );
     540                $this->assertEquals( $setting, $result_setting );
     541                $this->assertEquals( $setting_id, $result_setting->id );
     542        }
     543
     544        /**
     545         * @ticket 34596
     546         */
     547        function test_add_panel_return_instance() {
     548                $manager = new WP_Customize_Manager();
     549                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     550
     551                $panel_id = 'foo-panel';
     552                $result_panel = $manager->add_panel( $panel_id, array(
     553                        'title'    => 'Test Panel',
     554                        'priority' => 2,
     555                ) );
     556
     557                $this->assertInstanceOf( 'WP_Customize_Panel', $result_panel );
     558                $this->assertEquals( $panel_id, $result_panel->id );
     559
     560                $panel = new WP_Customize_Panel( $manager, $panel_id, array(
     561                        'title' => 'Test Panel 2',
     562                ) );
     563                $result_panel = $manager->add_panel( $panel );
     564
     565                $this->assertInstanceOf( 'WP_Customize_Panel', $result_panel );
     566                $this->assertEquals( $panel, $result_panel );
     567                $this->assertEquals( $panel_id, $result_panel->id );
     568        }
     569
     570        /**
     571         * @ticket 34596
     572         */
     573        function test_add_control_return_instance() {
     574                $manager = new WP_Customize_Manager();
     575                $section_id = 'foo-section';
     576                wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     577                $manager->add_section( $section_id, array(
     578                        'title'    => 'Section',
     579                        'priority' => 1,
     580                ) );
     581
     582                $control_id = 'foo-control';
     583                $manager->add_setting( $control_id );
     584
     585                $result_control = $manager->add_control( $control_id, array(
     586                        'section'  => $section_id,
     587                        'priority' => 1,
     588                        'setting'  => $control_id,
     589                ) );
     590                $this->assertInstanceOf( 'WP_Customize_Control', $result_control );
     591                $this->assertEquals( $control_id, $result_control->id );
     592
     593                $control = new WP_Customize_Control( $manager, $control_id, array(
     594                        'section'  => $section_id,
     595                        'priority' => 1,
     596                        'setting'  => $control_id,
     597                ) );
     598                $result_control = $manager->add_control( $control );
     599
     600                $this->assertInstanceOf( 'WP_Customize_Control', $result_control );
     601                $this->assertEquals( $control, $result_control );
     602                $this->assertEquals( $control_id, $result_control->id );
     603        }
    495604}
Note: See TracChangeset for help on using the changeset viewer.