Feature: Regenerate WordPress attachments
Background:
Given a WP install
And I try `wp theme install twentynineteen --activate`
Scenario: Regenerate all images while none exists
When I try `wp media regenerate --yes`
Then STDERR should contain:
"""
No images found.
"""
And the return code should be 0
@require-wp-5.3
Scenario: Regenerate all images default behavior
Given download:
| path | url |
| {CACHE_DIR}/large-image.jpg | http://wp-cli.org/behat-data/large-image.jpg |
| {CACHE_DIR}/canola.jpg | http://wp-cli.org/behat-data/canola.jpg |
| {CACHE_DIR}/white-150-square.jpg | http://wp-cli.org/behat-data/white-150-square.jpg |
And I run `wp option update uploads_use_yearmonth_folders 0`
When I run `wp media import {CACHE_DIR}/large-image.jpg --title="My imported large attachment" --porcelain`
Then save STDOUT as {LARGE_ATTACHMENT_ID}
And the wp-content/uploads/large-image.jpg file should exist
And the wp-content/uploads/large-image-scaled.jpg file should exist
And the wp-content/uploads/large-image-150x150.jpg file should exist
And the wp-content/uploads/large-image-300x225.jpg file should exist
And the wp-content/uploads/large-image-1024x768.jpg file should exist
And the wp-content/uploads/large-image-2048x1536.jpg file should exist
When I run `wp media import {CACHE_DIR}/canola.jpg --title="My imported medium attachment" --porcelain`
Then save STDOUT as {MEDIUM_ATTACHMENT_ID}
And the wp-content/uploads/canola.jpg file should exist
And the wp-content/uploads/canola-150x150.jpg file should exist
And the wp-content/uploads/canola-300x225.jpg file should exist
And the wp-content/uploads/canola-1024x768.jpg file should not exist
When I run `wp media import {CACHE_DIR}/white-150-square.jpg --title="My imported small attachment" --porcelain`
Then save STDOUT as {SMALL_ATTACHMENT_ID}
And the wp-content/uploads/white-150-square.jpg file should exist
And the wp-content/uploads/white-150-square-300x300.jpg file should not exist
And the wp-content/uploads/white-150-square-1024x1024.jpg file should not exist
When I run `wp media regenerate --yes`
Then STDOUT should contain:
"""
Found 3 images to regenerate.
"""
And STDOUT should contain:
"""
/3 Regenerated thumbnails for "My imported large attachment" (ID {LARGE_ATTACHMENT_ID})
"""
And STDOUT should contain:
"""
/3 Regenerated thumbnails for "My imported medium attachment" (ID {MEDIUM_ATTACHMENT_ID})
"""
And STDOUT should contain:
"""
/3 Regenerated thumbnails for "My imported small attachment" (ID {SMALL_ATTACHMENT_ID})
"""
And STDOUT should contain:
"""
Success: Regenerated 3 of 3 images.
"""
And the wp-content/uploads/large-image.jpg file should exist
And the wp-content/uploads/large-image-scaled.jpg file should exist
And the wp-content/uploads/large-image-150x150.jpg file should exist
And the wp-content/uploads/large-image-300x225.jpg file should exist
And the wp-content/uploads/large-image-1024x768.jpg file should exist
And the wp-content/uploads/large-image-2048x1536.jpg file should exist
And the wp-content/uploads/canola.jpg file should exist
And the wp-content/uploads/canola-150x150.jpg file should exist
And the wp-content/uploads/canola-300x225.jpg file should exist
And the wp-content/uploads/canola-1024x768.jpg file should not exist
And the wp-content/uploads/white-150-square.jpg file should exist
And the wp-content/uploads/white-150-square-300x300.jpg file should not exist
And the wp-content/uploads/white-150-square-1024x1024.jpg file should not exist
# Behavior changed with WordPress 5.3+, so we're adding separate tests for previous versions.
# Changes that impact this:
# https://core.trac.wordpress.org/ticket/43524
# https://core.trac.wordpress.org/ticket/47873
@less-than-wp-5.3 @broken
Scenario: Regenerate all images default behavior (pre-WP-5.3)
Given download:
| path | url |
| {CACHE_DIR}/large-image.jpg | http://wp-cli.org/behat-data/large-image.jpg |
| {CACHE_DIR}/canola.jpg | http://wp-cli.org/behat-data/canola.jpg |
| {CACHE_DIR}/white-150-square.jpg | http://wp-cli.org/behat-data/white-150-square.jpg |
And I run `wp option update uploads_use_yearmonth_folders 0`
When I run `wp media import {CACHE_DIR}/large-image.jpg --title="My imported large attachment" --porcelain`
Then save STDOUT as {LARGE_ATTACHMENT_ID}
And the wp-content/uploads/large-image.jpg file should exist
And the wp-content/uploads/large-image-150x150.jpg file should exist
And the wp-content/uploads/large-image-300x225.jpg file should exist
And the wp-content/uploads/large-image-1024x768.jpg file should exist
When I run `wp media import {CACHE_DIR}/canola.jpg --title="My imported medium attachment" --porcelain`
Then save STDOUT as {MEDIUM_ATTACHMENT_ID}
And the wp-content/uploads/canola.jpg file should exist
And the wp-content/uploads/canola-150x150.jpg file should exist
And the wp-content/uploads/canola-300x225.jpg file should exist
And the wp-content/uploads/canola-1024x768.jpg file should not exist
When I run `wp media import {CACHE_DIR}/white-150-square.jpg --title="My imported small attachment" --porcelain`
Then save STDOUT as {SMALL_ATTACHMENT_ID}
And the wp-content/uploads/white-150-square.jpg file should exist
And the wp-content/uploads/white-150-square-150x150.jpg file should not exist
And the wp-content/uploads/white-150-square-300x300.jpg file should not exist
And the wp-content/uploads/white-150-square-1024x1024.jpg file should not exist
When I run `wp media regenerate --yes`
Then STDOUT should contain:
"""
Found 3 images to regenerate.
"""
And STDOUT should contain:
"""
/3 Regenerated thumbnails for "My imported large attachment" (ID {LARGE_ATTACHMENT_ID})
"""
And STDOUT should contain:
"""
/3 Regenerated thumbnails for "My imported medium attachment" (ID {MEDIUM_ATTACHMENT_ID})
"""
And STDOUT should contain:
"""
/3 Regenerated thumbnails for "My imported small attachment" (ID {SMALL_ATTACHMENT_ID})
"""
And STDOUT should contain:
"""
Success: Regenerated 3 of 3 images.
"""
And the wp-content/uploads/large-image.jpg file should exist
And the wp-content/uploads/large-image-150x150.jpg file should exist
And the wp-content/uploads/large-image-300x225.jpg file should exist
And the wp-content/uploads/large-image-1024x768.jpg file should exist
And the wp-content/uploads/canola.jpg file should exist
And the wp-content/uploads/canola-150x150.jpg file should exist
And the wp-content/uploads/canola-300x225.jpg file should exist
And the wp-content/uploads/canola-1024x768.jpg file should not exist
And the wp-content/uploads/white-150-square.jpg file should exist
And the wp-content/uploads/white-150-square-150x150.jpg file should not exist
And the wp-content/uploads/white-150-square-300x300.jpg file should not exist
And the wp-content/uploads/white-150-square-1024x1024.jpg file should not exist
Scenario: Delete existing thumbnails when media is regenerated
Given download:
| path | url |
| {CACHE_DIR}/large-image.jpg | http://wp-cli.org/behat-data/large-image.jpg |
And a wp-content/mu-plugins/media-settings.php file:
"""
"""
And a wp-content/mu-plugins/media-settings.php file:
"""
--force`
Then the return code should be 0
And I run `wp core update-db`
And download:
| path | url |
| {CACHE_DIR}/audio-with-400x300-cover.mp3 | http://wp-cli.org/behat-data/audio-with-400x300-cover.mp3 |
| {CACHE_DIR}/audio-with-no-cover.mp3 | http://wp-cli.org/behat-data/audio-with-no-cover.mp3 |
And a wp-content/mu-plugins/media-settings.php file:
"""
"""
And a wp-content/mu-plugins/media-settings.php file:
"""