Changeset 47122 for trunk/tests/phpunit/tests/image/functions.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/image/functions.php
r46586 r47122 47 47 48 48 function test_is_image_positive() { 49 // these are all image files recognized by php49 // These are all image files recognized by PHP. 50 50 $files = array( 51 51 'test-image-cmyk.jpg', … … 73 73 74 74 function test_is_image_negative() { 75 // these are actually image files but aren't recognized or usable by php75 // These are actually image files but aren't recognized or usable by PHP. 76 76 $files = array( 77 77 'test-image.pct', … … 86 86 87 87 function test_is_displayable_image_positive() { 88 // these are all usable in typical web browsers88 // These are all usable in typical web browsers. 89 89 $files = array( 90 90 'test-image.gif', … … 104 104 105 105 function test_is_displayable_image_negative() { 106 // these are image files but aren't suitable for web pages because of compatibility or size issues106 // These are image files but aren't suitable for web pages because of compatibility or size issues. 107 107 $files = array( 108 // 'test-image-cmyk.jpg', Allowed in r9727109 // 'test-image.bmp', Allowed in r28589110 // 'test-image-grayscale.jpg', Allowed in r9727 108 // 'test-image-cmyk.jpg', Allowed in r9727. 109 // 'test-image.bmp', Allowed in r28589. 110 // 'test-image-grayscale.jpg', Allowed in r9727. 111 111 'test-image.pct', 112 112 'test-image.tga', … … 136 136 include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); 137 137 138 // Mime types 138 // Mime types. 139 139 $mime_types = array( 140 140 'image/jpeg', … … 143 143 ); 144 144 145 // Test each image editor engine 145 // Test each image editor engine. 146 146 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); 147 147 foreach ( $classes as $class ) { 148 148 149 // If the image editor isn't available, skip it 149 // If the image editor isn't available, skip it. 150 150 if ( ! call_user_func( array( $class, 'test' ) ) ) { 151 151 continue; … … 155 155 $loaded = $img->load(); 156 156 157 // Save a file as each mime type, assert it works 157 // Save a file as each mime type, assert it works. 158 158 foreach ( $mime_types as $mime_type ) { 159 159 if ( ! $img->supports_mime_type( $mime_type ) ) { … … 167 167 $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); 168 168 169 // Clean up 169 // Clean up. 170 170 unlink( $file ); 171 171 unlink( $ret['path'] ); 172 172 } 173 173 174 // Clean up 174 // Clean up. 175 175 unset( $img ); 176 176 } … … 187 187 } 188 188 189 // Test each image editor engine 189 // Test each image editor engine. 190 190 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); 191 191 foreach ( $classes as $class ) { 192 192 193 // If the image editor isn't available, skip it 193 // If the image editor isn't available, skip it. 194 194 if ( ! call_user_func( array( $class, 'test' ) ) ) { 195 195 continue; … … 199 199 $loaded = $img->load(); 200 200 201 // Save the file 201 // Save the file. 202 202 $mime_type = 'image/gif'; 203 203 $file = wp_tempnam( 'tmp.jpg' ); 204 204 $ret = $img->save( $file, $mime_type ); 205 205 206 // Make assertions 206 // Make assertions. 207 207 $this->assertNotEmpty( $ret ); 208 208 $this->assertNotWPError( $ret ); 209 209 $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); 210 210 211 // Clean up 211 // Clean up. 212 212 unlink( $file ); 213 213 unlink( $ret['path'] ); … … 226 226 } 227 227 228 // Mime types 228 // Mime types. 229 229 $mime_types = array( 230 230 'jpg' => 'image/jpeg', … … 233 233 'gif' => 'image/gif', 234 234 'png' => 'image/png', 235 'unk' => 'image/jpeg', // Default, unknown 236 ); 237 238 // Test each image editor engine 235 'unk' => 'image/jpeg', // Default, unknown. 236 ); 237 238 // Test each image editor engine. 239 239 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); 240 240 foreach ( $classes as $class ) { 241 241 242 // If the image editor isn't available, skip it 242 // If the image editor isn't available, skip it. 243 243 if ( ! call_user_func( array( $class, 'test' ) ) ) { 244 244 continue; … … 248 248 $loaded = $img->load(); 249 249 250 // Save the image as each file extension, check the mime type 250 // Save the image as each file extension, check the mime type. 251 251 $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 252 252 $this->assertNotWPError( $img ); … … 266 266 } 267 267 268 // Clean up 268 // Clean up. 269 269 unset( $img ); 270 270 } … … 279 279 public function test_load_directory() { 280 280 281 // First, test with deprecated wp_load_image function 281 // First, test with deprecated wp_load_image function. 282 282 $editor1 = wp_load_image( DIR_TESTDATA ); 283 283 $this->assertNotInternalType( 'resource', $editor1 ); … … 289 289 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); 290 290 foreach ( $classes as $class ) { 291 // If the image editor isn't available, skip it 291 // If the image editor isn't available, skip it. 292 292 if ( ! call_user_func( array( $class, 'test' ) ) ) { 293 293 continue;
Note: See TracChangeset
for help on using the changeset viewer.