Make WordPress Core

Changeset 38330


Ignore:
Timestamp:
08/23/2016 01:42:36 PM (8 years ago)
Author:
boonebgorges
Message:

Tests: Attachment create() method should match signature of other create() methods.

Legacy argument format continues to be accepted.

Props bcole808.
See #37630.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php

    r36347 r38330  
    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        $r = array_merge( array(
     27            'file' => '',
     28            'parent' => 0,
     29        ), $args );
     30
     31        return wp_insert_attachment( $r, $r['file'], $r['post_parent'] );
    732    }
    833
Note: See TracChangeset for help on using the changeset viewer.