Customizer: Return the original value when filtering theme mods/options and the current blog has changed.

props westonruter.
fixes #31428.

git-svn-id: https://develop.svn.wordpress.org/trunk@31707 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90)
2015-03-10 23:04:12 +00:00
parent 72fcd6e2ce
commit 32a124a884
2 changed files with 88 additions and 0 deletions
+49
View File
@@ -365,5 +365,54 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
$this->assertEquals( $default, get_option( $name, $this->undefined ), sprintf( 'Expected get_option(%s) to return setting default: %s.', $name, $default ) );
$this->assertEquals( $default, $setting->value() );
}
/**
* Ensure that is_current_blog_previewed returns the expected values.
*
* This is applicable to both single and multisite. This doesn't do switch_to_blog()
*
* @ticket 31428
*/
function test_is_current_blog_previewed() {
$type = 'option';
$name = 'blogname';
$post_value = rand_str();
$this->manager->set_post_value( $name, $post_value );
$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) );
$this->assertNull( $setting->is_current_blog_previewed() );
$setting->preview();
$this->assertTrue( $setting->is_current_blog_previewed() );
$this->assertEquals( $post_value, $setting->value() );
$this->assertEquals( $post_value, get_option( $name ) );
}
/**
* Ensure that previewing a setting is disabled when the current blog is switched.
*
* @ticket 31428
* @group multisite
*/
function test_previewing_with_switch_to_blog() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Cannot test WP_Customize_Setting::is_current_blog_previewed() with switch_to_blog() if not on multisite.' );
}
$type = 'option';
$name = 'blogdescription';
$post_value = rand_str();
$this->manager->set_post_value( $name, $post_value );
$setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) );
$this->assertNull( $setting->is_current_blog_previewed() );
$setting->preview();
$this->assertTrue( $setting->is_current_blog_previewed() );
$blog_id = $this->factory->blog->create();
switch_to_blog( $blog_id );
$this->assertFalse( $setting->is_current_blog_previewed() );
$this->assertNotEquals( $post_value, $setting->value() );
$this->assertNotEquals( $post_value, get_option( $name ) );
restore_current_blog();
}
}