Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions features/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,49 @@ Feature: Manage WordPress users
3
"""

Scenario: Delete user with invalid reassign
Given a WP install
And a session_no file:
"""
n
"""
And a session_yes file:
"""
y
"""

When I run `wp user create bobjones bob@example.com --role=author --porcelain`
And save STDOUT as {BOB_ID}

When I run `wp post list --format=count`
And save STDOUT as {TOTAL_POSTS}

When I run `wp post generate --count=3 --format=ids --post_author=bobjones`
And I run `wp post list --author={BOB_ID} --format=count`
Then STDOUT should be:
"""
3
"""

When I run `wp user delete bobjones < session_no`
Then STDOUT should contain:
"""
--reassign parameter not passed. All associated posts will be deleted. Proceed? [y/n]
"""

When I run `wp user delete bobjones --reassign=99999 < session_no`
Then STDOUT should contain:
"""
--reassign parameter is invalid. All associated posts will be deleted. Proceed? [y/n]
"""

When I run `wp user delete bobjones < session_yes`
And I run `wp post list --format=count`
Then STDOUT should be:
"""
{TOTAL_POSTS}
"""

Scenario: Deleting user from the whole network
Given a WP multisite install

Expand Down
4 changes: 4 additions & 0 deletions src/User_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,12 @@ public function delete( $args, $assoc_args ) {
WP_CLI::error( 'Reassigning content to a different user is not supported on multisite.' );
}

$is_reassign_valid = ( $reassign && false === get_userdata( $reassign ) ) ? false : true;

if ( ! $reassign ) {
WP_CLI::confirm( '--reassign parameter not passed. All associated posts will be deleted. Proceed?', $assoc_args );
} elseif ( ! $is_reassign_valid ) {
WP_CLI::confirm( '--reassign parameter is invalid. All associated posts will be deleted. Proceed?', $assoc_args );
}

$users = $this->fetcher->get_many( $args );
Expand Down