Changeset 1255 in tests for trunk/tests/image/resize.php
- Timestamp:
- 04/03/2013 07:24:44 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/image/resize.php
r1148 r1255 7 7 */ 8 8 abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase { 9 // image_resize( $file, $max_w, $max_h, $crop=false, $suffix=null, $dest_path=null, $jpeg_quality=75)10 9 11 10 function test_resize_jpg() { 12 $image = image_resize( DIR_TESTDATA.'/images/test-image.jpg', 25, 25 ); 11 $image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.jpg', 25, 25 ); 12 13 13 $this->assertEquals( 'test-image-25x25.jpg', basename($image) ); 14 14 list($w, $h, $type) = getimagesize($image); … … 16 16 $this->assertEquals( 25, $h ); 17 17 $this->assertEquals( IMAGETYPE_JPEG, $type ); 18 unlink($image); 18 19 unlink( $image ); 19 20 } 20 21 21 22 function test_resize_png() { 22 $image = image_resize( DIR_TESTDATA.'/images/test-image.png', 25, 25 ); 23 $image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.png', 25, 25 ); 24 23 25 $this->assertEquals( 'test-image-25x25.png', basename($image) ); 24 26 list($w, $h, $type) = getimagesize($image); … … 26 28 $this->assertEquals( 25, $h ); 27 29 $this->assertEquals( IMAGETYPE_PNG, $type ); 28 unlink($image); 30 31 unlink( $image ); 29 32 } 30 33 31 34 function test_resize_gif() { 32 $image = image_resize( DIR_TESTDATA.'/images/test-image.gif', 25, 25 ); 35 $image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.gif', 25, 25 ); 36 33 37 $this->assertEquals( 'test-image-25x25.gif', basename($image) ); 34 38 list($w, $h, $type) = getimagesize($image); … … 36 40 $this->assertEquals( 25, $h ); 37 41 $this->assertEquals( IMAGETYPE_GIF, $type ); 38 unlink($image); 42 43 unlink( $image ); 39 44 } 40 45 41 46 function test_resize_larger() { 42 47 // image_resize() should refuse to make an image larger 43 $image = image_resize( DIR_TESTDATA.'/images/test-image.jpg', 100, 100 ); 48 $image = $this->resize_helper( DIR_TESTDATA.'/images/test-image.jpg', 100, 100 ); 49 44 50 $this->assertInstanceOf( 'WP_Error', $image ); 45 51 $this->assertEquals( 'error_getting_dimensions', $image->get_error_code() ); … … 47 53 48 54 function test_resize_thumb_128x96() { 49 $image = image_resize( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 128, 96 ); 55 $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 128, 96 ); 56 50 57 $this->assertEquals( '2007-06-17DSC_4173-63x96.jpg', basename($image) ); 51 58 list($w, $h, $type) = getimagesize($image); … … 53 60 $this->assertEquals( 96, $h ); 54 61 $this->assertEquals( IMAGETYPE_JPEG, $type ); 55 // is this a valid test? do different systems always generate the same file? 56 #$this->assertEquals( 'be8f7aaa7b939970a3ded069a6e3619b', md5_file($image) ); 57 unlink($image); 62 63 unlink( $image ); 58 64 } 59 65 60 66 function test_resize_thumb_128x0() { 61 $image = image_resize( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 128, 0 ); 67 $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 128, 0 ); 68 62 69 $this->assertEquals( '2007-06-17DSC_4173-128x192.jpg', basename($image) ); 63 70 list($w, $h, $type) = getimagesize($image); … … 65 72 $this->assertEquals( 192, $h ); 66 73 $this->assertEquals( IMAGETYPE_JPEG, $type ); 67 // is this a valid test? do different systems always generate the same file? 68 #$this->assertEquals( '7b1c0d5e7d4f6a18ae7541c8abf1fd09', md5_file($image) ); 69 unlink($image); 74 75 unlink( $image ); 70 76 } 71 77 72 78 function test_resize_thumb_0x96() { 73 $image = image_resize( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 0, 96 ); 79 $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 0, 96 ); 80 74 81 $this->assertEquals( '2007-06-17DSC_4173-63x96.jpg', basename($image) ); 75 82 list($w, $h, $type) = getimagesize($image); … … 77 84 $this->assertEquals( 96, $h ); 78 85 $this->assertEquals( IMAGETYPE_JPEG, $type ); 79 // is this a valid test? do different systems always generate the same file? 80 #$this->assertEquals( 'be8f7aaa7b939970a3ded069a6e3619b', md5_file($image) ); 81 unlink($image); 86 87 unlink( $image ); 82 88 } 83 89 84 90 function test_resize_thumb_150x150_crop() { 85 $image = image_resize( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 150, 150, true ); 91 $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 150, 150, true ); 92 86 93 $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', basename($image) ); 87 94 list($w, $h, $type) = getimagesize($image); … … 89 96 $this->assertEquals( 150, $h ); 90 97 $this->assertEquals( IMAGETYPE_JPEG, $type ); 91 // is this a valid test? do different systems always generate the same file? 92 #$this->assertEquals( '9fdcf728e1d43da89edf866d009ca7e8', md5_file($image) ); 93 unlink($image); 98 99 unlink( $image ); 94 100 } 95 101 96 102 function test_resize_thumb_150x100_crop() { 97 $image = image_resize( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 150, 100, true ); 103 $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 150, 100, true ); 104 98 105 $this->assertEquals( '2007-06-17DSC_4173-150x100.jpg', basename($image) ); 99 106 list($w, $h, $type) = getimagesize($image); … … 101 108 $this->assertEquals( 100, $h ); 102 109 $this->assertEquals( IMAGETYPE_JPEG, $type ); 103 // is this a valid test? do different systems always generate the same file? 104 #$this->assertEquals( '2eeb18856505ab946074d90babc46452', md5_file($image) ); 110 105 111 unlink($image); 106 112 } 107 113 108 114 function test_resize_thumb_50x150_crop() { 109 $image = image_resize( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 50, 150, true ); 115 $image = $this->resize_helper( DIR_TESTDATA.'/images/2007-06-17DSC_4173.JPG', 50, 150, true ); 116 110 117 $this->assertEquals( '2007-06-17DSC_4173-50x150.jpg', basename($image) ); 111 118 list($w, $h, $type) = getimagesize($image); … … 113 120 $this->assertEquals( 150, $h ); 114 121 $this->assertEquals( IMAGETYPE_JPEG, $type ); 115 // is this a valid test? do different systems always generate the same file? 116 #$this->assertEquals( '94ed8e8463475774a5c5ff66118d3127', md5_file($image) ); 117 unlink($image); 122 123 unlink( $image ); 118 124 } 119 125 … … 123 129 */ 124 130 public function test_resize_non_existent_image() { 125 $image = image_resize( DIR_TESTDATA.'/images/test-non-existent-image.jpg', 25, 25 ); 131 $image = $this->resize_helper( DIR_TESTDATA.'/images/test-non-existent-image.jpg', 25, 25 ); 132 126 133 $this->assertInstanceOf( 'WP_Error', $image ); 127 134 $this->assertEquals( 'error_loading_image', $image->get_error_code() ); … … 133 140 */ 134 141 public function test_resize_bad_image() { 135 $image = image_resize( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 );142 $image = $this->resize_helper( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 ); 136 143 $this->assertInstanceOf( 'WP_Error', $image ); 137 144 $this->assertEquals( 'invalid_image', $image->get_error_code() ); 138 145 } 146 147 148 /** 149 * Function to help out the tests 150 */ 151 protected function resize_helper( $file, $width, $height, $crop = false ) { 152 $editor = wp_get_image_editor( $file ); 153 154 if ( is_wp_error( $editor ) ) 155 return $editor; 156 157 $resized = $editor->resize( $width, $height, $crop ); 158 if ( is_wp_error( $resized ) ) 159 return $resized; 160 161 $dest_file = $editor->generate_filename(); 162 $saved = $editor->save( $dest_file ); 163 164 if ( is_wp_error( $saved ) ) 165 return $saved; 166 167 return $dest_file; 168 } 139 169 }
Note: See TracChangeset
for help on using the changeset viewer.