@@ -63,9 +63,36 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
6363 public function set_up () {
6464 parent ::set_up ();
6565
66+ add_action ( 'set_auth_cookie ' , array ( $ this , 'action_set_auth_cookie ' ), 10 , 6 );
67+ add_action ( 'set_logged_in_cookie ' , array ( $ this , 'action_set_logged_in_cookie ' ), 10 );
68+ add_action ( 'clear_auth_cookie ' , array ( $ this , 'action_clear_auth_cookie ' ) );
69+
70+ $ _COOKIE = [];
6671 $ this ->author = clone self ::$ _author ;
6772 }
6873
74+ final public function action_set_auth_cookie (
75+ string $ cookie ,
76+ int $ expire ,
77+ int $ expiration ,
78+ int $ user_id ,
79+ string $ scheme ,
80+ string $ token
81+ ): void {
82+ $ _COOKIE [ SECURE_AUTH_COOKIE ] = $ cookie ;
83+ $ _COOKIE [ AUTH_COOKIE ] = $ cookie ;
84+ }
85+
86+ final public function action_set_logged_in_cookie ( string $ cookie ): void {
87+ $ _COOKIE [ LOGGED_IN_COOKIE ] = $ cookie ;
88+ }
89+
90+ final public function action_clear_auth_cookie (): void {
91+ unset( $ _COOKIE [ LOGGED_IN_COOKIE ] );
92+ unset( $ _COOKIE [ SECURE_AUTH_COOKIE ] );
93+ unset( $ _COOKIE [ AUTH_COOKIE ] );
94+ }
95+
6996 public function test_get_users_of_blog () {
7097 // Add one of each user role.
7198 $ nusers = array (
@@ -1122,6 +1149,42 @@ public function test_changing_password_invalidates_password_reset_key() {
11221149 $ this ->assertEmpty ( $ user ->user_activation_key );
11231150 }
11241151
1152+ /**
1153+ * @ticket 61366
1154+ * @dataProvider data_remember_user
1155+ */
1156+ public function test_changing_own_password_retains_current_session ( bool $ remember ) {
1157+ $ user = $ this ->author ;
1158+ $ manager = WP_Session_Tokens::get_instance ( $ user ->ID );
1159+ $ expiry = $ remember ? ( 2 * WEEK_IN_SECONDS ) : ( 2 * DAY_IN_SECONDS );
1160+ $ token = $ manager ->create ( time () + $ expiry );
1161+ $ pass = $ user ->user_pass ;
1162+
1163+ wp_set_current_user ( $ user ->ID );
1164+ wp_set_auth_cookie ( $ user ->ID , $ remember , '' , $ token );
1165+
1166+ $ userdata = array (
1167+ 'ID ' => $ user ->ID ,
1168+ 'user_pass ' => 'my_new_password ' ,
1169+ );
1170+ $ updated = wp_update_user ( $ userdata , $ manager );
1171+ $ valid = wp_validate_auth_cookie ();
1172+ $ cookie = wp_parse_auth_cookie ();
1173+
1174+ $ this ->assertNotWPError ( $ updated );
1175+ $ this ->assertNotSame ( $ pass , get_userdata ( $ user ->ID )->user_pass );
1176+ $ this ->assertSame ( $ user ->ID , $ valid );
1177+ $ this ->assertSame ( $ token , $ cookie ['token ' ] );
1178+ $ this ->assertCount ( 1 , $ manager ->get_all () );
1179+ }
1180+
1181+ public function data_remember_user () {
1182+ return array (
1183+ array ( true ),
1184+ array ( false ),
1185+ );
1186+ }
1187+
11251188 public function test_search_users_login () {
11261189 $ users = get_users (
11271190 array (
0 commit comments