Changeset 35781
- Timestamp:
- 12/06/2015 06:09:42 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-customize-manager.php
r35724 r35781 1038 1038 * 1039 1039 * @since 3.4.0 1040 * 1041 * @param WP_Customize_Setting|string $id Customize Setting object, or ID. 1042 * @param array $args Setting arguments; passed to WP_Customize_Setting 1043 * constructor. 1040 * @since 4.5.0 Return added WP_Customize_Setting instance. 1041 * @access public 1042 * 1043 * @param WP_Customize_Setting|string $id Customize Setting object, or ID. 1044 * @param array $args Setting arguments; passed to WP_Customize_Setting 1045 * constructor. 1046 * @return WP_Customize_Setting The instance of the setting that was added. 1044 1047 */ 1045 1048 public function add_setting( $id, $args = array() ) { … … 1049 1052 $setting = new WP_Customize_Setting( $this, $id, $args ); 1050 1053 } 1054 1051 1055 $this->settings[ $setting->id ] = $setting; 1056 return $setting; 1052 1057 } 1053 1058 … … 1062 1067 * 1063 1068 * @since 4.2.0 1069 * @access public 1064 1070 * 1065 1071 * @param array $setting_ids The setting IDs to add. … … 1142 1148 * 1143 1149 * @since 4.0.0 1150 * @since 4.5.0 Return added WP_Customize_Panel instance. 1144 1151 * @access public 1145 1152 * 1146 1153 * @param WP_Customize_Panel|string $id Customize Panel object, or Panel ID. 1147 1154 * @param array $args Optional. Panel arguments. Default empty array. 1155 * 1156 * @return WP_Customize_Panel The instance of the panel that was added. 1148 1157 */ 1149 1158 public function add_panel( $id, $args = array() ) { … … 1155 1164 1156 1165 $this->panels[ $panel->id ] = $panel; 1166 return $panel; 1157 1167 } 1158 1168 … … 1217 1227 * 1218 1228 * @since 3.4.0 1229 * @since 4.5.0 Return added WP_Customize_Section instance. 1230 * @access public 1219 1231 * 1220 1232 * @param WP_Customize_Section|string $id Customize Section object, or Section ID. 1221 1233 * @param array $args Section arguments. 1234 * 1235 * @return WP_Customize_Section The instance of the section that was added. 1222 1236 */ 1223 1237 public function add_section( $id, $args = array() ) { … … 1227 1241 $section = new WP_Customize_Section( $this, $id, $args ); 1228 1242 } 1243 1229 1244 $this->sections[ $section->id ] = $section; 1245 return $section; 1230 1246 } 1231 1247 … … 1287 1303 * 1288 1304 * @since 3.4.0 1305 * @since 4.5.0 Return added WP_Customize_Control instance. 1306 * @access public 1289 1307 * 1290 1308 * @param WP_Customize_Control|string $id Customize Control object, or ID. 1291 1309 * @param array $args Control arguments; passed to WP_Customize_Control 1292 1310 * constructor. 1311 * @return WP_Customize_Control The instance of the control that was added. 1293 1312 */ 1294 1313 public function add_control( $id, $args = array() ) { … … 1298 1317 $control = new WP_Customize_Control( $this, $id, $args ); 1299 1318 } 1319 1300 1320 $this->controls[ $control->id ] = $control; 1321 return $control; 1301 1322 } 1302 1323 -
trunk/tests/phpunit/tests/customize/manager.php
r35724 r35781 493 493 $this->assertEquals( $added_control_ids, $sorted_control_ids ); 494 494 } 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 } 495 604 }
Note: See TracChangeset
for help on using the changeset viewer.