From b0e625bfdf8f187e0ca97e10ac0abec80ea1996e Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 20 Oct 2016 09:06:11 +0000 Subject: [PATCH] Tests: Fix tests that don't pass when Twenty Seventeen is the default theme. There are some tests who's outcome can be affected by the default theme, so we need to ensure the Twenty Seventeen functionality is unhooked while the tests are running. See #38372. git-svn-id: https://develop.svn.wordpress.org/trunk@38838 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/customize/widgets.php | 1 + tests/phpunit/tests/media.php | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/customize/widgets.php b/tests/phpunit/tests/customize/widgets.php index c0836d39e5..310320b18c 100644 --- a/tests/phpunit/tests/customize/widgets.php +++ b/tests/phpunit/tests/customize/widgets.php @@ -44,6 +44,7 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase { remove_action( 'after_setup_theme', 'twentyfifteen_setup' ); remove_action( 'after_setup_theme', 'twentysixteen_setup' ); remove_action( 'customize_register', 'twentysixteen_customize_register', 11 ); + remove_action( 'after_setup_theme', 'twentyseventeen_setup' ); $this->backup_registered_sidebars = $GLOBALS['wp_registered_sidebars']; diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 7209f5e69e..d8d1569967 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -33,6 +33,18 @@ CAP; $this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name; $this->img_html = ''; $this->img_meta = array( 'width' => 100, 'height' => 100, 'sizes' => '' ); + + // Disable Twenty Seventeen changes to the image size attribute + remove_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr' ); + remove_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr' ); + } + + function tearDown() { + parent::tearDown(); + + // Reset Twenty Seventeen behaviour + add_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2 ); + add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 ); } function test_img_caption_shortcode_added() { @@ -55,10 +67,16 @@ CAP; $result = img_caption_shortcode( array( 'width' => 20, 'caption' => $this->caption ) ); + $this->assertEquals( 2, preg_match_all( '/wp-caption/', $result, $_r ) ); $this->assertEquals( 1, preg_match_all( '/alignnone/', $result, $_r ) ); $this->assertEquals( 1, preg_match_all( "/{$this->caption}/", $result, $_r ) ); - $this->assertEquals( 1, preg_match_all( "/width: 30/", $result, $_r ) ); + + if ( current_theme_supports( 'html5', 'caption' ) ) { + $this->assertEquals( 1, preg_match_all( "/width: 20/", $result, $_r ) ); + } else { + $this->assertEquals( 1, preg_match_all( "/width: 30/", $result, $_r ) ); + } } function test_img_caption_shortcode_with_old_format_id_and_align() {