Changeset 53529
- Timestamp:
- 06/19/2022 04:39:15 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/image/functions.php
r53528 r53529 241 241 242 242 /** 243 * Test save image file and mime_types 243 * Test wp_save_image_file() and mime types. 244 * 245 * @dataProvider data_wp_save_image_file 244 246 * 245 247 * @ticket 6821 248 * @covers ::wp_save_image_file 246 249 * @requires extension fileinfo 247 */ 248 public function test_wp_save_image_file() { 250 * 251 * @param string $class_name Name of the image editor engine class to be tested. 252 * @param string $mime_type The mime type to test. 253 */ 254 public function test_wp_save_image_file( $class_name, $mime_type ) { 255 require_once ABSPATH . 'wp-admin/includes/image-edit.php'; 256 257 $img = new $class_name( DIR_TESTDATA . '/images/canola.jpg' ); 258 $loaded = $img->load(); 259 260 if ( ! $img->supports_mime_type( $mime_type ) ) { 261 $this->markTestSkipped( 262 sprintf( 263 'The %s mime type is not supported by the %s engine', 264 $mime_type, 265 str_replace( 'WP_Image_Editor_', '', $class_name ) 266 ) 267 ); 268 } 269 270 $file = wp_tempnam(); 271 $ret = wp_save_image_file( $file, $img, $mime_type, 1 ); 272 273 $this->assertNotEmpty( $ret, 'Image failed to save - "empty" response returned' ); 274 $this->assertNotWPError( $ret, 'Image failed to save - WP_Error returned' ); 275 $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ), 'Mime type of the saved image does not match' ); 276 277 // Clean up. 278 unlink( $file ); 279 unlink( $ret['path'] ); 280 unset( $img ); 281 } 282 283 /** 284 * Data provider. 285 * 286 * @return array 287 */ 288 public function data_wp_save_image_file() { 249 289 $classes = $this->get_image_editor_engine_classes(); 250 251 require_once ABSPATH . 'wp-admin/includes/image-edit.php';252 290 253 291 // Mime types. … … 260 298 // Include WebP in tests when platform supports it. 261 299 if ( function_exists( 'imagewebp' ) ) { 262 array_push( $mime_types, 'image/webp' ); 263 } 264 265 // Test each image editor engine. 300 $mime_types[] = 'image/webp'; 301 } 302 303 $data = array(); 304 266 305 foreach ( $classes as $class ) { 267 $img = new $class( DIR_TESTDATA . '/images/canola.jpg' );268 $loaded = $img->load();269 270 // Save a file as each mime type, assert it works.271 306 foreach ( $mime_types as $mime_type ) { 272 if ( ! $img->supports_mime_type( $mime_type ) ) { 273 continue; 274 } 275 276 $file = wp_tempnam(); 277 $ret = wp_save_image_file( $file, $img, $mime_type, 1 ); 278 $this->assertNotEmpty( $ret ); 279 $this->assertNotWPError( $ret ); 280 $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ) ); 281 282 // Clean up. 283 unlink( $file ); 284 unlink( $ret['path'] ); 307 $data[ $class . '; ' . $mime_type ] = array( 308 'class_name' => $class, 309 'mime_type' => $mime_type, 310 ); 285 311 } 286 287 // Clean up. 288 unset( $img ); 289 } 312 } 313 314 return $data; 290 315 } 291 316
Note: See TracChangeset
for help on using the changeset viewer.