Changeset 34838 for trunk/tests/phpunit/tests/customize/setting.php
- Timestamp:
- 10/05/2015 09:57:32 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/customize/setting.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/setting.php
r32840 r34838 368 368 369 369 /** 370 * Test setting save method for custom type. 371 * 372 * @see WP_Customize_Setting::save() 373 * @see WP_Customize_Setting::update() 374 */ 375 function test_update_custom_type() { 376 $type = 'custom'; 377 $name = 'foo'; 378 $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) ); 379 $this->manager->add_setting( $setting ); 380 add_action( 'customize_update_custom', array( $this, 'handle_customize_update_custom_foo_action' ), 10, 2 ); 381 add_action( 'customize_save_foo', array( $this, 'handle_customize_save_custom_foo_action' ), 10, 2 ); 382 383 // Try saving before value set. 384 $this->assertTrue( 0 === did_action( 'customize_update_custom' ) ); 385 $this->assertTrue( 0 === did_action( 'customize_save_foo' ) ); 386 $this->assertFalse( $setting->save() ); 387 $this->assertTrue( 0 === did_action( 'customize_update_custom' ) ); 388 $this->assertTrue( 0 === did_action( 'customize_save_foo' ) ); 389 390 // Try setting post value without user as admin. 391 $this->manager->set_post_value( $setting->id, 'hello world' ); 392 $this->assertFalse( $setting->save() ); 393 $this->assertTrue( 0 === did_action( 'customize_update_custom' ) ); 394 $this->assertTrue( 0 === did_action( 'customize_save_foo' ) ); 395 396 // Satisfy all requirements for save to happen. 397 wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); 398 $this->assertTrue( false !== $setting->save() ); 399 $this->assertTrue( 1 === did_action( 'customize_update_custom' ) ); 400 $this->assertTrue( 1 === did_action( 'customize_save_foo' ) ); 401 } 402 403 /** 404 * Check customize_update_custom action. 405 * 406 * @see Tests_WP_Customize_Setting::test_update_custom_type() 407 * @param mixed $value 408 * @param WP_Customize_Setting $setting 409 */ 410 function handle_customize_update_custom_foo_action( $value, $setting = null ) { 411 $this->assertEquals( 'hello world', $value ); 412 $this->assertInstanceOf( 'WP_Customize_Setting', $setting ); 413 } 414 415 /** 416 * Check customize_save_foo action. 417 * 418 * @see Tests_WP_Customize_Setting::test_update_custom_type() 419 * @param WP_Customize_Setting $setting 420 */ 421 function handle_customize_save_custom_foo_action( $setting ) { 422 $this->assertInstanceOf( 'WP_Customize_Setting', $setting ); 423 $this->assertEquals( 'custom', $setting->type ); 424 $this->assertEquals( 'foo', $setting->id ); 425 } 426 427 /** 370 428 * Ensure that is_current_blog_previewed returns the expected values. 371 429 *
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)