Make WordPress Core

Ticket #36086: 36086.diff

File 36086.diff, 3.5 KB (added by obenland, 9 years ago)
  • tests/phpunit/tests/general/template.php

     
    192192                $this->site_icon_id = $this->_make_attachment( $upload );
    193193                return $this->site_icon_id;
    194194        }
     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        }
    195279}
  • tests/phpunit/tests/image/custom_logo.php

     
     1<?php
     2
     3/**
     4 * Tests for the WP_Custom_logo class.
     5 *
     6 * @group custom_logo
     7 */
     8class Tests_WP_Custom_Logo extends WP_UnitTestCase {
     9        public $wp_custom_logo;
     10        public $attachment_id = 0;
     11
     12        function setUp() {
     13                parent::setUp();
     14
     15                require_once ABSPATH . 'wp-admin/includes/class-wp-custom-logo.php';
     16                $this->wp_custom_logo = $GLOBALS['wp_custom_logo'];
     17        }
     18
     19        function tearDown() {
     20                $this->custom_logo = null;
     21                $this->remove_added_uploads();
     22                parent::tearDown();
     23        }
     24
     25        function test_delete_attachment_data() {
     26                $attachment_id = $this->_insert_attachment();
     27                set_theme_mod( 'custom_logo', $attachment_id );
     28
     29                wp_delete_attachment( $attachment_id, true );
     30
     31                $this->assertFalse( get_theme_mod( 'custom_logo' ) );
     32        }
     33
     34        function _insert_attachment() {
     35                if ( $this->attachment_id ) {
     36                        return $this->attachment_id;
     37                }
     38
     39                $filename = DIR_TESTDATA . '/images/test-image.jpg';
     40                $contents = file_get_contents( $filename );
     41
     42                $upload = wp_upload_bits( basename( $filename ), null, $contents );
     43
     44                $this->attachment_id = $this->_make_attachment( $upload );
     45                return $this->attachment_id;
     46        }
     47}