-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathmedia-prune.feature
More file actions
175 lines (154 loc) · 6.48 KB
/
media-prune.feature
File metadata and controls
175 lines (154 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
Feature: Prune WordPress attachment thumbnails
Background:
Given a WP install
And I try `wp theme install twentynineteen --activate`
Scenario: Prune all images while none exists
When I try `wp media prune --yes`
Then STDERR should contain:
"""
No images found.
"""
And the return code should be 0
@require-wp-5.3
Scenario: Prune all thumbnails for all images
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 |
And I run `wp option update uploads_use_yearmonth_folders 0`
When I run `wp media import {CACHE_DIR}/large-image.jpg --title="My 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
When I run `wp media import {CACHE_DIR}/canola.jpg --title="My 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
When I run `wp media prune --yes`
Then STDOUT should contain:
"""
Found 2 images to prune.
"""
And STDOUT should contain:
"""
/2 Pruned thumbnails for "My large attachment" (ID {LARGE_ATTACHMENT_ID})
"""
And STDOUT should contain:
"""
/2 Pruned thumbnails for "My medium attachment" (ID {MEDIUM_ATTACHMENT_ID})
"""
And STDOUT should contain:
"""
Success: Pruned 2 of 2 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 not exist
And the wp-content/uploads/large-image-300x225.jpg file should not exist
And the wp-content/uploads/canola.jpg file should exist
And the wp-content/uploads/canola-150x150.jpg file should not exist
And the wp-content/uploads/canola-300x225.jpg file should not exist
And I run `wp post meta get {LARGE_ATTACHMENT_ID} _wp_attachment_metadata --format=json`
Then STDOUT should not contain:
"""
"thumbnail"
"""
And STDOUT should not contain:
"""
"medium"
"""
@require-wp-5.3
Scenario: Prune a specific image size
Given download:
| path | url |
| {CACHE_DIR}/large-image.jpg | http://wp-cli.org/behat-data/large-image.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 large attachment" --porcelain`
Then save STDOUT as {LARGE_ATTACHMENT_ID}
And the wp-content/uploads/large-image-150x150.jpg file should exist
And the wp-content/uploads/large-image-300x225.jpg file should exist
When I run `wp media prune --image_size=thumbnail {LARGE_ATTACHMENT_ID}`
Then STDOUT should contain:
"""
Pruned thumbnails for "My large attachment" (ID {LARGE_ATTACHMENT_ID})
"""
And STDOUT should contain:
"""
Success: Pruned 1 of 1 images.
"""
And the wp-content/uploads/large-image-150x150.jpg file should not exist
And the wp-content/uploads/large-image-300x225.jpg file should exist
@require-wp-5.3
Scenario: Prune does not remove abandoned (unregistered) thumbnails by default
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:
"""
<?php
add_action( 'after_setup_theme', function(){
add_image_size( 'abandoned_size', 200, 200, true );
});
"""
And I run `wp option update uploads_use_yearmonth_folders 0`
When I run `wp media import {CACHE_DIR}/large-image.jpg --title="My large attachment" --porcelain`
Then save STDOUT as {LARGE_ATTACHMENT_ID}
And the wp-content/uploads/large-image-200x200.jpg file should exist
# Remove the custom image size (simulating an abandoned size).
Given a wp-content/mu-plugins/media-settings.php file:
"""
<?php
"""
When I run `wp media prune --yes`
Then STDOUT should contain:
"""
Success: Pruned
"""
And the wp-content/uploads/large-image-200x200.jpg file should exist
And I run `wp post meta get {LARGE_ATTACHMENT_ID} _wp_attachment_metadata --format=json`
Then STDOUT should contain:
"""
"abandoned_size"
"""
@require-wp-5.3
Scenario: Prune removes abandoned thumbnails with --remove-abandoned
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:
"""
<?php
add_action( 'after_setup_theme', function(){
add_image_size( 'abandoned_size', 200, 200, true );
});
"""
And I run `wp option update uploads_use_yearmonth_folders 0`
When I run `wp media import {CACHE_DIR}/large-image.jpg --title="My large attachment" --porcelain`
Then save STDOUT as {LARGE_ATTACHMENT_ID}
And the wp-content/uploads/large-image-200x200.jpg file should exist
# Remove the custom image size (simulating an abandoned size).
Given a wp-content/mu-plugins/media-settings.php file:
"""
<?php
"""
When I run `wp media prune --remove-abandoned --yes`
Then STDOUT should contain:
"""
Success: Pruned
"""
And the wp-content/uploads/large-image-200x200.jpg file should not exist
And I run `wp post meta get {LARGE_ATTACHMENT_ID} _wp_attachment_metadata --format=json`
Then STDOUT should not contain:
"""
"abandoned_size"
"""
Scenario: Error on unknown image size
When I try `wp media prune --image_size=nonexistent --yes`
Then STDERR should contain:
"""
Unknown image size "nonexistent".
"""
And the return code should be 1