Changeset 42343 for trunk/tests/phpunit/tests/image/resize.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/image/resize.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/image/resize.php
r42228 r42343 28 28 29 29 function test_resize_jpg() { 30 $image = $this->resize_helper( DIR_TESTDATA .'/images/test-image.jpg', 25, 25 );30 $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 25, 25 ); 31 31 32 32 $this->assertEquals( 'test-image-25x25.jpg', basename( $image ) ); 33 list($w, $h, $type) = getimagesize( $image);33 list($w, $h, $type) = getimagesize( $image ); 34 34 $this->assertEquals( 25, $w ); 35 35 $this->assertEquals( 25, $h ); … … 40 40 41 41 function test_resize_png() { 42 $image = $this->resize_helper( DIR_TESTDATA .'/images/test-image.png', 25, 25 );42 $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.png', 25, 25 ); 43 43 44 44 if ( ! is_string( $image ) ) { // WP_Error, stop GLib-GObject-CRITICAL assertion … … 47 47 48 48 $this->assertEquals( 'test-image-25x25.png', basename( $image ) ); 49 list($w, $h, $type) = getimagesize( $image);49 list($w, $h, $type) = getimagesize( $image ); 50 50 $this->assertEquals( 25, $w ); 51 51 $this->assertEquals( 25, $h ); … … 56 56 57 57 function test_resize_gif() { 58 $image = $this->resize_helper( DIR_TESTDATA .'/images/test-image.gif', 25, 25 );58 $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.gif', 25, 25 ); 59 59 60 60 if ( ! is_string( $image ) ) { // WP_Error, stop GLib-GObject-CRITICAL assertion … … 63 63 64 64 $this->assertEquals( 'test-image-25x25.gif', basename( $image ) ); 65 list($w, $h, $type) = getimagesize( $image);65 list($w, $h, $type) = getimagesize( $image ); 66 66 $this->assertEquals( 25, $w ); 67 67 $this->assertEquals( 25, $h ); … … 73 73 function test_resize_larger() { 74 74 // image_resize() should refuse to make an image larger 75 $image = $this->resize_helper( DIR_TESTDATA .'/images/test-image.jpg', 100, 100 );75 $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 100, 100 ); 76 76 77 77 $this->assertInstanceOf( 'WP_Error', $image ); … … 80 80 81 81 function test_resize_thumb_128x96() { 82 $image = $this->resize_helper( DIR_TESTDATA .'/images/2007-06-17DSC_4173.JPG', 128, 96 );82 $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 96 ); 83 83 84 84 $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', basename( $image ) ); 85 list($w, $h, $type) = getimagesize( $image);85 list($w, $h, $type) = getimagesize( $image ); 86 86 $this->assertEquals( 64, $w ); 87 87 $this->assertEquals( 96, $h ); … … 92 92 93 93 function test_resize_thumb_128x0() { 94 $image = $this->resize_helper( DIR_TESTDATA .'/images/2007-06-17DSC_4173.JPG', 128, 0 );94 $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 0 ); 95 95 96 96 $this->assertEquals( '2007-06-17DSC_4173-128x193.jpg', basename( $image ) ); 97 list($w, $h, $type) = getimagesize( $image);97 list($w, $h, $type) = getimagesize( $image ); 98 98 $this->assertEquals( 128, $w ); 99 99 $this->assertEquals( 193, $h ); … … 104 104 105 105 function test_resize_thumb_0x96() { 106 $image = $this->resize_helper( DIR_TESTDATA .'/images/2007-06-17DSC_4173.JPG', 0, 96 );106 $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 0, 96 ); 107 107 108 108 $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', basename( $image ) ); 109 list($w, $h, $type) = getimagesize( $image);109 list($w, $h, $type) = getimagesize( $image ); 110 110 $this->assertEquals( 64, $w ); 111 111 $this->assertEquals( 96, $h ); … … 116 116 117 117 function test_resize_thumb_150x150_crop() { 118 $image = $this->resize_helper( DIR_TESTDATA .'/images/2007-06-17DSC_4173.JPG', 150, 150, true );118 $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 150, true ); 119 119 120 120 $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', basename( $image ) ); 121 list($w, $h, $type) = getimagesize( $image);121 list($w, $h, $type) = getimagesize( $image ); 122 122 $this->assertEquals( 150, $w ); 123 123 $this->assertEquals( 150, $h ); … … 128 128 129 129 function test_resize_thumb_150x100_crop() { 130 $image = $this->resize_helper( DIR_TESTDATA .'/images/2007-06-17DSC_4173.JPG', 150, 100, true );130 $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 100, true ); 131 131 132 132 $this->assertEquals( '2007-06-17DSC_4173-150x100.jpg', basename( $image ) ); 133 list($w, $h, $type) = getimagesize( $image);133 list($w, $h, $type) = getimagesize( $image ); 134 134 $this->assertEquals( 150, $w ); 135 135 $this->assertEquals( 100, $h ); … … 140 140 141 141 function test_resize_thumb_50x150_crop() { 142 $image = $this->resize_helper( DIR_TESTDATA .'/images/2007-06-17DSC_4173.JPG', 50, 150, true );142 $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 50, 150, true ); 143 143 144 144 $this->assertEquals( '2007-06-17DSC_4173-50x150.jpg', basename( $image ) ); 145 list($w, $h, $type) = getimagesize( $image);145 list($w, $h, $type) = getimagesize( $image ); 146 146 $this->assertEquals( 50, $w ); 147 147 $this->assertEquals( 150, $h ); … … 153 153 /** 154 154 * Try resizing a non-existent image 155 * 155 156 * @ticket 6821 156 157 */ 157 158 public function test_resize_non_existent_image() { 158 $image = $this->resize_helper( DIR_TESTDATA .'/images/test-non-existent-image.jpg', 25, 25 );159 $image = $this->resize_helper( DIR_TESTDATA . '/images/test-non-existent-image.jpg', 25, 25 ); 159 160 160 161 $this->assertInstanceOf( 'WP_Error', $image ); … … 168 169 $editor = wp_get_image_editor( $file ); 169 170 170 if ( is_wp_error( $editor ) ) 171 if ( is_wp_error( $editor ) ) { 171 172 return $editor; 173 } 172 174 173 175 $resized = $editor->resize( $width, $height, $crop ); 174 if ( is_wp_error( $resized ) ) 176 if ( is_wp_error( $resized ) ) { 175 177 return $resized; 178 } 176 179 177 180 $dest_file = $editor->generate_filename(); 178 $saved = $editor->save( $dest_file );181 $saved = $editor->save( $dest_file ); 179 182 180 if ( is_wp_error( $saved ) ) 183 if ( is_wp_error( $saved ) ) { 181 184 return $saved; 185 } 182 186 183 187 return $dest_file;
Note: See TracChangeset
for help on using the changeset viewer.