mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Media:
- Introduce `wp_image_file_matches_image_meta()` utility function to check whether the image meta (retrieved by attachment ID) matches an image path or URI. A mismatch may happen in some cases, for example after the posts have been exported from one website and imported in another. - Add unit tests for the new function. - Improve `wp_image_src_get_dimensions()` a bit and use the new function to prevent these edge cases. Fixes #50543. git-svn-id: https://develop.svn.wordpress.org/trunk@48329 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2808,6 +2808,49 @@ EOF;
|
||||
'arbitrary context => true' => array( 'something_completely_arbitrary', true ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50543
|
||||
*/
|
||||
function test_wp_image_file_matches_image_meta() {
|
||||
$image_meta = wp_get_attachment_metadata( self::$large_id );
|
||||
$image_src_full = wp_get_attachment_image_url( self::$large_id, 'full' );
|
||||
$image_src_medium = wp_get_attachment_image_url( self::$large_id, 'medium' );
|
||||
|
||||
$this->assertTrue( wp_image_file_matches_image_meta( $image_src_full, $image_meta ) );
|
||||
$this->assertTrue( wp_image_file_matches_image_meta( $image_src_medium, $image_meta ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50543
|
||||
*/
|
||||
function test_wp_image_file_matches_image_meta_no_subsizes() {
|
||||
$image_meta = wp_get_attachment_metadata( self::$large_id );
|
||||
$image_src = wp_get_attachment_image_url( self::$large_id, 'full' );
|
||||
$image_meta['sizes'] = array();
|
||||
|
||||
$this->assertTrue( wp_image_file_matches_image_meta( $image_src, $image_meta ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50543
|
||||
*/
|
||||
function test_wp_image_file_matches_image_meta_invalid_meta() {
|
||||
$image_meta = ''; // Attachment is not an image.
|
||||
$image_src = $this->img_url;
|
||||
|
||||
$this->assertFalse( wp_image_file_matches_image_meta( $image_src, $image_meta ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50543
|
||||
*/
|
||||
function test_wp_image_file_matches_image_meta_different_meta() {
|
||||
$image_meta = wp_get_attachment_metadata( self::$large_id );
|
||||
$image_src = $this->img_url; // Different image.
|
||||
|
||||
$this->assertFalse( wp_image_file_matches_image_meta( $image_src, $image_meta ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user