Make WordPress Core


Ignore:
Timestamp:
10/21/2015 01:58:52 AM (9 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/ajax/MediaEdit.php

    r29120 r35309  
    1616
    1717    /**
    18      * List of media thumbnail ids
    19      * @var array
    20      */
    21     protected $_ids = array();
    22 
    23     /**
    24      * Set up the test fixture.
    25      */
    26     public function setUp() {
    27         parent::setUp();
    28     }
    29 
    30     /**
    3118     * Tear down the test fixture.
    3219     */
    3320    public function tearDown() {
    3421        // Cleanup
    35         foreach ( $this->_ids as $id ) {
    36             wp_delete_attachment( $id, true );
    37         }
    38 
     22        $this->remove_added_uploads();
    3923        parent::tearDown();
    40     }
    41 
    42     /**
    43      * Function snagged from ./tests/post/attachments.php
    44      */
    45     function _make_attachment($upload, $parent_post_id = 0) {
    46         $type = '';
    47         if ( !empty($upload['type']) ) {
    48             $type = $upload['type'];
    49         } else {
    50             $mime = wp_check_filetype( $upload['file'] );
    51             if ($mime)
    52                 $type = $mime['type'];
    53         }
    54 
    55         $attachment = array(
    56             'post_title' => basename( $upload['file'] ),
    57             'post_content' => '',
    58             'post_type' => 'attachment',
    59             'post_parent' => $parent_post_id,
    60             'post_mime_type' => $type,
    61             'guid' => $upload[ 'url' ],
    62         );
    63 
    64         // Save the data
    65         $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $parent_post_id );
    66         wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
    67         return $this->_ids[] = $id;
    6824    }
    6925
Note: See TracChangeset for help on using the changeset viewer.