Changeset 1148 in tests for trunk/tests/image/functions.php
- Timestamp:
- 11/21/2012 03:01:28 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/tests/image/functions.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/image/functions.php
r1126 r1148 14 14 */ 15 15 protected function get_mime_type( $filename ) { 16 $mime_type = ''; 17 if ( extension_loaded( 'fileinfo' ) ) { 16 $mime_type = ''; 17 if ( extension_loaded( 'fileinfo' ) ) { 18 18 $finfo = new finfo(); 19 19 $mime_type = $finfo->file( $filename, FILEINFO_MIME ); 20 } elseif ( function_exists('mime_content_type') ) { 20 } elseif ( function_exists('mime_content_type') ) { 21 21 $mime_type = mime_content_type( $filename ); 22 22 } … … 26 26 return $mime_type; 27 27 } 28 28 29 29 function test_is_image_positive() { 30 30 // these are all image files recognized by php … … 93 93 $this->assertFalse( file_is_displayable_image( DIR_TESTDATA.'/images/'.$file ), "file_is_valid_image($file) should return false" ); 94 94 } 95 } 96 95 } 96 97 97 /** 98 98 * Test save image file and mime_types … … 108 108 'image/png' 109 109 ); 110 110 111 111 // Test each image editor engine 112 112 $classes = array('WP_Image_Editor_GD', 'WP_Image_Editor_Imagick'); 113 113 foreach ( $classes as $class ) { 114 114 115 115 // If the image editor isn't available, skip it 116 116 if ( ! call_user_func( array( $class, 'test' ) ) ) { … … 122 122 // Call wp_save_image_file 123 123 $img = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); 124 124 125 125 // Save a file as each mime type, assert it works 126 126 foreach ( $mime_types as $mime_type ) { 127 $file = wp_tempnam(); 127 $file = wp_tempnam(); 128 128 $ret = wp_save_image_file( $file, $img, $mime_type, 1 ); 129 129 $this->assertNotEmpty( $ret ); 130 130 $this->assertNotInstanceOf( 'WP_Error', $ret ); 131 131 $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); 132 132 133 133 // Clean up 134 134 @unlink( $file ); … … 140 140 } 141 141 } 142 142 143 143 /** 144 144 * Test that a passed mime type overrides the extension in the filename … … 163 163 $file = wp_tempnam( 'tmp.jpg' ); 164 164 $ret = $img->save( $file, $mime_type ); 165 165 166 166 // Make assertions 167 167 $this->assertNotEmpty( $ret ); 168 168 $this->assertNotInstanceOf( 'WP_Error', $ret ); 169 169 $this->assertEquals( $mime_type, $this->get_mime_type( $ret['path'] ) ); 170 170 171 171 // Clean up 172 172 @unlink( $file ); … … 202 202 $filter = create_function( '', "return '$class';" ); 203 203 add_filter( 'image_editor_class', $filter ); 204 204 205 205 // Save the image as each file extension, check the mime type 206 206 $img = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );
Note: See TracChangeset
for help on using the changeset viewer.