Changeset 35309 for trunk/tests/phpunit/tests/post/attachments.php
- Timestamp:
- 10/21/2015 01:58:52 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/attachments.php
r35243 r35309 7 7 */ 8 8 class Tests_Post_Attachments extends WP_UnitTestCase { 9 protected $ids = array();10 9 11 10 function tearDown() { … … 15 14 } 16 15 17 function _make_attachment( $upload, $parent_post_id = 0 ) {18 19 $type = '';20 if ( !empty($upload['type']) ) {21 $type = $upload['type'];22 } else {23 $mime = wp_check_filetype( $upload['file'] );24 if ($mime)25 $type = $mime['type'];26 }27 28 $attachment = array(29 'post_title' => basename( $upload['file'] ),30 'post_content' => '',31 'post_type' => 'attachment',32 'post_parent' => $parent_post_id,33 'post_mime_type' => $type,34 'guid' => $upload[ 'url' ],35 );36 37 // Save the data38 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent_post_id );39 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );40 41 return $this->ids[] = $id;42 43 }44 45 16 function test_insert_bogus_image() { 46 $filename = rand_str() .'.jpg';17 $filename = rand_str() . '.jpg'; 47 18 $contents = rand_str(); 48 19 49 $upload = wp_upload_bits( $filename, null, $contents);20 $upload = wp_upload_bits( $filename, null, $contents ); 50 21 $this->assertTrue( empty($upload['error']) ); 51 52 $id = $this->_make_attachment($upload);53 22 } 54 23
Note: See TracChangeset
for help on using the changeset viewer.