@@ -984,6 +984,97 @@ Feature: Regenerate WordPress attachments
984984 """
985985 And the return code should be 1
986986
987+ Scenario : Provide error message when one of the multiple image sizes is non-existent
988+ When I try `wp media regenerate --image_size=medium --image_size=test1`
989+ Then STDERR should be:
990+ """
991+ Error: Unknown image size "test1".
992+ """
993+ And the return code should be 1
994+
995+ Scenario : Regenerate multiple specific image sizes
996+ Given download:
997+ | path | url |
998+ | {CACHE_DIR }/canola .jpg | http ://wp -cli .org /behat -data /canola .jpg |
999+ And a wp-content/mu-plugins/media-settings.php file:
1000+ """
1001+ <?php
1002+ add_action( 'after_setup_theme', function(){
1003+ add_image_size( 'too_big', 4000, 4000, true );
1004+ });
1005+ """
1006+ And I run `wp option update uploads_use_yearmonth_folders 0`
1007+
1008+ # Import without "test1" and "test2" image sizes.
1009+ When I run `wp media import {CACHE_DIR}/canola.jpg --title="My imported attachment" --porcelain`
1010+ And save STDOUT as {ATTACHMENT_ID}
1011+ Then the wp-content/uploads/canola-300x225.jpg file should exist
1012+ And the wp-content/uploads/canola-400x400.jpg file should not exist
1013+ And the wp-content/uploads/canola-350x350.jpg file should not exist
1014+
1015+ # Add "test1" and "test2" image sizes.
1016+ Given a wp-content/mu-plugins/media-settings.php file:
1017+ """
1018+ <?php
1019+ add_action( 'after_setup_theme', function(){
1020+ add_image_size( 'test1', 400, 400, true );
1021+ add_image_size( 'test2', 350, 350, true );
1022+ add_image_size( 'too_big', 4000, 4000, true );
1023+ });
1024+ """
1025+
1026+ # Regenerate both "test1" and "test2" sizes only if missing - both should be generated.
1027+ When I run `wp media regenerate --image_size=test1 --image_size=test2 --only-missing --yes`
1028+ Then STDOUT should contain:
1029+ """
1030+ Found 1 image to regenerate
1031+ """
1032+ And STDOUT should contain:
1033+ """
1034+ 1/1 Regenerated "test1", "test2" thumbnails for "My imported attachment"
1035+ """
1036+ And STDOUT should contain:
1037+ """
1038+ Success: Regenerated 1 of 1 images.
1039+ """
1040+ And the wp-content/uploads/canola-400x400.jpg file should exist
1041+ And the wp-content/uploads/canola-350x350.jpg file should exist
1042+ And the wp-content/uploads/canola-300x225.jpg file should exist
1043+
1044+ # Check metadata contains both new sizes.
1045+ When I run `wp post meta get {ATTACHMENT_ID} _wp_attachment_metadata --format=json | grep -o '"test1":{[^}]*"file":"canola-400x400.jpg"' `
1046+ Then STDOUT should contain:
1047+ """
1048+ "file":"canola-400x400.jpg"
1049+ """
1050+ When I run `wp post meta get {ATTACHMENT_ID} _wp_attachment_metadata --format=json | grep -o '"test2":{[^}]*"file":"canola-350x350.jpg"' `
1051+ Then STDOUT should contain:
1052+ """
1053+ "file":"canola-350x350.jpg"
1054+ """
1055+
1056+ # Check other sizes metadata is still present.
1057+ When I run `wp post meta get {ATTACHMENT_ID} _wp_attachment_metadata`
1058+ Then STDOUT should contain:
1059+ """
1060+ 'medium'
1061+ """
1062+ And STDOUT should contain:
1063+ """
1064+ 'thumbnail'
1065+ """
1066+
1067+ # Run again for already-generated sizes - nothing should happen.
1068+ When I run `wp media regenerate --image_size=test1 --image_size=test2 --only-missing --yes`
1069+ Then STDOUT should contain:
1070+ """
1071+ 1/1 No "test1", "test2" thumbnails regeneration needed for "My imported attachment"
1072+ """
1073+ And STDOUT should contain:
1074+ """
1075+ Success: Regenerated 1 of 1 images.
1076+ """
1077+
9871078 Scenario : Regenerating SVGs should be marked as skipped and not produce PHP notices
9881079 Given an svg.svg file:
9891080 """
0 commit comments