@@ -1686,6 +1686,54 @@ Feature: Regenerate WordPress attachments
16861686 """
16871687 And the return code should be 1
16881688
1689+ @require-wp-5.3
1690+ Scenario : Regenerate a large image that was edited by the user preserves the edits
1691+ Given download:
1692+ | path | url |
1693+ | {CACHE_DIR }/large -image .jpg | http ://wp -cli .org /behat -data /large -image .jpg |
1694+ And I run `wp option update uploads_use_yearmonth_folders 0`
1695+
1696+ When I run `wp media import {CACHE_DIR}/large-image.jpg --title="My imported large attachment" --porcelain`
1697+ Then save STDOUT as {ATTACHMENT_ID}
1698+ And the wp-content/uploads/large-image.jpg file should exist
1699+ And the wp-content/uploads/large-image-scaled.jpg file should exist
1700+
1701+ # Simulate a user edit by copying the scaled file as an "edited" version,
1702+ # updating the attached file metadata, and setting backup sizes.
1703+ When I run `wp eval '
1704+ $id = {ATTACHMENT_ID};
1705+ $meta = wp_get_attachment_metadata( $id );
1706+ $old_file = get_attached_file( $id );
1707+ $edited_file = preg_replace( "/(\. [^.]+)$/", "-e0000000000000$1", $old_file );
1708+ copy( $old_file, $edited_file );
1709+ $edited_relative = _wp_relative_upload_path( $edited_file );
1710+ update_post_meta( $id, "_wp_attached_file", $edited_relative );
1711+ $backup = array();
1712+ foreach ( $meta["sizes"] as $size => $size_data ) {
1713+ $backup[ $size . "-orig" ] = $size_data;
1714+ }
1715+ update_post_meta( $id, "_wp_attachment_backup_sizes", $backup );
1716+ ' `
1717+ Then the wp-content/uploads/large-image-scaled-e0000000000000.jpg file should exist
1718+
1719+ When I run `wp post meta get {ATTACHMENT_ID} _wp_attached_file`
1720+ Then STDOUT should contain:
1721+ """
1722+ large-image-scaled-e0000000000000.jpg
1723+ """
1724+
1725+ When I run `wp media regenerate {ATTACHMENT_ID} --yes`
1726+ Then STDOUT should contain:
1727+ """
1728+ Regenerated thumbnails for "My imported large attachment"
1729+ """
1730+
1731+ When I run `wp post meta get {ATTACHMENT_ID} _wp_attached_file`
1732+ Then STDOUT should contain:
1733+ """
1734+ large-image-scaled-e0000000000000.jpg
1735+ """
1736+
16891737 Scenario : Only delete missing image sizes
16901738 Given download:
16911739 | path | url |
0 commit comments