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/post/attachments.php

    r35243 r35309  
    77 */
    88class Tests_Post_Attachments extends WP_UnitTestCase {
    9         protected $ids = array();
    109
    1110        function tearDown() {
    … …  
    1514        }
    1615
    17         function _make_attachment( $upload, $parent_post_id = 0 ) {
    18 
    19                 $type = '';
    20                 if ( !empty($upload['type']) ) {
    21                         $type = $upload['type'];
    22                 } else {
    23                         $mime = wp_check_filetype( $upload['file'] );
    24                         if ($mime)
    25                                 $type = $mime['type'];
    26                 }
    27 
    28                 $attachment = array(
    29                         'post_title' => basename( $upload['file'] ),
    30                         'post_content' => '',
    31                         'post_type' => 'attachment',
    32                         'post_parent' => $parent_post_id,
    33                         'post_mime_type' => $type,
    34                         'guid' => $upload[ 'url' ],
    35                 );
    36 
    37                 // Save the data
    38                 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent_post_id );
    39                 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
    40 
    41                 return $this->ids[] = $id;
    42 
    43         }
    44 
    4516        function test_insert_bogus_image() {
    46                 $filename = rand_str().'.jpg';
     17                $filename = rand_str() . '.jpg';
    4718                $contents = rand_str();
    4819
    49                 $upload = wp_upload_bits($filename, null, $contents);
     20                $upload = wp_upload_bits( $filename, null, $contents );
    5021                $this->assertTrue( empty($upload['error']) );
    51 
    52                 $id = $this->_make_attachment($upload);
    5322        }
    5423
Note: See TracChangeset for help on using the changeset viewer.