mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Media: Accessibility: Copy attachment properties on site icon crop.
Add parity between site icon, custom header, and default image crop behaviors. [53027] fixed a bug where alt text and caption were not copied on custom headers, but did not apply that change in any other context. Deprecate the `create_attachment_object` method in the `Wp_Site_Icon` and `Custom_Image_Header` classes and replace that functionality with the new function `wp_copy_parent_attachment_properties()` to improve consistency. Props afercia, rcreators, jorbin, joedolson, huzaifaalmesbah, shailu25, swissspidy, mukesh27. Fixes #60524. git-svn-id: https://develop.svn.wordpress.org/trunk@57755 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
Showing
7 changed files
with
125 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/phpunit/tests/media/wpCopyParentAttachmentProperties.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* Tests for the `wp_copy_parent_attachment_properties()` function. | ||
* | ||
* @group media | ||
* @covers ::wp_copy_parent_attachment_properties | ||
*/ | ||
class Tests_Media_wpCopyParentAttachmentProperties extends WP_UnitTestCase { | ||
|
||
public function tear_down() { | ||
$this->remove_added_uploads(); | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
public function test_wp_copy_parent_attachment_properties() { | ||
$attachment = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' ); | ||
$parent_url = get_post( $attachment )->guid; | ||
// Add alternative text. | ||
update_post_meta( $attachment, '_wp_attachment_image_alt', 'Alt text' ); | ||
// Add image description. | ||
wp_update_post( | ||
array( | ||
'ID' => $attachment, | ||
'post_excerpt' => 'Image description', | ||
) | ||
); | ||
$file = wp_crop_image( | ||
DIR_TESTDATA . '/images/canola.jpg', | ||
0, | ||
0, | ||
100, | ||
100, | ||
100, | ||
100 | ||
); | ||
|
||
$object = wp_copy_parent_attachment_properties( $file, $attachment ); | ||
$cropped = str_replace( wp_basename( $parent_url ), 'cropped-canola.jpg', $parent_url ); | ||
|
||
$this->assertSame( $object['post_title'], 'cropped-canola.jpg', 'Attachment title is not identical' ); | ||
$this->assertSame( $object['context'], '', 'Attachment context is not identical' ); | ||
$this->assertSame( $object['post_mime_type'], 'image/jpeg', 'Attachment mime type is not identical' ); | ||
$this->assertSame( $object['post_content'], $cropped, 'Attachment content is not identical' ); | ||
$this->assertSame( $object['guid'], $cropped, 'Attachment GUID is not identical' ); | ||
$this->assertSame( $object['meta_input']['_wp_attachment_image_alt'], 'Alt text', 'Attachment alt text is not identical' ); | ||
$this->assertSame( $object['post_excerpt'], 'Image description', 'Attachment description is not identical' ); | ||
|
||
unlink( $file ); | ||
} | ||
} |