Skip to content

Commit ce82686

Browse files
authored
Report failure on post term remove when no term was removed (#693)
1 parent cc8531a commit ce82686

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎features/post-term.feature‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,27 @@ Feature: Manage post term
201201
| term_id | name | slug |
202202
| 3 | 4 | 4 |
203203

204+
Scenario: Remove a term that is not assigned to the post
205+
Given a WP install
206+
207+
When I run `wp post term add 1 post_tag apple`
208+
And I run `wp term create post_tag banana`
209+
Then STDOUT should not be empty
210+
211+
When I try `wp post term remove 1 post_tag banana`
212+
Then STDERR should be:
213+
"""
214+
Error: Failed to remove term.
215+
"""
216+
And STDOUT should be empty
217+
And the return code should be 1
218+
219+
When I run `wp post term list 1 post_tag --field=slug`
220+
Then STDOUT should be:
221+
"""
222+
apple
223+
"""
224+
204225
Scenario: Remove all terms from post
205226
Given a WP install
206227

‎src/WP_CLI/CommandWithTerms.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function remove( $args, $assoc_args ) {
211211

212212
$label = count( $terms ) > 1 ? 'terms' : 'term';
213213

214-
if ( is_wp_error( $result ) ) {
214+
if ( ! $result || is_wp_error( $result ) ) {
215215
WP_CLI::error( "Failed to remove {$label}." );
216216
}
217217

0 commit comments

Comments
 (0)