mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-06 07:36:58 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@28788 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -148,7 +148,8 @@ CAP;
|
||||
$this->assertEquals( '', $prepped['mime'] );
|
||||
$this->assertEquals( '', $prepped['type'] );
|
||||
$this->assertEquals( '', $prepped['subtype'] );
|
||||
$this->assertEquals( '', $prepped['url'] );
|
||||
// #21963, there will be a guid always, so there will be a URL
|
||||
$this->assertNotEquals( '', $prepped['url'] );
|
||||
$this->assertEquals( site_url( 'wp-includes/images/media/default.png' ), $prepped['icon'] );
|
||||
|
||||
// Fake a mime
|
||||
|
||||
@@ -231,4 +231,30 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
|
||||
$this->assertFalse( empty( $guid ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21963
|
||||
*/
|
||||
function test_update_attachment_fields() {
|
||||
$filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
|
||||
$contents = file_get_contents($filename);
|
||||
|
||||
$upload = wp_upload_bits( basename( $filename ), null, $contents );
|
||||
$this->assertTrue( empty( $upload['error'] ) );
|
||||
|
||||
$id = $this->_make_attachment( $upload );
|
||||
|
||||
$attached_file = get_post_meta( $id, '_wp_attached_file', true );
|
||||
|
||||
$post = get_post( $id, ARRAY_A );
|
||||
|
||||
$post['post_title'] = 'title';
|
||||
$post['post_excerpt'] = 'caption';
|
||||
$post['post_content'] = 'description';
|
||||
|
||||
wp_update_post( $post );
|
||||
|
||||
// Make sure the update didn't remove the attached file.
|
||||
$this->assertEquals( $attached_file, get_post_meta( $id, '_wp_attached_file', true ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user