set password action on user insert and update#9244
set password action on user insert and update#9244nimesh-xecurify wants to merge 2 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| // Assert initial password action (creation) | ||
| $this->assertSame( 1, $mock_action->get_call_count(), 'wp_set_password was not triggered during user creation.' ); | ||
| $mock_action->reset(); // Reset for update test | ||
|
|
There was a problem hiding this comment.
| // Assert initial password action (creation) | |
| $this->assertSame( 1, $mock_action->get_call_count(), 'wp_set_password was not triggered during user creation.' ); | |
| $mock_action->reset(); // Reset for update test |
I think this is covered by the previous test case.
dream-encode
left a comment
There was a problem hiding this comment.
Minor tweaks, working on a commit now.
| public function test_set_password_action_on_user_update() { | ||
| $mock_action = new MockAction(); | ||
| add_action( 'wp_set_password', array( $mock_action, 'action' ), 10, 3 ); | ||
|
|
||
| // Step 1: Create a user | ||
| $user_id = $this->factory()->user->create( | ||
| array( | ||
| 'role' => 'subscriber', | ||
| 'user_login' => 'testuser_update', | ||
| 'user_email' => 'testuser_update@example.com', | ||
| 'user_pass' => 'initialpassword', | ||
| ) | ||
| ); | ||
|
|
||
| // Assert initial password action (creation) | ||
| $this->assertSame( 1, $mock_action->get_call_count(), 'wp_set_password was not triggered during user creation.' ); | ||
| $mock_action->reset(); // Reset for update test | ||
|
|
||
| // Step 2: Update the password via wp_set_password | ||
| $updated_password = 'newpassword123'; | ||
| wp_set_password( $updated_password, $user_id ); | ||
|
|
||
| // Assert action triggered | ||
| $this->assertSame( 1, $mock_action->get_call_count(), 'wp_set_password was not triggered during password update.' ); | ||
| $args = $mock_action->get_args(); | ||
| $this->assertSame( $updated_password, $args[0][0], 'Invalid password in wp_set_password action.' ); | ||
| $this->assertSame( $user_id, $args[0][1], 'Invalid user ID in wp_set_password action.' ); | ||
| } |
There was a problem hiding this comment.
| public function test_set_password_action_on_user_update() { | |
| $mock_action = new MockAction(); | |
| add_action( 'wp_set_password', array( $mock_action, 'action' ), 10, 3 ); | |
| // Step 1: Create a user | |
| $user_id = $this->factory()->user->create( | |
| array( | |
| 'role' => 'subscriber', | |
| 'user_login' => 'testuser_update', | |
| 'user_email' => 'testuser_update@example.com', | |
| 'user_pass' => 'initialpassword', | |
| ) | |
| ); | |
| // Assert initial password action (creation) | |
| $this->assertSame( 1, $mock_action->get_call_count(), 'wp_set_password was not triggered during user creation.' ); | |
| $mock_action->reset(); // Reset for update test | |
| // Step 2: Update the password via wp_set_password | |
| $updated_password = 'newpassword123'; | |
| wp_set_password( $updated_password, $user_id ); | |
| // Assert action triggered | |
| $this->assertSame( 1, $mock_action->get_call_count(), 'wp_set_password was not triggered during password update.' ); | |
| $args = $mock_action->get_args(); | |
| $this->assertSame( $updated_password, $args[0][0], 'Invalid password in wp_set_password action.' ); | |
| $this->assertSame( $user_id, $args[0][1], 'Invalid user ID in wp_set_password action.' ); | |
| } |
Actually, this whole test is a dupe of Tests_Auth::test_wp_set_password_action()
|
|
||
| // Step 2: Update the user password explicitly via `wp_set_password`. | ||
| $updated_password = 'updatedpassword123'; | ||
| wp_set_password( $updated_password, $user_id ); | ||
|
|
||
| // Assert that `wp_set_password` was triggered once during the password update. | ||
| $this->assertSame( 1, $mock_action->get_call_count(), 'wp_set_password was not triggered during password update.' ); | ||
| $args = $mock_action->get_args(); | ||
| $this->assertSame( $updated_password, $args[0][0], 'Wrong password argument in action when updating user.' ); | ||
| $this->assertSame( $user_id, $args[0][1], 'Wrong user ID in action when updating user.' ); | ||
|
|
||
| $mock_action->reset(); // Reset mock for the final scenario. |
There was a problem hiding this comment.
| // Step 2: Update the user password explicitly via `wp_set_password`. | |
| $updated_password = 'updatedpassword123'; | |
| wp_set_password( $updated_password, $user_id ); | |
| // Assert that `wp_set_password` was triggered once during the password update. | |
| $this->assertSame( 1, $mock_action->get_call_count(), 'wp_set_password was not triggered during password update.' ); | |
| $args = $mock_action->get_args(); | |
| $this->assertSame( $updated_password, $args[0][0], 'Wrong password argument in action when updating user.' ); | |
| $this->assertSame( $user_id, $args[0][1], 'Wrong user ID in action when updating user.' ); | |
| $mock_action->reset(); // Reset mock for the final scenario. |
Same here. Dupe code.
Fires a wp_set_password action whenever a user is created or updated.
Trac ticket: https://core.trac.wordpress.org/ticket/22114