| | 195 | |
| | 196 | /** |
| | 197 | * @group custom_logo |
| | 198 | * |
| | 199 | * @since 4.5.0 |
| | 200 | */ |
| | 201 | function test_has_custom_logo() { |
| | 202 | $this->assertFalse( has_custom_logo() ); |
| | 203 | |
| | 204 | $this->_set_custom_logo(); |
| | 205 | $this->assertTrue( has_custom_logo() ); |
| | 206 | |
| | 207 | $this->_remove_custom_logo(); |
| | 208 | $this->assertFalse( has_custom_logo() ); |
| | 209 | } |
| | 210 | |
| | 211 | /** |
| | 212 | * @group custom_logo |
| | 213 | * |
| | 214 | * @since 4.5.0 |
| | 215 | */ |
| | 216 | function test_get_custom_logo() { |
| | 217 | $this->assertEmpty( get_custom_logo() ); |
| | 218 | |
| | 219 | $this->_set_custom_logo(); |
| | 220 | $custom_logo = get_custom_logo(); |
| | 221 | $this->assertNotEmpty( $custom_logo ); |
| | 222 | $this->assertInternalType( 'string', $custom_logo ); |
| | 223 | |
| | 224 | $this->_remove_custom_logo(); |
| | 225 | $this->assertEmpty( get_custom_logo() ); |
| | 226 | } |
| | 227 | |
| | 228 | /** |
| | 229 | * @group custom_logo |
| | 230 | * |
| | 231 | * @since 4.5.0 |
| | 232 | */ |
| | 233 | function test_the_custom_logo() { |
| | 234 | $this->expectOutputString( '' ); |
| | 235 | the_custom_logo(); |
| | 236 | |
| | 237 | $this->_set_custom_logo(); |
| | 238 | $this->expectOutputString( get_custom_logo() ); |
| | 239 | the_custom_logo(); |
| | 240 | $this->_remove_custom_logo(); |
| | 241 | } |
| | 242 | |
| | 243 | /** |
| | 244 | * Sets a site icon in options for testing. |
| | 245 | * |
| | 246 | * @since 4.5.0 |
| | 247 | */ |
| | 248 | function _set_custom_logo() { |
| | 249 | if ( ! $this->custom_logo_id ) { |
| | 250 | $this->_insert_custom_logo(); |
| | 251 | } |
| | 252 | |
| | 253 | set_theme_mod( 'custom_logo', $this->custom_logo_id ); |
| | 254 | } |
| | 255 | |
| | 256 | /** |
| | 257 | * Removes the site icon from options. |
| | 258 | * |
| | 259 | * @since 4.5.0 |
| | 260 | */ |
| | 261 | function _remove_custom_logo() { |
| | 262 | remove_theme_mod( 'custom_logo' ); |
| | 263 | } |
| | 264 | |
| | 265 | /** |
| | 266 | * Inserts an attachment for testing custom logos. |
| | 267 | * |
| | 268 | * @since 4.5.0 |
| | 269 | */ |
| | 270 | function _insert_custom_logo() { |
| | 271 | $filename = DIR_TESTDATA . '/images/test-image.jpg'; |
| | 272 | $contents = file_get_contents( $filename ); |
| | 273 | $upload = wp_upload_bits( basename( $filename ), null, $contents ); |
| | 274 | |
| | 275 | // Save the data. |
| | 276 | $this->custom_logo_id = $this->_make_attachment( $upload ); |
| | 277 | return $this->custom_logo_id; |
| | 278 | } |