| 434 | |
| 435 | /** |
| 436 | * @ticket 34596 |
| 437 | */ |
| 438 | function test_add_section_return_instance() { |
| 439 | $manager = new WP_Customize_Manager(); |
| 440 | $section_id = 'foo-section'; |
| 441 | wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); |
| 442 | |
| 443 | $result_section = $manager->add_section( $section_id, array( |
| 444 | 'title' => 'Section', |
| 445 | 'priority' => 1, |
| 446 | ) ); |
| 447 | |
| 448 | $this->assertInstanceOf( 'WP_Customize_Section', $result_section ); |
| 449 | |
| 450 | $section = new WP_Customize_Section( $manager, $section_id, array( |
| 451 | 'title' => 'Section 2', |
| 452 | 'priority' => 2 |
| 453 | ) ); |
| 454 | $result_section = $manager->add_section( $section ); |
| 455 | |
| 456 | $this->assertInstanceOf( 'WP_Customize_Section', $result_section ); |
| 457 | $this->assertEquals( $section, $result_section ); |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * @ticket 34596 |
| 462 | */ |
| 463 | function test_add_setting_return_instance() { |
| 464 | $manager = new WP_Customize_Manager(); |
| 465 | wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); |
| 466 | |
| 467 | $result_setting = $manager->add_setting( 'return-instance-test' ); |
| 468 | |
| 469 | $this->assertInstanceOf( 'WP_Customize_Setting', $result_setting ); |
| 470 | |
| 471 | $setting = new WP_Customize_Setting( $manager, 'return-instance-test-2' ); |
| 472 | $result_setting = $manager->add_setting( $setting ); |
| 473 | |
| 474 | $this->assertInstanceOf( 'WP_Customize_Setting', $result_setting ); |
| 475 | $this->assertEquals( $setting, $result_setting ); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * @ticket 34596 |
| 480 | */ |
| 481 | function test_add_panel_return_instance() { |
| 482 | $manager = new WP_Customize_Manager(); |
| 483 | wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); |
| 484 | |
| 485 | $result_panel = $manager->add_panel( 'return-instance-test', array( |
| 486 | 'title' => 'Test Panel', |
| 487 | 'priority' => 2 |
| 488 | ) ); |
| 489 | |
| 490 | $this->assertInstanceOf( 'WP_Customize_Panel', $result_panel ); |
| 491 | |
| 492 | $panel = new WP_Customize_Panel( $manager, 'return-instance-test-2', array( |
| 493 | 'title' => 'Test Panel 2', |
| 494 | ) ); |
| 495 | |
| 496 | $result_panel = $manager->add_panel( $panel ); |
| 497 | $this->assertInstanceOf( 'WP_Customize_Panel', $result_panel ); |
| 498 | $this->assertEquals( $panel, $result_panel ); |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * @ticket 34596 |
| 503 | */ |
| 504 | function test_add_control_return_instance() { |
| 505 | $manager = new WP_Customize_Manager(); |
| 506 | $section_id = 'foo-section'; |
| 507 | wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); |
| 508 | $manager->add_section( $section_id, array( |
| 509 | 'title' => 'Section', |
| 510 | 'priority' => 1, |
| 511 | ) ); |
| 512 | $id = 'return-instance-test'; |
| 513 | $manager->add_setting( $id ); |
| 514 | $control = new WP_Customize_Control( $manager, $id, array( |
| 515 | 'section' => $section_id, |
| 516 | 'priority' => 1, |
| 517 | 'setting' => $id, |
| 518 | ) ); |
| 519 | $result_control = $manager->add_control( $control ); |
| 520 | |
| 521 | $this->assertInstanceOf( 'WP_Customize_Control', $result_control ); |
| 522 | $this->assertEquals( $control, $result_control ); |
| 523 | |
| 524 | $result_control = $manager->add_control( 'return-instance-test2', array( |
| 525 | 'section' => $section_id, |
| 526 | 'priority' => 1, |
| 527 | 'setting' => $id, |
| 528 | ) ); |
| 529 | $this->assertInstanceOf( 'WP_Customize_Control', $result_control ); |
| 530 | } |