- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/custom-css-setting.php
r41376 r42343 32 32 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 33 33 34 $user_id = self::factory()->user->create( array( 35 'role' => 'administrator', 36 ) ); 34 $user_id = self::factory()->user->create( 35 array( 36 'role' => 'administrator', 37 ) 38 ); 37 39 if ( is_multisite() ) { 38 40 grant_super_admin( $user_id ); … … 43 45 global $wp_customize; 44 46 $this->wp_customize = new WP_Customize_Manager(); 45 $wp_customize = $this->wp_customize;47 $wp_customize = $this->wp_customize; 46 48 47 49 do_action( 'customize_register', $this->wp_customize ); … … 118 120 $this->assertNull( wp_get_custom_css_post( 'twentyten' ) ); 119 121 120 $original_css = 'body { color: black; }'; 121 $post_id = $this->factory()->post->create( array( 122 'post_title' => $this->setting->stylesheet, 123 'post_name' => $this->setting->stylesheet, 124 'post_content' => $original_css, 125 'post_status' => 'publish', 126 'post_type' => 'custom_css', 127 ) ); 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 ) ); 122 $original_css = 'body { color: black; }'; 123 $post_id = $this->factory()->post->create( 124 array( 125 'post_title' => $this->setting->stylesheet, 126 'post_name' => $this->setting->stylesheet, 127 'post_content' => $original_css, 128 'post_status' => 'publish', 129 'post_type' => 'custom_css', 130 ) 131 ); 132 $twentyten_css = 'body { color: red; }'; 133 $twentyten_post_id = $this->factory()->post->create( 134 array( 135 'post_title' => 'twentyten', 136 'post_name' => 'twentyten', 137 'post_content' => $twentyten_css, 138 'post_status' => 'publish', 139 'post_type' => 'custom_css', 140 ) 141 ); 136 142 $twentyten_setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[twentyten]' ); 137 143 … … 163 169 164 170 // Make sure that wp_update_custom_css_post() works as expected for updates. 165 $r = wp_update_custom_css_post( 'body { color:red; }', array( 166 'stylesheet' => $this->setting->stylesheet, 167 'preprocessed' => "body\n\tcolor:red;", 168 ) ); 171 $r = wp_update_custom_css_post( 172 'body { color:red; }', array( 173 'stylesheet' => $this->setting->stylesheet, 174 'preprocessed' => "body\n\tcolor:red;", 175 ) 176 ); 169 177 $this->assertInstanceOf( 'WP_Post', $r ); 170 178 $this->assertEquals( $post_id, $r->ID ); … … 177 185 178 186 // Make sure that wp_update_custom_css_post() works as expected for insertion. 179 $r = wp_update_custom_css_post( 'body { background:black; }', array( 180 'stylesheet' => 'other', 181 ) ); 187 $r = wp_update_custom_css_post( 188 'body { background:black; }', array( 189 'stylesheet' => 'other', 190 ) 191 ); 182 192 $this->assertInstanceOf( 'WP_Post', $r ); 183 193 $this->assertEquals( 'other', get_post( $r )->post_name ); … … 202 212 function test_custom_css_revision_saved() { 203 213 $inserted_css = 'body { background: black; }'; 204 $updated_css = 'body { background: red; }'; 205 206 $post = wp_update_custom_css_post( $inserted_css, array( 207 'stylesheet' => 'testtheme', 208 ) ); 214 $updated_css = 'body { background: red; }'; 215 216 $post = wp_update_custom_css_post( 217 $inserted_css, array( 218 'stylesheet' => 'testtheme', 219 ) 220 ); 209 221 210 222 $this->assertSame( $inserted_css, $post->post_content ); … … 213 225 $this->assertSame( $inserted_css, $revisions[0]->post_content ); 214 226 215 wp_update_custom_css_post( $updated_css, array( 216 'stylesheet' => 'testtheme', 217 ) ); 227 wp_update_custom_css_post( 228 $updated_css, array( 229 'stylesheet' => 'testtheme', 230 ) 231 ); 218 232 219 233 $revisions = array_values( wp_get_post_revisions( $post ) ); … … 256 270 $this->assertEquals( '/*default*//*filtered*/', $this->setting->value() ); 257 271 258 $this->factory()->post->create( array( 259 'post_title' => $this->setting->stylesheet, 260 'post_name' => $this->setting->stylesheet, 261 'post_content' => '/*custom*/', 262 'post_status' => 'publish', 263 'post_type' => 'custom_css', 264 ) ); 272 $this->factory()->post->create( 273 array( 274 'post_title' => $this->setting->stylesheet, 275 'post_name' => $this->setting->stylesheet, 276 'post_content' => '/*custom*/', 277 'post_status' => 'publish', 278 'post_type' => 'custom_css', 279 ) 280 ); 265 281 remove_theme_mod( 'custom_css_post_id' ); 266 282 $this->assertEquals( '/*custom*//*filtered*/', $this->setting->value() ); … … 291 307 function test_update_filter() { 292 308 $original_css = 'body { color:red; }'; 293 $post_id = $this->factory()->post->create( array( 294 'post_title' => $this->setting->stylesheet, 295 'post_name' => $this->setting->stylesheet, 296 'post_content' => $original_css, 297 'post_status' => 'publish', 298 'post_type' => 'custom_css', 299 ) ); 309 $post_id = $this->factory()->post->create( 310 array( 311 'post_title' => $this->setting->stylesheet, 312 'post_name' => $this->setting->stylesheet, 313 'post_content' => $original_css, 314 'post_status' => 'publish', 315 'post_type' => 'custom_css', 316 ) 317 ); 300 318 301 319 $overridden_css = 'body { color:green; }'; 302 320 $this->wp_customize->set_post_value( $this->setting->id, $overridden_css ); 303 321 304 $post = get_post( $post_id );322 $post = get_post( $post_id ); 305 323 $original_title = $post->post_title; 306 324 … … 331 349 $this->assertEquals( $args['preprocessed'], $data['preprocessed'] ); 332 350 333 $data['css'] .= '/* filtered post_content */';351 $data['css'] .= '/* filtered post_content */'; 334 352 $data['preprocessed'] = '/* filtered post_content_filtered */'; 335 $data['post_title'] = 'Ignored';353 $data['post_title'] = 'Ignored'; 336 354 return $data; 337 355 } … … 353 371 // Basic, valid CSS throws no errors. 354 372 $basic_css = 'body { background: #f00; } h1.site-title { font-size: 36px; } a:hover { text-decoration: none; } input[type="text"] { padding: 1em; }'; 355 $result = $this->setting->validate( $basic_css );373 $result = $this->setting->validate( $basic_css ); 356 374 $this->assertTrue( $result ); 357 375 358 376 // Check for markup. 359 377 $unclosed_comment = $basic_css . '</style>'; 360 $result = $this->setting->validate( $unclosed_comment );378 $result = $this->setting->validate( $unclosed_comment ); 361 379 $this->assertTrue( array_key_exists( 'illegal_markup', $result->errors ) ); 362 380 }
Note: See TracChangeset
for help on using the changeset viewer.