WordPress.org

Make WordPress Core

Ticket #37630: 37630.3.diff

File 37630.3.diff, 1.6 KB (added by boonebgorges, 4 years ago)
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php

    diff --git tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
    index 592591e..0b2b0dc 100644
     
    22
    33class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post {
    44
    5         function create_object( $file, $parent = 0, $args = array() ) {
    6                 return wp_insert_attachment( $args, $file, $parent );
     5        /**
     6         * Create an attachment fixture.
     7         *
     8         * @param array $args {
     9         *     Array of arguments. Accepts all arguments that can be passed to
     10         *     wp_insert_attachment(), in addition to the following:
     11         *     @type int    $post_parent ID of the post to which the attachment belongs.
     12         *     @type string $file        Path of the attached file.
     13         * }
     14         * @param int   $legacy_parent Deprecated.
     15         * @param array $legacy_args   Deprecated
     16         */
     17        function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) {
     18                // Backward compatibility for legacy argument format.
     19                if ( is_string( $args ) ) {
     20                        $file = $args;
     21                        $args = $legacy_args;
     22                        $args['post_parent'] = $legacy_parent;
     23                        $args['file'] = $file;
     24                }
     25
     26                if ( ! isset( $args['file'] ) || ! isset( $args['post_parent'] ) ) {
     27                        return new WP_Error( 'attachment_factory_missing_argument', "'file' and 'post_parent' are required arguments" );
     28                }
     29
     30                return wp_insert_attachment( $args, $args['file'], $args['post_parent'] );
    731        }
    832
    933        function create_upload_object( $file, $parent = 0 ) {