From 6f69ca857e1a9539194cbebbab31d2c228d3c946 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Thu, 10 Mar 2016 18:56:56 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@36949 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/general-template.php | 10 ++--- tests/phpunit/tests/general/template.php | 57 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 9246da0dc1..e8e936cbc4 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -876,11 +876,7 @@ function get_custom_logo( $blog_id = 0 ) { } $custom_logo_id = get_theme_mod( 'custom_logo' ); - - if ( is_multisite() && ms_is_switched() ) { - restore_current_blog(); - } - $size = get_theme_support( 'custom-logo', 'size' ); + $size = get_theme_support( 'custom-logo', 'size' ); // We have a logo. Logo is go. if ( $custom_logo_id ) { @@ -902,6 +898,10 @@ function get_custom_logo( $blog_id = 0 ) { ); } + if ( is_multisite() && ms_is_switched() ) { + restore_current_blog(); + } + /** * Filter the custom logo output. * diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php index 5b987c872d..c7807e2c28 100644 --- a/tests/phpunit/tests/general/template.php +++ b/tests/phpunit/tests/general/template.php @@ -217,6 +217,37 @@ class Tests_General_Template extends WP_UnitTestCase { $this->assertFalse( has_custom_logo() ); } + /** + * @group custom_logo + * @group multisite + */ + function test_has_custom_logo_returns_true_when_called_for_other_site_with_custom_logo_set() { + if ( ! is_multisite() ) { + $this->markTestSkipped( 'This test requires multisite.' ); + } + + $blog_id = $this->factory->blog->create(); + switch_to_blog( $blog_id ); + $this->_set_custom_logo(); + restore_current_blog(); + + $this->assertTrue( has_custom_logo( $blog_id ) ); + } + + /** + * @group custom_logo + * @group multisite + */ + function test_has_custom_logo_returns_false_when_called_for_other_site_without_custom_logo_set() { + if ( ! is_multisite() ) { + $this->markTestSkipped( 'This test requires multisite.' ); + } + + $blog_id = $this->factory->blog->create(); + + $this->assertFalse( has_custom_logo( $blog_id ) ); + } + /** * @group custom_logo * @@ -234,6 +265,32 @@ class Tests_General_Template extends WP_UnitTestCase { $this->assertEmpty( get_custom_logo() ); } + /** + * @group custom_logo + * @group multisite + */ + function test_get_custom_logo_returns_logo_when_called_for_other_site_with_custom_logo_set() { + if ( ! is_multisite() ) { + $this->markTestSkipped( 'This test requires multisite.' ); + } + + $blog_id = $this->factory->blog->create(); + switch_to_blog( $blog_id ); + + $this->_set_custom_logo(); + $home_url = get_home_url( $blog_id, '/' ); + $size = get_theme_support( 'custom-logo', 'size' ); + $image = wp_get_attachment_image( $this->custom_logo_id, $size, false, array( + 'class' => "custom-logo attachment-$size", + 'data-size' => $size, + 'itemprop' => 'logo', + ) ); + restore_current_blog(); + + $expected_custom_logo = ''; + $this->assertEquals( $expected_custom_logo, get_custom_logo( $blog_id ) ); + } + /** * @group custom_logo *