WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/20/14 18:26:17 (4 years ago)
Author:
wonderboymusic
Message:

Reinstate the changes from [28579] with some adjustments:

  • Check ! empty( $postarr['file'] ) before calling update_attached_file()
  • Add a unit test: test_update_attachment_fields()
  • Run the same logic for empty guid for attachments that always ran in wp_insert_post(), as per #18310. This fixes a unit test that would have broken when this ticket was marked closed.
  • Updated the unit test in Tests_Media::test_wp_prepare_attachment_for_js() to account for url no longer being empty

Props kovshenin, wonderboymusic.
See #21963.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/attachments.php

    r26004 r28788  
    232232    } 
    233233 
     234    /** 
     235     * @ticket 21963 
     236     */ 
     237    function test_update_attachment_fields() { 
     238        $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); 
     239        $contents = file_get_contents($filename); 
     240 
     241        $upload = wp_upload_bits( basename( $filename ), null, $contents ); 
     242        $this->assertTrue( empty( $upload['error'] ) ); 
     243 
     244        $id = $this->_make_attachment( $upload ); 
     245 
     246        $attached_file = get_post_meta( $id, '_wp_attached_file', true ); 
     247 
     248        $post = get_post( $id, ARRAY_A ); 
     249 
     250        $post['post_title'] = 'title'; 
     251        $post['post_excerpt'] = 'caption'; 
     252        $post['post_content'] = 'description'; 
     253 
     254        wp_update_post( $post ); 
     255 
     256        // Make sure the update didn't remove the attached file. 
     257        $this->assertEquals( $attached_file, get_post_meta( $id, '_wp_attached_file', true ) ); 
     258    } 
     259 
    234260} 
Note: See TracChangeset for help on using the changeset viewer.