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
This commit is contained in:
parent
827bcc32a8
commit
6f69ca857e
@ -876,10 +876,6 @@ function get_custom_logo( $blog_id = 0 ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$custom_logo_id = get_theme_mod( 'custom_logo' );
|
$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.
|
// We have a logo. Logo is go.
|
||||||
@ -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.
|
* Filter the custom logo output.
|
||||||
*
|
*
|
||||||
|
@ -217,6 +217,37 @@ class Tests_General_Template extends WP_UnitTestCase {
|
|||||||
$this->assertFalse( has_custom_logo() );
|
$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
|
* @group custom_logo
|
||||||
*
|
*
|
||||||
@ -234,6 +265,32 @@ class Tests_General_Template extends WP_UnitTestCase {
|
|||||||
$this->assertEmpty( get_custom_logo() );
|
$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 = '<a href="' . $home_url . '" class="custom-logo-link" rel="home" itemprop="url">' . $image . '</a>';
|
||||||
|
$this->assertEquals( $expected_custom_logo, get_custom_logo( $blog_id ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group custom_logo
|
* @group custom_logo
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user