Make WordPress Core


Ignore:
Timestamp:
10/19/2016 07:38:27 PM (8 years ago)
Author:
westonruter
Message:

Customize: Fix unit tests when twentyfifteen is WP_DEFAULT_THEME instead of twentysixteen.

Use an inactive core theme for previewing theme switch instead of assuming twentysixteen is installed and active and twentyfifteen is not.

See #30937.

File:
1 edited

Legend:

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

    r38813 r38830  
    6969        $_REQUEST = array();
    7070        parent::tearDown();
     71    }
     72
     73    /**
     74     * Get a core theme that is not the same as the current theme.
     75     *
     76     * @throws Exception If an inactive core Twenty* theme cannot be found.
     77     * @return string Theme slug (stylesheet).
     78     */
     79    function get_inactive_core_theme() {
     80        $stylesheet = get_stylesheet();
     81        foreach ( wp_get_themes() as $theme ) {
     82            if ( $theme->stylesheet !== $stylesheet && 0 === strpos( $theme->stylesheet, 'twenty' ) ) {
     83                return $theme->stylesheet;
     84            }
     85        }
     86        throw new Exception( 'Unable to find inactive twenty* theme.' );
    7187    }
    7288
     
    348364     */
    349365    function test_add_state_query_params() {
     366        $preview_theme = $this->get_inactive_core_theme();
     367
    350368        $uuid = wp_generate_uuid4();
    351369        $messenger_channel = 'preview-0';
     
    367385            'changeset_uuid' => $uuid,
    368386            'messenger_channel' => null,
    369             'theme' => 'twentyfifteen',
     387            'theme' => $preview_theme,
    370388        ) );
    371389        $url = $wp_customize->add_state_query_params( home_url( '/' ) );
     
    376394        $this->assertArrayHasKey( 'customize_theme', $query_params );
    377395        $this->assertEquals( $uuid, $query_params['customize_changeset_uuid'] );
    378         $this->assertEquals( 'twentyfifteen', $query_params['customize_theme'] );
     396        $this->assertEquals( $preview_theme, $query_params['customize_theme'] );
    379397
    380398        $uuid = wp_generate_uuid4();
     
    382400            'changeset_uuid' => $uuid,
    383401            'messenger_channel' => null,
    384             'theme' => 'twentyfifteen',
     402            'theme' => $preview_theme,
    385403        ) );
    386404        $url = $wp_customize->add_state_query_params( 'http://not-allowed.example.com/?q=1' );
     
    611629        wp_set_current_user( self::$admin_user_id );
    612630
     631        $preview_theme = $this->get_inactive_core_theme();
    613632        $stashed_theme_mods = array(
    614             'twentyfifteen' => array(
     633            $preview_theme => array(
    615634                'background_color' => array(
    616635                    'value' => '#123456',
     
    622641        $manager = new WP_Customize_Manager( array(
    623642            'changeset_uuid' => $uuid,
    624             'theme' => 'twentyfifteen',
     643            'theme' => $preview_theme,
    625644        ) );
    626645        $manager->register_controls();
    627646        $GLOBALS['wp_customize'] = $manager;
    628647
    629         $manager->set_post_value( 'blogname', 'Hello 2015' );
     648        $manager->set_post_value( 'blogname', 'Hello Preview Theme' );
    630649        $post_values = $manager->unsanitized_post_values();
    631650        $manager->save_changeset_post( array( 'status' => 'publish' ) ); // Activate.
    632651
    633652        $this->assertEquals( '#123456', $post_values['background_color'] );
    634         $this->assertEquals( 'twentyfifteen', get_stylesheet() );
    635         $this->assertEquals( 'Hello 2015', get_option( 'blogname' ) );
     653        $this->assertEquals( $preview_theme, get_stylesheet() );
     654        $this->assertEquals( 'Hello Preview Theme', get_option( 'blogname' ) );
    636655    }
    637656
     
    750769        wp_set_current_user( self::$admin_user_id );
    751770
     771        $preview_theme = $this->get_inactive_core_theme();
    752772        $stashed_theme_mods = array(
    753             'twentyfifteen' => array(
     773            $preview_theme => array(
    754774                'background_color' => array(
    755775                    'value' => '#000000',
     
    828848        $manager = new WP_Customize_Manager( array(
    829849            'changeset_uuid' => $uuid,
    830             'theme' => 'twentyfifteen',
     850            'theme' => $preview_theme,
    831851        ) );
    832852        $this->assertFalse( $manager->is_theme_active() );
Note: See TracChangeset for help on using the changeset viewer.