| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Test the WP_Image_Editor_GD class |
| 5 | * @group image |
| 6 | * @group media |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * @todo how does one run this test on it's own without including the parent class? |
| 11 | */ |
| 12 | require_once( 'base.php' ); |
| 13 | |
| 14 | class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { |
| 15 | public $editor_engine = 'WP_Image_Editor_GD'; |
| 16 | |
| 17 | public function setup() { |
| 18 | require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' ); |
| 19 | require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' ); |
| 20 | parent::setUp(); |
| 21 | } |
| 22 | |
| 23 | public function test_image_preserves_alpha_on_resize() { |
| 24 | |
| 25 | $file = DIR_TESTDATA . '/images/transparent.png'; |
| 26 | |
| 27 | $editor = wp_get_image_editor( $file ); |
| 28 | $editor->load(); |
| 29 | $editor->resize(5,5); |
| 30 | $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; |
| 31 | |
| 32 | $editor->save( $save_to_file ); |
| 33 | |
| 34 | $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Test the image created with WP_Image_Edior_GD preserves alpha with no resizing etc |
| 40 | * |
| 41 | * |
| 42 | */ |
| 43 | public function test_image_preserves_alpha() { |
| 44 | |
| 45 | $file = DIR_TESTDATA . '/images/transparent.png'; |
| 46 | |
| 47 | $editor = wp_get_image_editor( $file ); |
| 48 | $editor->load(); |
| 49 | |
| 50 | $save_to_file = tempnam( get_temp_dir(), '' ) . '.png'; |
| 51 | |
| 52 | $editor->save( $save_to_file ); |
| 53 | |
| 54 | $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 ); |
| 55 | } |
| 56 | |
| 57 | } |