WordPress.org

Make WordPress Core

Ticket #37630: 37630.diff

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

     
    22
    33class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post {
    44
     5        function create( $file, $parent = 0, $args = array(), $generation_definitions = null ) {
     6                if ( is_null( $generation_definitions ) )
     7                        $generation_definitions = $this->default_generation_definitions;
     8
     9                $generated_args = $this->generate_args( $args, $generation_definitions, $callbacks );
     10                $created = $this->create_object( $file, $parent, $generated_args );
     11                if ( !$created || is_wp_error( $created ) )
     12                        return $created;
     13
     14                if ( $callbacks ) {
     15                        $updated_fields = $this->apply_callbacks( $callbacks, $created );
     16                        $save_result = $this->update_object( $created, $updated_fields );
     17                        if ( !$save_result || is_wp_error( $save_result ) )
     18                                return $save_result;
     19                }
     20                return $created;
     21        }
     22
    523        function create_object( $file, $parent = 0, $args = array() ) {
    624                return wp_insert_attachment( $args, $file, $parent );
    725        }