WordPress.org

Make WordPress Core

Ticket #42990: 42990.patch

File 42990.patch, 24.8 KB (added by Frank Klein, 23 months ago)
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php

    diff --git tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
    index 7288af6d63..113f67616d 100644
    class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { 
    3333                return wp_insert_attachment( $r, $r['file'], $r['post_parent'] );
    3434        }
    3535
    36         function create_upload_object( $file, $parent = 0 ) {
     36        /**
     37         * Upload a file and create an associated attachment post.
     38         *
     39         * @since 4.4.0
     40         *
     41         * @param string $file   Path of the file to upload and associate to the attachment.
     42         * @param int    $parent Optional. Attachment parent post id.
     43         *
     44         * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
     45         */
     46        public function create_upload_object( $file, $parent = 0 ) {
    3747                $contents = file_get_contents( $file );
    3848                $upload   = wp_upload_bits( basename( $file ), null, $contents );
    3949
  • tests/phpunit/includes/testcase.php

    diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
    index fee06e0df9..4272a02d39 100644
    class WP_UnitTestCase extends PHPUnit_Framework_TestCase { 
    10321032         * Creates an attachment post from an uploaded file.
    10331033         *
    10341034         * @since 4.4.0
     1035         * @deprecated 5.0.0 Use WP_UnitTest_Factory_For_Attachment::create_upload_object() instead.
    10351036         *
    10361037         * @param array $upload         Array of information about the uploaded file, provided by wp_upload_bits().
    10371038         * @param int   $parent_post_id Optional. Parent post ID.
    class WP_UnitTestCase extends PHPUnit_Framework_TestCase { 
    10391040         * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
    10401041         */
    10411042        function _make_attachment( $upload, $parent_post_id = 0 ) {
    1042                 $type = '';
    1043                 if ( ! empty( $upload['type'] ) ) {
    1044                         $type = $upload['type'];
    1045                 } else {
    1046                         $mime = wp_check_filetype( $upload['file'] );
    1047                         if ( $mime ) {
    1048                                 $type = $mime['type'];
    1049                         }
    1050                 }
    1051 
    1052                 $attachment = array(
    1053                         'post_title'     => basename( $upload['file'] ),
    1054                         'post_content'   => '',
    1055                         'post_type'      => 'attachment',
    1056                         'post_parent'    => $parent_post_id,
    1057                         'post_mime_type' => $type,
    1058                         'guid'           => $upload['url'],
    1059                 );
     1043                trigger_error( __METHOD__ . ' is deprecated since version 5.0.0. Use WP_UnitTest_Factory_For_Attachment::create_upload_object() instead' );
    10601044
    1061                 $id = wp_insert_attachment( $attachment, $upload['file'], $parent_post_id );
    1062                 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
    1063                 return $id;
     1045                return self::factory()->attachment->create_upload_object( $upload['file'], $parent_post_id );
    10641046        }
    10651047
    10661048        /**
  • tests/phpunit/tests/ajax/Attachments.php

    diff --git tests/phpunit/tests/ajax/Attachments.php tests/phpunit/tests/ajax/Attachments.php
    index cf11ddc5a0..31012f687d 100644
    class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase { 
    2626                wp_set_current_user( $user_id );
    2727                $_POST = array_merge( $_POST, $post );
    2828
    29                 $filename = DIR_TESTDATA . '/images/canola.jpg';
    30                 $contents = file_get_contents( $filename );
    31 
    32                 $upload     = wp_upload_bits( basename( $filename ), null, $contents );
    33                 $attachment = $this->_make_attachment( $upload );
     29                $attachment = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' );
    3430
    3531                // Set up a default request
    3632                $_POST['nonce']      = wp_create_nonce( 'media-send-to-editor' );
    class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase { 
    7773                wp_set_current_user( $user_id );
    7874                $_POST = array_merge( $_POST, $post );
    7975
    80                 $filename = DIR_TESTDATA . '/formatting/entities.txt';
    81                 $contents = file_get_contents( $filename );
    82 
    83                 $upload     = wp_upload_bits( basename( $filename ), null, $contents );
    84                 $attachment = $this->_make_attachment( $upload );
     76                $attachment = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/formatting/entities.txt' );
    8577
    8678                // Set up a default request
    8779                $_POST['nonce']      = wp_create_nonce( 'media-send-to-editor' );
  • tests/phpunit/tests/ajax/MediaEdit.php

    diff --git tests/phpunit/tests/ajax/MediaEdit.php tests/phpunit/tests/ajax/MediaEdit.php
    index a55e3829a8..892893be1b 100644
    class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase { 
    2929        public function testCropImageThumbnail() {
    3030                include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
    3131
    32                 $filename = DIR_TESTDATA . '/images/canola.jpg';
    33                 $contents = file_get_contents( $filename );
    34 
    35                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    36                 $id     = $this->_make_attachment( $upload );
     32                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' );
    3733
    3834                $_REQUEST['action']  = 'image-editor';
    3935                $_REQUEST['context'] = 'edit-attachment';
    class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase { 
    6056
    6157                include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
    6258
    63                 $filename = DIR_TESTDATA . '/images/canola.jpg';
    64                 $contents = file_get_contents( $filename );
    65 
    66                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    67                 $id     = $this->_make_attachment( $upload );
     59                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' );
    6860
    6961                $_REQUEST['action']  = 'image-editor';
    7062                $_REQUEST['context'] = 'edit-attachment';
  • tests/phpunit/tests/general/template.php

    diff --git tests/phpunit/tests/general/template.php tests/phpunit/tests/general/template.php
    index 05ef9777d8..c0423afe4f 100644
    class Tests_General_Template extends WP_UnitTestCase { 
    228228         * @since 4.3.0
    229229         */
    230230        function _insert_attachment() {
    231                 $filename = DIR_TESTDATA . '/images/test-image.jpg';
    232                 $contents = file_get_contents( $filename );
    233 
    234                 $upload              = wp_upload_bits( basename( $filename ), null, $contents );
    235                 $this->site_icon_url = $upload['url'];
    236 
    237                 // Save the data
    238                 $this->site_icon_id = $this->_make_attachment( $upload );
     231                $this->site_icon_id  = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
     232                $this->site_icon_url = wp_get_attachment_url( $this->site_icon_id );
    239233                return $this->site_icon_id;
    240234        }
    241235
    class Tests_General_Template extends WP_UnitTestCase { 
    404398         * @since 4.5.0
    405399         */
    406400        function _insert_custom_logo() {
    407                 $filename = DIR_TESTDATA . '/images/test-image.jpg';
    408                 $contents = file_get_contents( $filename );
    409                 $upload   = wp_upload_bits( basename( $filename ), null, $contents );
    410 
    411                 // Save the data.
    412                 $this->custom_logo_url = $upload['url'];
    413                 $this->custom_logo_id  = $this->_make_attachment( $upload );
     401                $this->custom_logo_id  = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
     402                $this->custom_logo_url = wp_get_attachment_url( $this->custom_logo_id );
    414403                return $this->custom_logo_id;
    415404        }
    416405
  • tests/phpunit/tests/image/intermediateSize.php

    diff --git tests/phpunit/tests/image/intermediateSize.php tests/phpunit/tests/image/intermediateSize.php
    index 95ee173edd..99b94bea21 100644
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    1515                parent::tearDown();
    1616        }
    1717
    18         public function _make_attachment( $file, $parent_post_id = 0 ) {
    19                 $contents = file_get_contents( $file );
    20                 $upload   = wp_upload_bits( basename( $file ), null, $contents );
    21 
    22                 return parent::_make_attachment( $upload, $parent_post_id );
    23         }
    24 
    2518        function test_make_intermediate_size_no_size() {
    2619                $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false );
    2720
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    7164        function test_get_intermediate_sizes_by_name() {
    7265                add_image_size( 'test-size', 330, 220, true );
    7366
    74                 $file = DIR_TESTDATA . '/images/waffles.jpg';
    75                 $id   = $this->_make_attachment( $file, 0 );
     67                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
    7668
    7769                // look for a size by name
    7870                $image = image_get_intermediate_size( $id, 'test-size' );
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    9486                add_image_size( 'false-height', 330, 400, true );
    9587                add_image_size( 'false-width', 600, 220, true );
    9688
    97                 $file = DIR_TESTDATA . '/images/waffles.jpg';
    98                 $id   = $this->_make_attachment( $file, 0 );
     89                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
    9990
    10091                // look for a size by array that exists
    10192                // note: staying larger than 300px to miss default medium crop
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    116107                add_image_size( 'false-height', 330, 100, true );
    117108                add_image_size( 'false-width', 150, 220, true );
    118109
    119                 $file = DIR_TESTDATA . '/images/waffles.jpg';
    120                 $id   = $this->_make_attachment( $file, 0 );
     110                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
    121111
    122112                // look for a size by array that doesn't exist
    123113                // note: staying larger than 300px to miss default medium crop
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    137127                add_image_size( 'false-height', 330, 100, true );
    138128                add_image_size( 'false-width', 150, 220, true );
    139129
    140                 $file = DIR_TESTDATA . '/images/waffles.jpg';
    141                 $id   = $this->_make_attachment( $file, 0 );
     130                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
    142131
    143132                // look for a size by array that doesn't exist
    144133                // note: staying larger than 300px to miss default medium crop
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    160149                add_image_size( 'test-size', $random_w, 0, false );
    161150                add_image_size( 'false-height', $random_w, 100, true );
    162151
    163                 $file = DIR_TESTDATA . '/images/waffles.jpg';
    164                 $id   = $this->_make_attachment( $file, 0 );
     152                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
    165153
    166154                $original = wp_get_attachment_metadata( $id );
    167155                $image_w  = $random_w;
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    188176                add_image_size( 'test-size', 0, $height, false );
    189177                add_image_size( 'false-height', 300, $height, true );
    190178
    191                 $file = DIR_TESTDATA . '/images/waffles.jpg';
    192                 $id   = $this->_make_attachment( $file, 0 );
     179                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
    193180
    194181                $original = wp_get_attachment_metadata( $id );
    195182                $image_h  = $height;
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    214201                $height = 201;
    215202                add_image_size( 'off-by-one', $width, $height, true );
    216203
    217                 $file = DIR_TESTDATA . '/images/waffles.jpg';
    218                 $id   = $this->_make_attachment( $file, 0 );
     204                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
    219205
    220206                $original = wp_get_attachment_metadata( $id );
    221207                $image_h  = $height;
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    235221                // Add a hard cropped size that matches the aspect ratio we're going to test.
    236222                add_image_size( 'test-size', 200, 100, true );
    237223
    238                 $file = DIR_TESTDATA . '/images/waffles.jpg';
    239                 $id   = $this->_make_attachment( $file, 0 );
     224                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
    240225
    241226                // Request a size by array that doesn't exist and is smaller than the 'thumbnail'
    242227                $image = image_get_intermediate_size( $id, array( 50, 25 ) );
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    249234         * @ticket 34384
    250235         */
    251236        public function test_get_intermediate_size_with_small_size_array_fallback() {
    252                 $file = DIR_TESTDATA . '/images/waffles.jpg';
    253                 $id   = $this->_make_attachment( $file, 0 );
     237                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
    254238
    255239                $original       = wp_get_attachment_metadata( $id );
    256240                $thumbnail_file = $original['sizes']['thumbnail']['file'];
  • tests/phpunit/tests/image/siteIcon.php

    diff --git tests/phpunit/tests/image/siteIcon.php tests/phpunit/tests/image/siteIcon.php
    index 509b69f975..974dfe6b04 100644
    class Tests_WP_Site_Icon extends WP_UnitTestCase { 
    156156        }
    157157
    158158        function _insert_attachment() {
    159                 if ( $this->attachment_id ) {
    160                         return $this->attachment_id;
     159                if ( ! $this->attachment_id ) {
     160                        $this->attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    161161                }
    162162
    163                 $filename = DIR_TESTDATA . '/images/test-image.jpg';
    164                 $contents = file_get_contents( $filename );
    165 
    166                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    167 
    168                 $this->attachment_id = $this->_make_attachment( $upload );
    169163                return $this->attachment_id;
    170164        }
    171165}
  • tests/phpunit/tests/post/attachments.php

    diff --git tests/phpunit/tests/post/attachments.php tests/phpunit/tests/post/attachments.php
    index 08e44500f8..21813ab02f 100644
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    2222        }
    2323
    2424        function test_insert_image_no_thumb() {
    25 
    2625                // this image is smaller than the thumbnail size so it won't have one
    27                 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
    28                 $contents = file_get_contents( $filename );
    29 
    30                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    31                 $this->assertTrue( empty( $upload['error'] ) );
    32 
    33                 $id = $this->_make_attachment( $upload );
     26                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    3427
    3528                // intermediate copies should not exist
    3629                $this->assertFalse( image_get_intermediate_size( $id, 'thumbnail' ) );
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    3932
    4033                // medium, medium_large, and full size will both point to the original
    4134                $downsize = image_downsize( $id, 'medium' );
    42                 $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) );
     35                $this->assertEquals( basename( wp_get_attachment_url( $id ) ), basename( $downsize[0] ) );
    4336                $this->assertEquals( 50, $downsize[1] );
    4437                $this->assertEquals( 50, $downsize[2] );
    4538
    4639                $downsize = image_downsize( $id, 'medium_large' );
    47                 $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) );
     40                $this->assertEquals( basename( wp_get_attachment_url( $id ) ), basename( $downsize[0] ) );
    4841                $this->assertEquals( 50, $downsize[1] );
    4942                $this->assertEquals( 50, $downsize[2] );
    5043
    5144                $downsize = image_downsize( $id, 'full' );
    52                 $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) );
     45                $this->assertEquals( basename( wp_get_attachment_url( $id ) ), basename( $downsize[0] ) );
    5346                $this->assertEquals( 50, $downsize[1] );
    5447                $this->assertEquals( 50, $downsize[2] );
    5548
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    6356                update_option( 'medium_size_w', 0 );
    6457                update_option( 'medium_size_h', 0 );
    6558
    66                 $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' );
    67                 $contents = file_get_contents( $filename );
    68 
    69                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    70                 $this->assertTrue( empty( $upload['error'] ) );
    71 
    72                 $id = $this->_make_attachment( $upload );
     59                $id =  self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/a2-small.jpg' );;
    7360
    7461                // intermediate copies should exist: thumbnail only
    7562                $thumb = image_get_intermediate_size( $id, 'thumbnail' );
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    119106                update_option( 'medium_large_size_w', 600 );
    120107                update_option( 'medium_large_size_h', 0 );
    121108
    122                 $filename = ( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );
    123                 $contents = file_get_contents( $filename );
    124 
    125                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    126                 $this->assertTrue( empty( $upload['error'] ) );
    127 
    128                 $id      = $this->_make_attachment( $upload );
     109                $id      = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );
    129110                $uploads = wp_upload_dir();
    130111
    131112                // intermediate copies should exist: thumbnail and medium
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    178159                update_option( 'medium_large_size_w', 600 );
    179160                update_option( 'medium_large_size_h', 0 );
    180161
    181                 $filename = ( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );
    182                 $contents = file_get_contents( $filename );
    183 
    184                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    185                 $this->assertTrue( empty( $upload['error'] ) );
    186 
    187                 $id      = $this->_make_attachment( $upload );
     162                $id      = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );;
    188163                $uploads = wp_upload_dir();
    189164
    190165                // check that the file and intermediates exist
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    220195         * @ticket 21963
    221196         */
    222197        function test_insert_image_without_guid() {
    223                 // this image is smaller than the thumbnail size so it won't have one
    224                 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
    225                 $contents = file_get_contents( $filename );
     198                $attachment_id = self::factory()->attachment->create( array( 'file' => '' ) );
    226199
    227                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    228                 $this->assertTrue( empty( $upload['error'] ) );
    229 
    230                 $upload['url'] = '';
    231                 $id            = $this->_make_attachment( $upload );
     200                $guid = get_the_guid( $attachment_id );
    232201
    233                 $guid = get_the_guid( $id );
    234202                $this->assertFalse( empty( $guid ) );
     203                $this->assertContains( '?attachment_id=' . $attachment_id, $guid );
    235204        }
    236205
    237206        /**
    238207         * @ticket 21963
    239208         */
    240209        function test_update_attachment_fields() {
    241                 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
    242                 $contents = file_get_contents( $filename );
    243 
    244                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    245                 $this->assertTrue( empty( $upload['error'] ) );
    246 
    247                 $id = $this->_make_attachment( $upload );
     210                $id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    248211
    249212                $attached_file = get_post_meta( $id, '_wp_attached_file', true );
    250213
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    264227         * @ticket 29646
    265228         */
    266229        function test_update_orphan_attachment_parent() {
    267                 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
    268                 $contents = file_get_contents( $filename );
    269 
    270                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    271                 $this->assertTrue( empty( $upload['error'] ) );
    272 
    273                 $attachment_id = $this->_make_attachment( $upload );
     230                $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    274231
    275232                // Assert that the attachment is an orphan
    276233                $attachment = get_post( $attachment_id );
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    296253                $siteurl = get_option( 'siteurl' );
    297254                update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) );
    298255
    299                 $filename = DIR_TESTDATA . '/images/test-image.jpg';
    300                 $contents = file_get_contents( $filename );
    301 
    302                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    303                 $this->assertTrue( empty( $upload['error'] ) );
    304 
    305                 // Set attachment ID.
    306                 $attachment_id = $this->_make_attachment( $upload );
     256                $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    307257
    308258                $_SERVER['HTTPS'] = 'off';
    309259
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    321271                $siteurl = get_option( 'siteurl' );
    322272                update_option( 'siteurl', set_url_scheme( $siteurl, 'https' ) );
    323273
    324                 $filename = DIR_TESTDATA . '/images/test-image.jpg';
    325                 $contents = file_get_contents( $filename );
    326 
    327                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    328                 $this->assertTrue( empty( $upload['error'] ) );
    329 
    330274                // Set attachment ID.
    331                 $attachment_id = $this->_make_attachment( $upload );
     275                $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    332276
    333277                $_SERVER['HTTPS'] = 'off';
    334278
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    346290                $siteurl = get_option( 'siteurl' );
    347291                update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) );
    348292
    349                 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
    350                 $contents = file_get_contents( $filename );
    351 
    352                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    353                 $this->assertTrue( empty( $upload['error'] ) );
    354 
    355293                // Set attachment ID
    356                 $attachment_id = $this->_make_attachment( $upload );
     294                $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    357295
    358296                $_SERVER['HTTPS'] = 'on';
    359297
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    374312                $siteurl = get_option( 'siteurl' );
    375313                update_option( 'siteurl', set_url_scheme( $siteurl, 'https' ) );
    376314
    377                 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
    378                 $contents = file_get_contents( $filename );
    379 
    380                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    381                 $this->assertTrue( empty( $upload['error'] ) );
    382 
    383315                // Set attachment ID.
    384                 $attachment_id = $this->_make_attachment( $upload );
     316                $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    385317
    386318                $_SERVER['HTTPS'] = 'on';
    387319
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    402334                $siteurl = get_option( 'siteurl' );
    403335                update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) );
    404336
    405                 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
    406                 $contents = file_get_contents( $filename );
    407 
    408                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    409                 $this->assertTrue( empty( $upload['error'] ) );
    410 
    411337                // Set attachment ID
    412                 $attachment_id = $this->_make_attachment( $upload );
     338                $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    413339
    414340                $_SERVER['HTTPS'] = 'on';
    415341                set_current_screen( 'dashboard' );
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    429355                // Set https upload URL
    430356                add_filter( 'upload_dir', '_upload_dir_https' );
    431357
    432                 $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
    433                 $contents = file_get_contents( $filename );
    434 
    435                 $upload = wp_upload_bits( basename( $filename ), null, $contents );
    436                 $this->assertTrue( empty( $upload['error'] ) );
    437 
    438358                // Set attachment ID
    439                 $attachment_id = $this->_make_attachment( $upload );
     359                $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );;
    440360
    441361                $_SERVER['HTTPS'] = 'on';
    442362                set_current_screen( 'dashboard' );
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    451371        }
    452372
    453373        public function test_wp_attachment_is() {
    454                 $filename = DIR_TESTDATA . '/images/test-image.jpg';
    455                 $contents = file_get_contents( $filename );
    456 
    457                 $upload        = wp_upload_bits( basename( $filename ), null, $contents );
    458                 $attachment_id = $this->_make_attachment( $upload );
     374                $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
    459375
    460376                $this->assertTrue( wp_attachment_is_image( $attachment_id ) );
    461377                $this->assertTrue( wp_attachment_is( 'image', $attachment_id ) );
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    469385                        add_filter( 'upload_mimes', array( $this, 'whitelist_psd_mime_type' ), 10, 2 );
    470386                }
    471387
    472                 $filename = DIR_TESTDATA . '/images/test-image.psd';
    473                 $contents = file_get_contents( $filename );
    474 
    475                 $upload        = wp_upload_bits( basename( $filename ), null, $contents );
    476                 $attachment_id = $this->_make_attachment( $upload );
     388                $attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.psd' );
    477389
    478390                $this->assertFalse( wp_attachment_is_image( $attachment_id ) );
    479391                $this->assertTrue( wp_attachment_is( 'psd', $attachment_id ) );
  • tests/phpunit/tests/xmlrpc/wp/getMediaItem.php

    diff --git tests/phpunit/tests/xmlrpc/wp/getMediaItem.php tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
    index e036a7f4b9..3759343191 100644
    class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase { 
    1818
    1919                add_theme_support( 'post-thumbnails' );
    2020
    21                 $filename = ( DIR_TESTDATA . '/images/waffles.jpg' );
    22                 $contents = file_get_contents( $filename );
    23                 $upload   = wp_upload_bits( basename( $filename ), null, $contents );
    24 
    25                 $this->attachment_id   = $this->_make_attachment( $upload, self::$post_id );
     21                $this->attachment_id   = self::factory()->attachment->create_upload_object(
     22                        DIR_TESTDATA . '/images/waffles.jpg',
     23                        self::$post_id
     24                );
    2625                $this->attachment_data = get_post( $this->attachment_id, ARRAY_A );
    2726
    2827                set_post_thumbnail( self::$post_id, $this->attachment_id );