WordPress.org

Make WordPress Core

Changeset 36905


Ignore:
Timestamp:
03/09/2016 08:43:28 PM (5 years ago)
Author:
jorbin
Message:

Add Automated Tests for custom logo support

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

Fixes #36086. See #33755.
Props obenland.

Location:
trunk/tests/phpunit/tests
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/general/template.php

    r35572 r36905  
    1212    public $site_icon_url;
    1313
     14    public $custom_logo_id;
     15    public $custom_logo_url;
     16
    1417    function setUp() {
    1518        parent::setUp();
     
    1720        require_once ABSPATH . 'wp-admin/includes/class-wp-site-icon.php';
    1821        $this->wp_site_icon = $GLOBALS['wp_site_icon'];
     22    }
     23
     24    function tearDown() {
     25        $this->_remove_custom_logo();
     26
     27        parent::tearDown();
    1928    }
    2029
     
    193202        return $this->site_icon_id;
    194203    }
     204
     205    /**
     206     * @group custom_logo
     207     *
     208     * @since 4.5.0
     209     */
     210    function test_has_custom_logo() {
     211        $this->assertFalse( has_custom_logo() );
     212
     213        $this->_set_custom_logo();
     214        $this->assertTrue( has_custom_logo() );
     215
     216        $this->_remove_custom_logo();
     217        $this->assertFalse( has_custom_logo() );
     218    }
     219
     220    /**
     221     * @group custom_logo
     222     *
     223     * @since 4.5.0
     224     */
     225    function test_get_custom_logo() {
     226        $this->assertEmpty( get_custom_logo() );
     227
     228        $this->_set_custom_logo();
     229        $custom_logo = get_custom_logo();
     230        $this->assertNotEmpty( $custom_logo );
     231        $this->assertInternalType( 'string', $custom_logo );
     232
     233        $this->_remove_custom_logo();
     234        $this->assertEmpty( get_custom_logo() );
     235    }
     236
     237    /**
     238     * @group custom_logo
     239     *
     240     * @since 4.5.0
     241     */
     242    function test_the_custom_logo() {
     243        $this->expectOutputString( '' );
     244        the_custom_logo();
     245
     246        $this->_set_custom_logo();
     247        $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>' );
     248        the_custom_logo();
     249    }
     250
     251    /**
     252     * Sets a site icon in options for testing.
     253     *
     254     * @since 4.5.0
     255     */
     256    function _set_custom_logo() {
     257        if ( ! $this->custom_logo_id ) {
     258            $this->_insert_custom_logo();
     259        }
     260
     261        set_theme_mod( 'custom_logo', $this->custom_logo_id );
     262    }
     263
     264    /**
     265     * Removes the site icon from options.
     266     *
     267     * @since 4.5.0
     268     */
     269    function _remove_custom_logo() {
     270        remove_theme_mod( 'custom_logo' );
     271    }
     272
     273    /**
     274     * Inserts an attachment for testing custom logos.
     275     *
     276     * @since 4.5.0
     277     */
     278    function _insert_custom_logo() {
     279        $filename = DIR_TESTDATA . '/images/test-image.jpg';
     280        $contents = file_get_contents( $filename );
     281        $upload   = wp_upload_bits( basename( $filename ), null, $contents );
     282
     283        // Save the data.
     284        $this->custom_logo_url = $upload['url'];
     285        $this->custom_logo_id  = $this->_make_attachment( $upload );
     286        return $this->custom_logo_id;
     287    }
    195288}
Note: See TracChangeset for help on using the changeset viewer.