Skip to content

Commit

Permalink
Automatically generate attachment file to with factory() attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
lipemat committed Nov 1, 2019
1 parent 61a832a commit 2ab74ee
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions includes/factory/class-wp-unittest-factory-for-attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post {




/**
* Create an attachment fixture.
*
Expand All @@ -14,6 +17,8 @@ class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post {
* @param int $legacy_parent Deprecated.
* @param array $legacy_args Deprecated.
*
* @since 1.8.0 (Automatically generate file to go with attachment)
*
* @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
*/
function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) {
Expand All @@ -25,10 +30,18 @@ function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) {
$args['file'] = $file;
}

// @since 1.8.0
if ( empty( $args['file']) ) {
$this->test_file = '/tmp/canola.jpg';
copy( DIR_TESTDATA . '/images/canola.jpg', $this->test_file );
$args['file'] = $this->test_file;
}

$r = array_merge(
array(
'file' => '',
'post_parent' => 0,
'post_mime_type' => 'import'
),
$args
);
Expand Down

0 comments on commit 2ab74ee

Please sign in to comment.