Make WordPress Core


Ignore:
Timestamp:
10/21/2015 01:58:52 AM (11 years ago)
Author:
wonderboymusic
Message:

Unit Tests: consolidate the many separate implementations of _make_attachment() into a helper method on WP_UnitTestCase.

Fixes #34075.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/intermediate_size.php

    r35243 r35309  
    66 */
    77class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
    8         protected $ids = array();
    9 
    108        function tearDown() {
    119                $this->remove_added_uploads();
     
    1311        }
    1412
    15         /**
    16          * Upload files and create attachements for testing
    17          */
    18         private function _make_attachment( $file, $parent_post_id = 0 ) {
     13        public function _make_attachment( $file, $parent_post_id = 0 ) {
    1914                $contents = file_get_contents( $file );
    2015                $upload = wp_upload_bits( basename( $file ), null, $contents );
    2116
    22                 $type = '';
    23                 if ( ! empty( $upload['type'] ) ) {
    24                         $type = $upload['type'];
    25                 } else {
    26                         $mime = wp_check_filetype( $upload['file'] );
    27                         if ( $mime ) {
    28                                 $type = $mime['type'];
    29                         }
    30                 }
    31 
    32                 $attachment = array(
    33                         'post_title' => basename( $upload['file'] ),
    34                         'post_content' => '',
    35                         'post_type' => 'attachment',
    36                         'post_parent' => $parent_post_id,
    37                         'post_mime_type' => $type,
    38                         'guid' => $upload['url'],
    39                 );
    40 
    41                 // Save the data
    42                 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent_post_id );
    43                 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
    44 
    45                 $this->ids[] = $id;
    46                 return $id;
     17                return parent::_make_attachment( $upload, $parent_post_id );
    4718        }
    4819
Note: See TracChangeset for help on using the changeset viewer.