From d854564f737d81341079777fd2f08982ff7965c0 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sun, 22 Feb 2015 21:06:36 +0000 Subject: [PATCH] Better image-type support checks in image unit tests. PHP can be compiled without support for certain image types. Our unit tests should be sensitive to these configurations. Fixes #31124. git-svn-id: https://develop.svn.wordpress.org/trunk@31510 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/image/editor_gd.php | 33 +++++++++++++++++++------ tests/phpunit/tests/image/functions.php | 8 ++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/image/editor_gd.php b/tests/phpunit/tests/image/editor_gd.php index c2ef69d2ef..21f54656f1 100644 --- a/tests/phpunit/tests/image/editor_gd.php +++ b/tests/phpunit/tests/image/editor_gd.php @@ -31,15 +31,22 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { parent::tearDown(); } - /** - * Check support for GD compatible mime types. - */ - public function test_supports_mime_type() { + public function test_supports_mime_type_jpeg() { $gd_image_editor = new WP_Image_Editor_GD( null ); + $expected = imagetypes() & IMG_JPG; + $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/jpeg' ) ); + } - $this->assertTrue( $gd_image_editor->supports_mime_type( 'image/jpeg' ), 'Does not support image/jpeg' ); - $this->assertTrue( $gd_image_editor->supports_mime_type( 'image/png' ), 'Does not support image/png' ); - $this->assertTrue( $gd_image_editor->supports_mime_type( 'image/gif' ), 'Does not support image/gif' ); + public function test_supports_mime_type_png() { + $gd_image_editor = new WP_Image_Editor_GD( null ); + $expected = imagetypes() & IMG_PNG; + $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/png' ) ); + } + + public function test_supports_mime_type_gif() { + $gd_image_editor = new WP_Image_Editor_GD( null ); + $expected = imagetypes() & IMG_GIF; + $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/gif' ) ); } /** @@ -460,6 +467,10 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { * @ticket 23039 */ public function test_image_preserves_alpha_on_resize() { + if ( ! ( imagetypes() & IMG_PNG ) ) { + $this->markTestSkipped( 'This test requires PHP to be compiled with PNG support.' ); + } + $file = DIR_TESTDATA . '/images/transparent.png'; $editor = wp_get_image_editor( $file ); @@ -483,6 +494,10 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { * @ticket 23039 */ public function test_image_preserves_alpha() { + if ( ! ( imagetypes() & IMG_PNG ) ) { + $this->markTestSkipped( 'This test requires PHP to be compiled with PNG support.' ); + } + $file = DIR_TESTDATA . '/images/transparent.png'; $editor = wp_get_image_editor( $file ); @@ -505,6 +520,10 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { * @ticket 30596 */ public function test_image_preserves_alpha_on_rotate() { + if ( ! ( imagetypes() & IMG_PNG ) ) { + $this->markTestSkipped( 'This test requires PHP to be compiled with PNG support.' ); + } + $file = DIR_TESTDATA . '/images/transparent.png'; $image = imagecreatefrompng( $file ); diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 73a414637f..f0705d85bd 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -137,6 +137,10 @@ class Tests_Image_Functions extends WP_UnitTestCase { // Save a file as each mime type, assert it works foreach ( $mime_types as $mime_type ) { + if ( ! $class::supports_mime_type( $mime_type ) ) { + continue; + } + $file = wp_tempnam(); $ret = wp_save_image_file( $file, $img, $mime_type, 1 ); $this->assertNotEmpty( $ret ); @@ -228,6 +232,10 @@ class Tests_Image_Functions extends WP_UnitTestCase { $temp = get_temp_dir(); foreach ( $mime_types as $ext => $mime_type ) { + if ( ! $class::supports_mime_type( $mime_type ) ) { + continue; + } + $file = wp_unique_filename( $temp, uniqid() . ".$ext" ); $ret = $img->save( trailingslashit( $temp ) . $file ); $this->assertNotEmpty( $ret );