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
This commit is contained in:
Boone Gorges
2015-02-22 21:06:36 +00:00
parent a468005276
commit d854564f73
2 changed files with 34 additions and 7 deletions

View File

@@ -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 );

View File

@@ -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 );