Make WordPress Core


Ignore:
Timestamp:
03/10/2015 11:04:12 PM (10 years ago)
Author:
ocean90
Message:

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

props westonruter.
fixes #31428.

File:
1 edited

Legend:

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

    r31705 r31707  
    366366        $this->assertEquals( $default, $setting->value() );
    367367    }
     368
     369    /**
     370     * Ensure that is_current_blog_previewed returns the expected values.
     371     *
     372     * This is applicable to both single and multisite. This doesn't do switch_to_blog()
     373     *
     374     * @ticket 31428
     375     */
     376    function test_is_current_blog_previewed() {
     377        $type = 'option';
     378        $name = 'blogname';
     379        $post_value = rand_str();
     380        $this->manager->set_post_value( $name, $post_value );
     381        $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) );
     382        $this->assertNull( $setting->is_current_blog_previewed() );
     383        $setting->preview();
     384        $this->assertTrue( $setting->is_current_blog_previewed() );
     385
     386        $this->assertEquals( $post_value, $setting->value() );
     387        $this->assertEquals( $post_value, get_option( $name ) );
     388    }
     389
     390    /**
     391     * Ensure that previewing a setting is disabled when the current blog is switched.
     392     *
     393     * @ticket 31428
     394     * @group multisite
     395     */
     396    function test_previewing_with_switch_to_blog() {
     397        if ( ! is_multisite() ) {
     398            $this->markTestSkipped( 'Cannot test WP_Customize_Setting::is_current_blog_previewed() with switch_to_blog() if not on multisite.' );
     399        }
     400
     401        $type = 'option';
     402        $name = 'blogdescription';
     403        $post_value = rand_str();
     404        $this->manager->set_post_value( $name, $post_value );
     405        $setting = new WP_Customize_Setting( $this->manager, $name, compact( 'type' ) );
     406        $this->assertNull( $setting->is_current_blog_previewed() );
     407        $setting->preview();
     408        $this->assertTrue( $setting->is_current_blog_previewed() );
     409
     410        $blog_id = $this->factory->blog->create();
     411        switch_to_blog( $blog_id );
     412        $this->assertFalse( $setting->is_current_blog_previewed() );
     413        $this->assertNotEquals( $post_value, $setting->value() );
     414        $this->assertNotEquals( $post_value, get_option( $name ) );
     415        restore_current_blog();
     416    }
    368417}
    369418
Note: See TracChangeset for help on using the changeset viewer.