diff --git a/tests/phpunit/tests/image/base.php b/tests/phpunit/tests/image/base.php index 7ea54883c6..d417cf17ea 100644 --- a/tests/phpunit/tests/image/base.php +++ b/tests/phpunit/tests/image/base.php @@ -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 * diff --git a/tests/phpunit/tests/image/editor_gd.php b/tests/phpunit/tests/image/editor_gd.php index c1abe2c4f4..14dcd985ff 100644 --- a/tests/phpunit/tests/image/editor_gd.php +++ b/tests/phpunit/tests/image/editor_gd.php @@ -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 ); } diff --git a/tests/phpunit/tests/image/editor_imagick.php b/tests/phpunit/tests/image/editor_imagick.php index 6e0342ea7f..b77ae065f3 100644 --- a/tests/phpunit/tests/image/editor_imagick.php +++ b/tests/phpunit/tests/image/editor_imagick.php @@ -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 ); }