Make WordPress Core

Changeset 36949


Ignore:
Timestamp:
03/10/2016 06:56:56 PM (9 years ago)
Author:
obenland
Message:

Tests: Introduce multisite unit tests.

Makes sure custom logo functions work for other sites within a network.
Fixes a bug in get_custom_logo() where the correct logo was returned, but
linked to the wrong site.

H/t ocean90.
See #33755, #36086.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r36939 r36949  
    877877
    878878    $custom_logo_id = get_theme_mod( 'custom_logo' );
    879 
    880     if ( is_multisite() && ms_is_switched() ) {
    881         restore_current_blog();
    882     }
    883     $size = get_theme_support( 'custom-logo', 'size' );
     879    $size           = get_theme_support( 'custom-logo', 'size' );
    884880
    885881    // We have a logo. Logo is go.
     
    901897            esc_attr( $size )
    902898        );
     899    }
     900
     901    if ( is_multisite() && ms_is_switched() ) {
     902        restore_current_blog();
    903903    }
    904904
  • trunk/tests/phpunit/tests/general/template.php

    r36914 r36949  
    220220    /**
    221221     * @group custom_logo
     222     * @group multisite
     223     */
     224    function test_has_custom_logo_returns_true_when_called_for_other_site_with_custom_logo_set() {
     225        if ( ! is_multisite() ) {
     226            $this->markTestSkipped( 'This test requires multisite.' );
     227        }
     228
     229        $blog_id = $this->factory->blog->create();
     230        switch_to_blog( $blog_id );
     231        $this->_set_custom_logo();
     232        restore_current_blog();
     233
     234        $this->assertTrue( has_custom_logo( $blog_id ) );
     235    }
     236
     237    /**
     238     * @group custom_logo
     239     * @group multisite
     240     */
     241    function test_has_custom_logo_returns_false_when_called_for_other_site_without_custom_logo_set() {
     242        if ( ! is_multisite() ) {
     243            $this->markTestSkipped( 'This test requires multisite.' );
     244        }
     245
     246        $blog_id = $this->factory->blog->create();
     247
     248        $this->assertFalse( has_custom_logo( $blog_id ) );
     249    }
     250
     251    /**
     252     * @group custom_logo
    222253     *
    223254     * @since 4.5.0
     
    233264        $this->_remove_custom_logo();
    234265        $this->assertEmpty( get_custom_logo() );
     266    }
     267
     268    /**
     269     * @group custom_logo
     270     * @group multisite
     271     */
     272    function test_get_custom_logo_returns_logo_when_called_for_other_site_with_custom_logo_set() {
     273        if ( ! is_multisite() ) {
     274            $this->markTestSkipped( 'This test requires multisite.' );
     275        }
     276
     277        $blog_id = $this->factory->blog->create();
     278        switch_to_blog( $blog_id );
     279
     280        $this->_set_custom_logo();
     281        $home_url = get_home_url( $blog_id, '/' );
     282        $size     = get_theme_support( 'custom-logo', 'size' );
     283        $image    = wp_get_attachment_image( $this->custom_logo_id, $size, false, array(
     284            'class'     => "custom-logo attachment-$size",
     285            'data-size' => $size,
     286            'itemprop'  => 'logo',
     287        ) );
     288        restore_current_blog();
     289
     290        $expected_custom_logo =  '<a href="' . $home_url . '" class="custom-logo-link" rel="home" itemprop="url">' . $image . '</a>';
     291        $this->assertEquals( $expected_custom_logo, get_custom_logo( $blog_id ) );
    235292    }
    236293
Note: See TracChangeset for help on using the changeset viewer.