| | 89 | |
| | 90 | /** |
| | 91 | * Test if inline styles work |
| | 92 | * @ticket 24813 |
| | 93 | */ |
| | 94 | public function test_inline_styles() { |
| | 95 | |
| | 96 | $style = ".thing {\n"; |
| | 97 | $style .= "\tbackground: red;\n"; |
| | 98 | $style .= "}"; |
| | 99 | |
| | 100 | $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; |
| | 101 | $expected .= "<style type='text/css'>\n"; |
| | 102 | $expected .= "$style\n"; |
| | 103 | $expected .= "</style>\n"; |
| | 104 | |
| | 105 | wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); |
| | 106 | wp_add_inline_style( 'handle', $style ); |
| | 107 | |
| | 108 | // No styles left to print |
| | 109 | $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); |
| | 110 | } |
| | 111 | |
| | 112 | /** |
| | 113 | * Test if inline styles work with concatination |
| | 114 | * @global WP_Styles $wp_styles |
| | 115 | * @ticket 24813 |
| | 116 | */ |
| | 117 | public function test_inline_styles_concat() { |
| | 118 | |
| | 119 | global $wp_styles; |
| | 120 | |
| | 121 | $wp_styles->do_concat = true; |
| | 122 | $wp_styles->default_dirs = array( '/wp-admin/', '/wp-includes/css/' ); // Default dirs as in wp-includes/script-loader.php |
| | 123 | |
| | 124 | $style = ".thing {\n"; |
| | 125 | $style .= "\tbackground: red;\n"; |
| | 126 | $style .= "}"; |
| | 127 | |
| | 128 | $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; |
| | 129 | $expected .= "<style type='text/css'>\n"; |
| | 130 | $expected .= "$style\n"; |
| | 131 | $expected .= "</style>\n"; |
| | 132 | |
| | 133 | wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); |
| | 134 | wp_add_inline_style( 'handle', $style ); |
| | 135 | |
| | 136 | wp_print_styles(); |
| | 137 | $this->assertEquals( $expected, $wp_styles->print_html ); |
| | 138 | |
| | 139 | } |
| | 140 | |
| | 141 | /** |
| | 142 | * Test if multiple inline styles work |
| | 143 | * @ticket 24813 |
| | 144 | */ |
| | 145 | public function test_multiple_inline_styles() { |
| | 146 | |
| | 147 | $style1 = ".thing1 {\n"; |
| | 148 | $style1 .= "\tbackground: red;\n"; |
| | 149 | $style1 .= "}"; |
| | 150 | |
| | 151 | $style2 = ".thing2 {\n"; |
| | 152 | $style2 .= "\tbackground: blue;\n"; |
| | 153 | $style2 .= "}"; |
| | 154 | |
| | 155 | $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; |
| | 156 | $expected .= "<style type='text/css'>\n"; |
| | 157 | $expected .= "$style1\n"; |
| | 158 | $expected .= "$style2\n"; |
| | 159 | $expected .= "</style>\n"; |
| | 160 | |
| | 161 | wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); |
| | 162 | wp_add_inline_style( 'handle', $style1 ); |
| | 163 | wp_add_inline_style( 'handle', $style2 ); |
| | 164 | |
| | 165 | // No styles left to print |
| | 166 | $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); |
| | 167 | |
| | 168 | } |
| | 169 | |
| | 170 | /** |
| | 171 | * Test if a plugin doing it the wrong way still works |
| | 172 | * @ticket 24813 |
| | 173 | */ |
| | 174 | public function test_plugin_doing_inline_styles_wrong() { |
| | 175 | |
| | 176 | $style = "<style type='text/css'>\n"; |
| | 177 | $style .= ".thing {\n"; |
| | 178 | $style .= "\tbackground: red;\n"; |
| | 179 | $style .= "}\n"; |
| | 180 | $style .= "</style>"; |
| | 181 | |
| | 182 | $expected = "<link rel='stylesheet' id='handle-css' href='http://example.com?ver=1' type='text/css' media='all' />\n"; |
| | 183 | $expected .= "$style\n"; |
| | 184 | |
| | 185 | wp_enqueue_style( 'handle', 'http://example.com', array(), 1 ); |
| | 186 | |
| | 187 | // Suppress _doing_it_wrong error |
| | 188 | @wp_add_inline_style( 'handle', $style ); |
| | 189 | |
| | 190 | $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); |
| | 191 | |
| | 192 | } |
| | 193 | |