Changeset 42343 for trunk/tests/phpunit/tests/dependencies/styles.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/dependencies/styles.php
r36649 r42343 9 9 function setUp() { 10 10 parent::setUp(); 11 if ( empty( $GLOBALS['wp_styles'] ) ) 11 if ( empty( $GLOBALS['wp_styles'] ) ) { 12 12 $GLOBALS['wp_styles'] = null; 13 } 13 14 $this->old_wp_styles = $GLOBALS['wp_styles']; 14 15 remove_action( 'wp_default_styles', 'wp_default_styles' ); 15 16 remove_action( 'wp_print_styles', 'print_emoji_styles' ); 16 $GLOBALS['wp_styles'] = new WP_Styles();17 $GLOBALS['wp_styles'] = new WP_Styles(); 17 18 $GLOBALS['wp_styles']->default_version = get_bloginfo( 'version' ); 18 19 } … … 27 28 /** 28 29 * Test versioning 30 * 29 31 * @ticket 11315 30 32 */ 31 33 function test_wp_enqueue_style() { 32 wp_enqueue_style( 'no-deps-no-version', 'example.com' );33 wp_enqueue_style( 'no-deps-version', 'example.com', array(), 1.2);34 wp_enqueue_style( 'no-deps-null-version', 'example.com', array(), null);35 wp_enqueue_style( 'no-deps-null-version-print-media', 'example.com', array(), null, 'print');36 $ver = get_bloginfo( 'version' );34 wp_enqueue_style( 'no-deps-no-version', 'example.com' ); 35 wp_enqueue_style( 'no-deps-version', 'example.com', array(), 1.2 ); 36 wp_enqueue_style( 'no-deps-null-version', 'example.com', array(), null ); 37 wp_enqueue_style( 'no-deps-null-version-print-media', 'example.com', array(), null, 'print' ); 38 $ver = get_bloginfo( 'version' ); 37 39 $expected = "<link rel='stylesheet' id='no-deps-no-version-css' href='http://example.com?ver=$ver' type='text/css' media='all' />\n"; 38 40 $expected .= "<link rel='stylesheet' id='no-deps-version-css' href='http://example.com?ver=1.2' type='text/css' media='all' />\n"; … … 40 42 $expected .= "<link rel='stylesheet' id='no-deps-null-version-print-media-css' href='http://example.com' type='text/css' media='print' />\n"; 41 43 42 $this->assertEquals( $expected, get_echo('wp_print_styles'));44 $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); 43 45 44 46 // No styles left to print 45 $this->assertEquals( "", get_echo('wp_print_styles'));47 $this->assertEquals( '', get_echo( 'wp_print_styles' ) ); 46 48 } 47 49 48 50 /** 49 51 * Test the different protocol references in wp_enqueue_style 52 * 50 53 * @global WP_Styles $wp_styles 51 54 * @ticket 16560 … … 54 57 // Init 55 58 global $wp_styles; 56 $base_url_backup = $wp_styles->base_url;59 $base_url_backup = $wp_styles->base_url; 57 60 $wp_styles->base_url = 'http://example.com/wordpress'; 58 $expected = '';59 $ver = get_bloginfo( 'version' );61 $expected = ''; 62 $ver = get_bloginfo( 'version' ); 60 63 61 64 // Try with an HTTP reference 62 65 wp_enqueue_style( 'reset-css-http', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' ); 63 $expected .= "<link rel='stylesheet' id='reset-css-http-css' href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";66 $expected .= "<link rel='stylesheet' id='reset-css-http-css' href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n"; 64 67 65 68 // Try with an HTTPS reference 66 69 wp_enqueue_style( 'reset-css-https', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' ); 67 $expected .= "<link rel='stylesheet' id='reset-css-https-css' href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";70 $expected .= "<link rel='stylesheet' id='reset-css-https-css' href='http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n"; 68 71 69 72 // Try with an automatic protocol reference (//) 70 73 wp_enqueue_style( 'reset-css-doubleslash', '//yui.yahooapis.com/2.8.1/build/reset/reset-min.css' ); 71 $expected .= "<link rel='stylesheet' id='reset-css-doubleslash-css' href='//yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";74 $expected .= "<link rel='stylesheet' id='reset-css-doubleslash-css' href='//yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n"; 72 75 73 76 // Try with a local resource and an automatic protocol reference (//) 74 77 $url = '//my_plugin/style.css'; 75 78 wp_enqueue_style( 'plugin-style', $url ); 76 $expected .= "<link rel='stylesheet' id='plugin-style-css' href='$url?ver=$ver' type='text/css' media='all' />\n";79 $expected .= "<link rel='stylesheet' id='plugin-style-css' href='$url?ver=$ver' type='text/css' media='all' />\n"; 77 80 78 81 // Try with a bad protocol 79 82 wp_enqueue_style( 'reset-css-ftp', 'ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css' ); 80 $expected .= "<link rel='stylesheet' id='reset-css-ftp-css' href='{$wp_styles->base_url}ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n";83 $expected .= "<link rel='stylesheet' id='reset-css-ftp-css' href='{$wp_styles->base_url}ftp://yui.yahooapis.com/2.8.1/build/reset/reset-min.css?ver=$ver' type='text/css' media='all' />\n"; 81 84 82 85 // Go! … … 92 95 /** 93 96 * Test if inline styles work 97 * 94 98 * @ticket 24813 95 99 */ … … 98 102 $style = ".thing {\n"; 99 103 $style .= "\tbackground: red;\n"; 100 $style .= "}";104 $style .= '}'; 101 105 102 106 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; … … 114 118 /** 115 119 * Test if inline styles work with concatination 120 * 116 121 * @global WP_Styles $wp_styles 117 122 * @ticket 24813 … … 121 126 global $wp_styles; 122 127 123 $wp_styles->do_concat = true;128 $wp_styles->do_concat = true; 124 129 $wp_styles->default_dirs = array( '/wp-admin/', '/wp-includes/css/' ); // Default dirs as in wp-includes/script-loader.php 125 130 126 131 $style = ".thing {\n"; 127 132 $style .= "\tbackground: red;\n"; 128 $style .= "}";133 $style .= '}'; 129 134 130 135 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; … … 143 148 /** 144 149 * Test if multiple inline styles work 150 * 145 151 * @ticket 24813 146 152 */ … … 149 155 $style1 = ".thing1 {\n"; 150 156 $style1 .= "\tbackground: red;\n"; 151 $style1 .= "}";157 $style1 .= '}'; 152 158 153 159 $style2 = ".thing2 {\n"; 154 160 $style2 .= "\tbackground: blue;\n"; 155 $style2 .= "}";161 $style2 .= '}'; 156 162 157 163 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; … … 182 188 $style .= "\tbackground: red;\n"; 183 189 $style .= "}\n"; 184 $style .= "</style>";190 $style .= '</style>'; 185 191 186 192 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; … … 197 203 /** 198 204 * Test to make sure <style> tags aren't output if there are no inline styles. 205 * 199 206 * @ticket 24813 200 207 */ 201 208 public function test_unnecessary_style_tags() { 202 209 203 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n";210 $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; 204 211 205 212 wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); … … 244 251 */ 245 252 function test_wp_add_inline_style_for_handle_without_source() { 246 $style = "a { color: blue; }";253 $style = 'a { color: blue; }'; 247 254 248 255 $expected = "<link rel='stylesheet' id='handle-one-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; … … 275 282 array( 276 283 "media='all'", 277 'all' 284 'all', 278 285 ), 279 286 array( 280 287 "media='(orientation: portrait)'", 281 '(orientation: portrait)' 288 '(orientation: portrait)', 282 289 ), 283 290 array( 284 291 "media='(max-width: 640px)'", 285 '(max-width: 640px)' 292 '(max-width: 640px)', 286 293 ), 287 294 array( 288 295 "media='print and (min-width: 25cm)'", 289 'print and (min-width: 25cm)' 296 'print and (min-width: 25cm)', 290 297 ), 291 298 array( 292 299 "media='screen and (color), projection and (color)'", 293 'screen and (color), projection and (color)' 300 'screen and (color), projection and (color)', 294 301 ), 295 302 array( 296 303 "media='not screen and (color)'", 297 'not screen and (color)' 304 'not screen and (color)', 298 305 ), 299 306 );
Note: See TracChangeset
for help on using the changeset viewer.