Make WordPress Core


Ignore:
Timestamp:
11/09/2016 08:42:22 PM (10 years ago)
Author:
westonruter
Message:

Customize: Split out custom_css query logic from wp_get_custom_css() into a re-usable wp_get_custom_css_post() function to also be used when updating.

Props georgestephanis, westonruter.
See #38672, #35395.

File:
1 edited

Legend:

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

    r39175 r39185  
    4646
    4747                do_action( 'customize_register', $this->wp_customize );
    48                 $this->setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[twentysixteen]' );
     48                $this->setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[' . get_stylesheet() . ']' );
    4949                $this->wp_customize->add_setting( $this->setting );
    5050        }
     
    7979                $this->assertTrue( post_type_exists( 'custom_css' ) );
    8080                $this->assertEquals( 'custom_css', $this->setting->type );
    81                 $this->assertEquals( 'twentysixteen', $this->setting->stylesheet );
     81                $this->assertEquals( get_stylesheet(), $this->setting->stylesheet );
    8282                $this->assertEquals( 'edit_css', $this->setting->capability );
    8383
     
    114114                $this->assertEquals( $this->setting->default, $this->setting->value() );
    115115
     116                $this->assertNull( wp_get_custom_css_post() );
     117                $this->assertNull( wp_get_custom_css_post( $this->setting->stylesheet ) );
     118                $this->assertNull( wp_get_custom_css_post( 'twentyten' ) );
     119
    116120                $original_css = 'body { color: black; }';
    117                 $this->factory()->post->create( array(
     121                $post_id = $this->factory()->post->create( array(
    118122                        'post_title' => $this->setting->stylesheet,
    119123                        'post_name' => $this->setting->stylesheet,
    120                         'post_content' => 'body { color: black; }',
     124                        'post_content' => $original_css,
    121125                        'post_status' => 'publish',
    122126                        'post_type' => 'custom_css',
    123127                ) );
     128                $twentyten_css = 'body { color: red; }';
     129                $twentyten_post_id = $this->factory()->post->create( array(
     130                        'post_title' => 'twentyten',
     131                        'post_name' => 'twentyten',
     132                        'post_content' => $twentyten_css,
     133                        'post_status' => 'publish',
     134                        'post_type' => 'custom_css',
     135                ) );
     136                $twentyten_setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[twentyten]' );
     137
     138                $this->assertEquals( $post_id, wp_get_custom_css_post()->ID );
     139                $this->assertEquals( $post_id, wp_get_custom_css_post( $this->setting->stylesheet )->ID );
     140                $this->assertEquals( $twentyten_post_id, wp_get_custom_css_post( 'twentyten' )->ID );
    124141
    125142                $this->assertEquals( $original_css, wp_get_custom_css( $this->setting->stylesheet ) );
    126143                $this->assertEquals( $original_css, $this->setting->value() );
     144                $this->assertEquals( $twentyten_css, wp_get_custom_css( 'twentyten' ) );
     145                $this->assertEquals( $twentyten_css, $twentyten_setting->value() );
    127146
    128147                $updated_css = 'body { color: blue; }';
     
    139158                $this->assertEquals( $previewed_css, $this->setting->value() );
    140159                $this->assertEquals( $previewed_css, wp_get_custom_css( $this->setting->stylesheet ) );
     160
     161                wp_delete_post( $post_id );
     162                $this->assertNull( wp_get_custom_css_post() );
     163                $this->assertNull( wp_get_custom_css_post( get_stylesheet() ) );
     164                $this->assertEquals( $previewed_css, wp_get_custom_css( get_stylesheet() ), 'Previewed value remains in spite of deleted post.' );
     165                wp_delete_post( $twentyten_post_id );
     166                $this->assertNull( wp_get_custom_css_post( 'twentyten' ) );
     167                $this->assertEquals( '', wp_get_custom_css( 'twentyten' ) );
    141168        }
    142169
Note: See TracChangeset for help on using the changeset viewer.