Changeset 35309
- Timestamp:
- 10/21/2015 01:58:52 AM (8 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase.php
r35258 r35309 421 421 $GLOBALS['wp_the_query'] = new WP_Query(); 422 422 $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; 423 423 424 424 $public_query_vars = $GLOBALS['wp']->public_query_vars; 425 425 $private_query_vars = $GLOBALS['wp']->private_query_vars; … … 724 724 $wp_rewrite->flush_rules(); 725 725 } 726 727 function _make_attachment($upload, $parent_post_id = 0) { 728 $type = ''; 729 if ( !empty($upload['type']) ) { 730 $type = $upload['type']; 731 } else { 732 $mime = wp_check_filetype( $upload['file'] ); 733 if ($mime) 734 $type = $mime['type']; 735 } 736 737 $attachment = array( 738 'post_title' => basename( $upload['file'] ), 739 'post_content' => '', 740 'post_type' => 'attachment', 741 'post_parent' => $parent_post_id, 742 'post_mime_type' => $type, 743 'guid' => $upload[ 'url' ], 744 ); 745 746 // Save the data 747 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent_post_id ); 748 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 749 return $id; 750 } 726 751 } -
trunk/tests/phpunit/tests/ajax/MediaEdit.php
r29120 r35309 16 16 17 17 /** 18 * List of media thumbnail ids19 * @var array20 */21 protected $_ids = array();22 23 /**24 * Set up the test fixture.25 */26 public function setUp() {27 parent::setUp();28 }29 30 /**31 18 * Tear down the test fixture. 32 19 */ 33 20 public function tearDown() { 34 21 // Cleanup 35 foreach ( $this->_ids as $id ) { 36 wp_delete_attachment( $id, true ); 37 } 38 22 $this->remove_added_uploads(); 39 23 parent::tearDown(); 40 }41 42 /**43 * Function snagged from ./tests/post/attachments.php44 */45 function _make_attachment($upload, $parent_post_id = 0) {46 $type = '';47 if ( !empty($upload['type']) ) {48 $type = $upload['type'];49 } else {50 $mime = wp_check_filetype( $upload['file'] );51 if ($mime)52 $type = $mime['type'];53 }54 55 $attachment = array(56 'post_title' => basename( $upload['file'] ),57 'post_content' => '',58 'post_type' => 'attachment',59 'post_parent' => $parent_post_id,60 'post_mime_type' => $type,61 'guid' => $upload[ 'url' ],62 );63 64 // Save the data65 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent_post_id );66 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );67 return $this->_ids[] = $id;68 24 } 69 25 -
trunk/tests/phpunit/tests/general/template.php
r34983 r35309 155 155 156 156 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 157 $type = ''; 158 if ( ! empty( $upload['type'] ) ) { 159 $type = $upload['type']; 160 } else { 161 $mime = wp_check_filetype( $upload['file'] ); 162 if ( $mime ) { 163 $type = $mime['type']; 164 } 165 } 157 $this->site_icon_url = $upload['url']; 166 158 167 $attachment = array(168 'post_title' => basename( $upload['file'] ),169 'post_content' => $upload['url'],170 'post_type' => 'attachment',171 'post_mime_type' => $type,172 'guid' => $upload['url'],173 );174 159 175 160 // Save the data 176 $this->site_icon_url = $upload['url']; 177 $this->site_icon_id = wp_insert_attachment( $attachment, $upload['file'] ); 178 wp_update_attachment_metadata( $this->site_icon_id, wp_generate_attachment_metadata( $this->site_icon_id, $upload['file'] ) ); 161 $this->site_icon_id = $this->_make_attachment( $upload ); 162 return $this->site_icon_id; 179 163 } 180 164 } -
trunk/tests/phpunit/tests/image/header.php
r34214 r35309 105 105 106 106 function test_create_attachment_object() { 107 global $custom_image_header;108 109 107 $id = wp_insert_attachment( array( 110 108 'post_status' => 'publish', … … 124 122 125 123 function test_insert_cropped_attachment() { 126 global $custom_image_header;127 128 124 $id = wp_insert_attachment( array( 129 125 'post_status' => 'publish', -
trunk/tests/phpunit/tests/image/intermediate_size.php
r35243 r35309 6 6 */ 7 7 class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 8 protected $ids = array();9 10 8 function tearDown() { 11 9 $this->remove_added_uploads(); … … 13 11 } 14 12 15 /** 16 * Upload files and create attachements for testing 17 */ 18 private function _make_attachment( $file, $parent_post_id = 0 ) { 13 public function _make_attachment( $file, $parent_post_id = 0 ) { 19 14 $contents = file_get_contents( $file ); 20 15 $upload = wp_upload_bits( basename( $file ), null, $contents ); 21 16 22 $type = ''; 23 if ( ! empty( $upload['type'] ) ) { 24 $type = $upload['type']; 25 } else { 26 $mime = wp_check_filetype( $upload['file'] ); 27 if ( $mime ) { 28 $type = $mime['type']; 29 } 30 } 31 32 $attachment = array( 33 'post_title' => basename( $upload['file'] ), 34 'post_content' => '', 35 'post_type' => 'attachment', 36 'post_parent' => $parent_post_id, 37 'post_mime_type' => $type, 38 'guid' => $upload['url'], 39 ); 40 41 // Save the data 42 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent_post_id ); 43 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 44 45 $this->ids[] = $id; 46 return $id; 17 return parent::_make_attachment( $upload, $parent_post_id ); 47 18 } 48 19 -
trunk/tests/phpunit/tests/image/site_icon.php
r35299 r35309 159 159 160 160 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 161 $type = '';162 if ( ! empty( $upload['type'] ) ) {163 $type = $upload['type'];164 } else {165 $mime = wp_check_filetype( $upload['file'] );166 if ( $mime ) {167 $type = $mime['type'];168 }169 }170 161 171 $attachment = array( 172 'post_title' => basename( $upload['file'] ), 173 'post_content' => $upload['url'], 174 'post_type' => 'attachment', 175 'post_mime_type' => $type, 176 'guid' => $upload['url'], 177 ); 178 179 // Save the data 180 $this->attachment_id = wp_insert_attachment( $attachment, $upload['file'] ); 181 wp_update_attachment_metadata( $this->attachment_id, wp_generate_attachment_metadata( $this->attachment_id, $upload['file'] ) ); 182 162 $this->attachment_id = $this->_make_attachment( $upload ); 183 163 return $this->attachment_id; 184 164 } -
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 -
trunk/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
r25002 r35309 23 23 $contents = file_get_contents( $filename ); 24 24 $upload = wp_upload_bits(basename($filename), null, $contents); 25 $mime = wp_check_filetype( $filename );26 $this->attachment_data = array(27 'post_title' => basename( $upload['file'] ),28 'post_content' => '',29 'post_type' => 'attachment',30 'post_parent' => $this->post_id,31 'post_mime_type' => $mime['type'],32 'guid' => $upload[ 'url' ]33 );34 25 35 $id = wp_insert_attachment( $this->attachment_data, $upload[ 'file' ], $this->post_id ); 36 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 37 $this->attachment_id = $id; 26 $this->attachment_id = $this->_make_attachment( $upload, $this->post_id ); 27 $this->attachment_data = get_post( $this->attachment_id, ARRAY_A ); 38 28 39 29 set_post_thumbnail( $this->post_id, $this->attachment_id ); … … 42 32 function tearDown() { 43 33 remove_theme_support( 'post-thumbnails' ); 34 35 $this->remove_added_uploads(); 44 36 45 37 parent::tearDown();
Note: See TracChangeset
for help on using the changeset viewer.