From b93e0739a92fd0c1f7a3f5442c61e7d59cc24feb Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 23 Aug 2016 13:42:36 +0000 Subject: [PATCH] Tests: Attachment `create()` method should match signature of other `create()` methods. Legacy argument format continues to be accepted. Props bcole808. See #37630. git-svn-id: https://develop.svn.wordpress.org/trunk@38330 602fd350-edb4-49c9-b593-d223f7449a82 --- ...ass-wp-unittest-factory-for-attachment.php | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php index 592591ed54..3ed8493860 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php @@ -2,8 +2,33 @@ class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { - function create_object( $file, $parent = 0, $args = array() ) { - return wp_insert_attachment( $args, $file, $parent ); + /** + * Create an attachment fixture. + * + * @param array $args { + * Array of arguments. Accepts all arguments that can be passed to + * wp_insert_attachment(), in addition to the following: + * @type int $post_parent ID of the post to which the attachment belongs. + * @type string $file Path of the attached file. + * } + * @param int $legacy_parent Deprecated. + * @param array $legacy_args Deprecated + */ + function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) { + // Backward compatibility for legacy argument format. + if ( is_string( $args ) ) { + $file = $args; + $args = $legacy_args; + $args['post_parent'] = $legacy_parent; + $args['file'] = $file; + } + + $r = array_merge( array( + 'file' => '', + 'parent' => 0, + ), $args ); + + return wp_insert_attachment( $r, $r['file'], $r['post_parent'] ); } function create_upload_object( $file, $parent = 0 ) {