Changeset 55019 for trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
- Timestamp:
- 12/28/2022 02:07:16 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
r47122 r55019 1 1 <?php 2 2 3 /** 4 * Unit test factory for attachments. 5 * 6 * Note: The below @method notations are defined solely for the benefit of IDEs, 7 * as a way to indicate expected return values from the given factory methods. 8 * 9 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 10 * @method WP_Post|WP_Error create_and_get( $args = array(), $generation_definitions = null ) 11 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 12 */ 3 13 class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { 4 14 5 15 /** 6 16 * Create an attachment fixture. 17 * 18 * @since UT (3.7.0) 19 * @since 6.2.0 Returns a WP_Error object on failure. 7 20 * 8 21 * @param array $args { … … 15 28 * @param array $legacy_args Deprecated. 16 29 * 17 * @return int|WP_Error The attachment ID on success . The value 0 or WP_Erroron failure.30 * @return int|WP_Error The attachment ID on success, WP_Error object on failure. 18 31 */ 19 32 public function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) { … … 34 47 ); 35 48 36 return wp_insert_attachment( $r, $r['file'], $r['post_parent'] );49 return wp_insert_attachment( $r, $r['file'], $r['post_parent'], true ); 37 50 } 38 51 … … 40 53 * Saves an attachment. 41 54 * 55 * @since 4.4.0 56 * @since 6.2.0 Returns a WP_Error object on failure. 57 * 42 58 * @param string $file The file name to create attachment object for. 43 59 * @param int $parent ID of the post to attach the file to. 44 60 * 45 * @return int|WP_Error The attachment ID on success . The value 0 or WP_Erroron failure.61 * @return int|WP_Error The attachment ID on success, WP_Error object on failure. 46 62 */ 47 63 public function create_upload_object( $file, $parent = 0 ) { … … 69 85 70 86 // Save the data. 71 $id = wp_insert_attachment( $attachment, $upload['file'], $parent ); 72 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 87 $attachment_id = wp_insert_attachment( $attachment, $upload['file'], $parent, true ); 73 88 74 return $id; 89 if ( is_wp_error( $attachment_id ) ) { 90 return $attachment_id; 91 } 92 93 wp_update_attachment_metadata( 94 $attachment_id, 95 wp_generate_attachment_metadata( $attachment_id, $upload['file'] ) 96 ); 97 98 return $attachment_id; 75 99 } 76 100 }
Note: See TracChangeset
for help on using the changeset viewer.