Add Automated Tests for custom logo support

[36698] introduced custom logos, this tests the API. 

Fixes #36086. See #33755.
Props obenland.



git-svn-id: https://develop.svn.wordpress.org/trunk@36905 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Aaron Jorbin 2016-03-09 20:43:28 +00:00
parent 7e71bb398c
commit 6adbde9340
2 changed files with 138 additions and 0 deletions

View File

@ -11,6 +11,9 @@ class Tests_General_Template extends WP_UnitTestCase {
public $site_icon_id;
public $site_icon_url;
public $custom_logo_id;
public $custom_logo_url;
function setUp() {
parent::setUp();
@ -18,6 +21,12 @@ class Tests_General_Template extends WP_UnitTestCase {
$this->wp_site_icon = $GLOBALS['wp_site_icon'];
}
function tearDown() {
$this->_remove_custom_logo();
parent::tearDown();
}
/**
* @group site_icon
*/
@ -192,4 +201,88 @@ class Tests_General_Template extends WP_UnitTestCase {
$this->site_icon_id = $this->_make_attachment( $upload );
return $this->site_icon_id;
}
/**
* @group custom_logo
*
* @since 4.5.0
*/
function test_has_custom_logo() {
$this->assertFalse( has_custom_logo() );
$this->_set_custom_logo();
$this->assertTrue( has_custom_logo() );
$this->_remove_custom_logo();
$this->assertFalse( has_custom_logo() );
}
/**
* @group custom_logo
*
* @since 4.5.0
*/
function test_get_custom_logo() {
$this->assertEmpty( get_custom_logo() );
$this->_set_custom_logo();
$custom_logo = get_custom_logo();
$this->assertNotEmpty( $custom_logo );
$this->assertInternalType( 'string', $custom_logo );
$this->_remove_custom_logo();
$this->assertEmpty( get_custom_logo() );
}
/**
* @group custom_logo
*
* @since 4.5.0
*/
function test_the_custom_logo() {
$this->expectOutputString( '' );
the_custom_logo();
$this->_set_custom_logo();
$this->expectOutputString( '<a href="http://example.org/" class="custom-logo-link" rel="home" itemprop="url"><img width="50" height="50" src="' . $this->custom_logo_url . '" class="custom-logo attachment-" alt="' . basename( $this->custom_logo_url ) . '" data-size="" itemprop="logo" /></a>' );
the_custom_logo();
}
/**
* Sets a site icon in options for testing.
*
* @since 4.5.0
*/
function _set_custom_logo() {
if ( ! $this->custom_logo_id ) {
$this->_insert_custom_logo();
}
set_theme_mod( 'custom_logo', $this->custom_logo_id );
}
/**
* Removes the site icon from options.
*
* @since 4.5.0
*/
function _remove_custom_logo() {
remove_theme_mod( 'custom_logo' );
}
/**
* Inserts an attachment for testing custom logos.
*
* @since 4.5.0
*/
function _insert_custom_logo() {
$filename = DIR_TESTDATA . '/images/test-image.jpg';
$contents = file_get_contents( $filename );
$upload = wp_upload_bits( basename( $filename ), null, $contents );
// Save the data.
$this->custom_logo_url = $upload['url'];
$this->custom_logo_id = $this->_make_attachment( $upload );
return $this->custom_logo_id;
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* Tests for the WP_Custom_logo class.
*
* @group custom_logo
*/
class Tests_WP_Custom_Logo extends WP_UnitTestCase {
public $attachment_id = 0;
function setUp() {
parent::setUp();
require_once ABSPATH . 'wp-admin/includes/class-wp-custom-logo.php';
}
function tearDown() {
$this->custom_logo = null;
$this->remove_added_uploads();
parent::tearDown();
}
function test_delete_attachment_data() {
$attachment_id = $this->_insert_attachment();
set_theme_mod( 'custom_logo', $attachment_id );
wp_delete_attachment( $attachment_id, true );
$this->assertFalse( get_theme_mod( 'custom_logo' ) );
}
function _insert_attachment() {
if ( $this->attachment_id ) {
return $this->attachment_id;
}
$filename = DIR_TESTDATA . '/images/test-image.jpg';
$contents = file_get_contents( $filename );
$upload = wp_upload_bits( basename( $filename ), null, $contents );
$this->attachment_id = $this->_make_attachment( $upload );
return $this->attachment_id;
}
}