Fix the unit tests for Imagick alpha.

These tests were written to use the `assertImageAtAlpha()` helper method, whose
internals were specific to GD. As a result, the tests could not pass. This
changeset introduces GD- and Imagick-specific versions of this method.

Props voldemortensen.
Fixes #24871.

git-svn-id: https://develop.svn.wordpress.org/trunk@30549 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2014-11-24 20:56:36 +00:00
parent 951409119e
commit 7c8c493a9c
3 changed files with 28 additions and 6 deletions

View File

@ -36,13 +36,13 @@ abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
}
/**
* Helper assertion for testing alpha on images
* Helper assertion for testing alpha on images using GD library
*
* @param string $image_path
* @param array $point array(x,y)
* @param int $alpha
*/
protected function assertImageAlphaAtPoint( $image_path, $point, $alpha ) {
protected function assertImageAlphaAtPointGD( $image_path, $point, $alpha ) {
$im = imagecreatefrompng( $image_path );
$rgb = imagecolorat( $im, $point[0], $point[1] );
@ -51,6 +51,20 @@ abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
$this->assertEquals( $alpha, $colors['alpha'] );
}
/**
* Helper assertion for testing alpha on images using Imagick
*
* @param string $image_path
* @param array $point array(x,y)
* @param int $expected
*/
protected function assertImageAlphaAtPointImagick( $image_path, $point, $expected ) {
$im = new Imagick( $image_path );
$pixel = $im->getImagePixelColor( $point[0], $point[1] );
$color = $pixel->getColorValue( imagick::COLOR_ALPHA );
$this->assertEquals( $expected, $color );
}
/**
* Helper assertion to check actual image dimensions on disk
*

View File

@ -472,7 +472,7 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
$editor->save( $save_to_file );
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
$this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
unlink( $save_to_file );
}
@ -495,7 +495,7 @@ class Tests_Image_Editor_GD extends WP_Image_UnitTestCase {
$editor->save( $save_to_file );
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
$this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
unlink( $save_to_file );
}

View File

@ -472,7 +472,11 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
$editor->save( $save_to_file );
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
$im = new Imagick( $save_to_file );
$pixel = $im->getImagePixelColor( 0, 0 );
$expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
$this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
unlink( $save_to_file );
}
@ -495,7 +499,11 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase {
$editor->save( $save_to_file );
$this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
$im = new Imagick( $save_to_file );
$pixel = $im->getImagePixelColor( 0, 0 );
$expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
$this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
unlink( $save_to_file );
}