| 1189 | * @ticket 40370 |
| 1190 | */ |
| 1191 | public function test_media_handle_upload_add_image_size() { |
| 1192 | global $_wp_additional_image_sizes; |
| 1193 | |
| 1194 | $iptc_file = DIR_TESTDATA . '/images/test-image-iptc.jpg'; |
| 1195 | |
| 1196 | // Make a copy of this file as it gets moved during the file upload |
| 1197 | $tmp_name = wp_tempnam( $iptc_file ); |
| 1198 | |
| 1199 | copy( $iptc_file, $tmp_name ); |
| 1200 | |
| 1201 | // FIXME : change to correct upload method that creates thumbnails |
| 1202 | // and resuts in the new filenames with hashes |
| 1203 | $_FILES['async-upload'] = array( |
| 1204 | 'tmp_name' => $tmp_name, |
| 1205 | 'name' => 'test-image-iptc.jpg', |
| 1206 | 'type' => 'image/jpeg', |
| 1207 | 'error' => 0, |
| 1208 | 'size' => filesize( $iptc_file ), |
| 1209 | ); |
| 1210 | |
| 1211 | // add multiple image sizes |
| 1212 | add_image_size( 'newscentered', 400, 400, array( 'center', 'center') ); |
| 1213 | add_image_size( 'newstop', 400, 400, array( 'center', 'top' ) ); |
| 1214 | add_image_size( 'newsbottom', 400, 400, array( 'center', 'bottom' ) ); |
| 1215 | |
| 1216 | $info = wp_upload_dir(); |
| 1217 | |
| 1218 | $orig = array_map('basename', glob( ABSPATH . 'wp-content/uploads' |
| 1219 | . $info['subdir'] .'/*.png')); |
| 1220 | |
| 1221 | // upload file |
| 1222 | $post_id = media_handle_upload( |
| 1223 | 'async-upload', |
| 1224 | 0, |
| 1225 | array(), |
| 1226 | array( |
| 1227 | 'action' => 'test_iptc_upload', |
| 1228 | 'test_form' => false, |
| 1229 | ) |
| 1230 | ); |
| 1231 | |
| 1232 | unset( $_FILES['upload'] ); |
| 1233 | |
| 1234 | // Clean up. |
| 1235 | wp_delete_attachment( $post_id ); |
| 1236 | |
| 1237 | // 3 new files should be created |
| 1238 | $new = array_map('basename', glob( ABSPATH . 'wp-content/uploads' |
| 1239 | . $info['subdir'] .'/*.{jpg, png}', GLOB_BRACE)); |
| 1240 | $new_files = array_diff($new, $orig); |
| 1241 | |
| 1242 | $this->assertCount(3, $new_files ); |
| 1243 | |
| 1244 | } |
| 1245 | |
| 1246 | /** |