Changeset 10222
- Timestamp:
- 10/08/2015 10:27:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase.php
r10125 r10222 552 552 $this->deactivated_components[] = $component; 553 553 } 554 555 /** 556 * Fake an attachment upload (doesn't actually upload a file). 557 * 558 * @param string $file Absolute path to valid file. 559 * @param int $parent Optional. Post ID to attach the new post to. 560 * @return int Attachment post ID. 561 */ 562 public function fake_attachment_upload( $file, $parent = 0 ) { 563 $mime = wp_check_filetype( $file ); 564 if ( $mime ) { 565 $type = $mime['type']; 566 } else { 567 $type = ''; 568 } 569 570 $url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . basename( $file ); 571 $attachment = array( 572 'guid' => 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $url, 573 'post_content' => '', 574 'post_mime_type' => $type, 575 'post_parent' => $parent, 576 'post_title' => basename( $file ), 577 'post_type' => 'attachment', 578 ); 579 580 $id = wp_insert_attachment( $attachment, $url, $parent ); 581 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $url ) ); 582 583 return $id; 584 } 554 585 }
Note: See TracChangeset
for help on using the changeset viewer.