You appear to be a bot. Output may be restricted
Description
Test crud methods on WP_Customize_Custom_CSS_Setting.
Usage
Test_WP_Customize_Custom_CSS_Setting::test_crud();
Parameters
Returns
void
Source
File name: wordpress-develop-tests/phpunit/tests/customize/custom-css-setting.php
Lines:
1 to 96 of 96
public function test_crud() { $this->setting->default = '/* Hello World */'; $this->assertSame( $this->setting->default, $this->setting->value() ); $this->assertNull( wp_get_custom_css_post() ); $this->assertNull( wp_get_custom_css_post( $this->setting->stylesheet ) ); $this->assertNull( wp_get_custom_css_post( 'twentyten' ) ); $original_css = 'body { color: black; }'; $post_id = $this->factory()->post->create( array( 'post_title' => $this->setting->stylesheet, 'post_name' => $this->setting->stylesheet, 'post_content' => $original_css, 'post_status' => 'publish', 'post_type' => 'custom_css', ) ); $twentyten_css = 'body { color: red; }'; $twentyten_post_id = $this->factory()->post->create( array( 'post_title' => 'twentyten', 'post_name' => 'twentyten', 'post_content' => $twentyten_css, 'post_status' => 'publish', 'post_type' => 'custom_css', ) ); $twentyten_setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[twentyten]' ); remove_theme_mod( 'custom_css_post_id' ); $this->assertSame( $post_id, wp_get_custom_css_post()->ID ); $this->assertSame( $post_id, wp_get_custom_css_post( $this->setting->stylesheet )->ID ); $this->assertSame( $twentyten_post_id, wp_get_custom_css_post( 'twentyten' )->ID ); $this->assertSame( $original_css, wp_get_custom_css( $this->setting->stylesheet ) ); $this->assertSame( $original_css, $this->setting->value() ); $this->assertSame( $twentyten_css, wp_get_custom_css( 'twentyten' ) ); $this->assertSame( $twentyten_css, $twentyten_setting->value() ); $updated_css = 'body { color: blue; }'; $this->wp_customize->set_post_value( $this->setting->id, $updated_css ); $saved = $this->setting->save(); $this->assertNotFalse( $saved ); $this->assertSame( $updated_css, $this->setting->value() ); $this->assertSame( $updated_css, wp_get_custom_css( $this->setting->stylesheet ) ); $this->assertSame( $updated_css, get_post( $post_id )->post_content ); $previewed_css = 'body { color: red; }'; $this->wp_customize->set_post_value( $this->setting->id, $previewed_css ); $this->setting->preview(); $this->assertSame( $previewed_css, $this->setting->value() ); $this->assertSame( $previewed_css, wp_get_custom_css( $this->setting->stylesheet ) ); // Make sure that wp_update_custom_css_post() works as expected for updates. $r = wp_update_custom_css_post( 'body { color:red; }', array( 'stylesheet' => $this->setting->stylesheet, 'preprocessed' => "body\n\tcolor:red;", ) ); $this->assertInstanceOf( 'WP_Post', $r ); $this->assertSame( $post_id, $r->ID ); $this->assertSame( 'body { color:red; }', get_post( $r )->post_content ); $this->assertSame( "body\n\tcolor:red;", get_post( $r )->post_content_filtered ); $r = wp_update_custom_css_post( 'body { content: "\o/"; }' ); $this->assertSame( $this->wp_customize->get_stylesheet(), get_post( $r )->post_name ); $this->assertSame( 'body { content: "\o/"; }', get_post( $r )->post_content ); $this->assertSame( '', get_post( $r )->post_content_filtered ); // Make sure that wp_update_custom_css_post() works as expected for insertion. $r = wp_update_custom_css_post( 'body { background:black; }', array( 'stylesheet' => 'other', ) ); $this->assertInstanceOf( 'WP_Post', $r ); $this->assertSame( 'other', get_post( $r )->post_name ); $this->assertSame( 'body { background:black; }', get_post( $r )->post_content ); $this->assertSame( 'publish', get_post( $r )->post_status ); // Test deletion. wp_delete_post( $post_id ); $this->assertNull( wp_get_custom_css_post() ); $this->assertNull( wp_get_custom_css_post( get_stylesheet() ) ); $this->assertSame( $previewed_css, wp_get_custom_css( get_stylesheet() ), 'Previewed value remains in spite of deleted post.' ); wp_delete_post( $twentyten_post_id ); $this->assertNull( wp_get_custom_css_post( 'twentyten' ) ); $this->assertSame( '', wp_get_custom_css( 'twentyten' ) ); }