wordpress-develop/tests/phpunit/tests/image/base.php
Andrew Nacin 8045afd81b Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root.

see #25088.


git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
2013-08-29 18:39:34 +00:00

51 lines
1.2 KiB
PHP

<?php
/**
* @group image
*/
abstract class WP_Image_UnitTestCase extends WP_UnitTestCase {
/**
* Set the image editor engine according to the unit test's specification
*/
public function setUp() {
if ( ! call_user_func( array( $this->editor_engine, 'test' ) ) ) {
$this->markTestSkipped( sprintf('The image editor engine %s is not supported on this system', $this->editor_engine) );
}
add_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
}
/**
* Undo the image editor override
*/
public function tearDown() {
remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 );
}
/**
* Override the image editor engine
* @return string
*/
public function setEngine( $editors ) {
return array( $this->editor_engine );
}
/**
* Helper assertion for testing alpha on images
*
* @param string $image_path
* @param array $point array(x,y)
* @param int $alpha
*/
protected function assertImageAlphaAtPoint( $image_path, $point, $alpha ) {
$im = imagecreatefrompng( $image_path );
$rgb = imagecolorat($im, $point[0], $point[1]);
$colors = imagecolorsforindex($im, $rgb);
$this->assertEquals( $alpha, $colors['alpha'] );
}
}