Changeset 53530
- Timestamp:
- 06/19/2022 04:51:49 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/image/functions.php
r53529 r53530 316 316 317 317 /** 318 * Test that a passed mime type overrides the extension in the filename 318 * Test that a passed mime type overrides the extension in the filename when saving an image. 319 * 320 * @dataProvider data_mime_overrides_filename 319 321 * 320 322 * @ticket 6821 323 * @covers WP_Image_Editor::get_mime_type 324 * @covers WP_Image_Editor::get_output_format 321 325 * @requires extension fileinfo 322 */ 323 public function test_mime_overrides_filename() { 324 $classes = $this->get_image_editor_engine_classes(); 325 326 // Test each image editor engine. 327 foreach ( $classes as $class ) { 328 $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); 329 $loaded = $img->load(); 330 331 // Save the file. 332 $mime_type = 'image/gif'; 333 $file = wp_tempnam( 'tmp.jpg' ); 334 $ret = $img->save( $file, $mime_type ); 335 336 // Make assertions. 337 $this->assertNotEmpty( $ret ); 338 $this->assertNotWPError( $ret ); 339 $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ) ); 340 341 // Clean up. 342 unlink( $file ); 343 unlink( $ret['path'] ); 344 unset( $img ); 345 } 326 * 327 * @param string $class_name Name of the image editor engine class to be tested. 328 */ 329 public function test_mime_overrides_filename_when_saving_an_image( $class_name ) { 330 $img = new $class_name( DIR_TESTDATA . '/images/canola.jpg' ); 331 $loaded = $img->load(); 332 333 // Save the file. 334 $mime_type = 'image/gif'; 335 $file = wp_tempnam( 'tmp.jpg' ); 336 $ret = $img->save( $file, $mime_type ); 337 338 // Make assertions. 339 $this->assertNotEmpty( $ret, 'Image failed to save - "empty" response returned' ); 340 $this->assertNotWPError( $ret, 'Image failed to save - WP_Error returned' ); 341 $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ), 'Mime type of the saved image did not override file name' ); 342 343 // Clean up. 344 unlink( $file ); 345 unlink( $ret['path'] ); 346 unset( $img ); 347 } 348 349 /** 350 * Data provider. 351 * 352 * @return array 353 */ 354 public function data_mime_overrides_filename() { 355 return $this->text_array_to_dataprovider( $this->get_image_editor_engine_classes() ); 346 356 } 347 357
Note: See TracChangeset
for help on using the changeset viewer.