| 918 | /** |
| 919 | * Tests that `wp_update_user()` allows updating a user when |
| 920 | * the `user_login` and `user_email` are the same. |
| 921 | * |
| 922 | * @ticket 57967 |
| 923 | * |
| 924 | * @covers ::wp_update_user |
| 925 | */ |
| 926 | public function test_wp_update_user_should_allow_user_login_with_same_user_email() { |
| 927 | $user_email = 'ababa@example.com'; |
| 928 | |
| 929 | $user_id = wp_insert_user( |
| 930 | array( |
| 931 | 'user_login' => $user_email, |
| 932 | 'user_email' => $user_email, |
| 933 | 'user_pass' => 'whatever', |
| 934 | 'user_nicename' => 'whatever', |
| 935 | ) |
| 936 | ); |
| 937 | |
| 938 | $existing_id = wp_update_user( |
| 939 | array( |
| 940 | 'ID' => $user_id, |
| 941 | 'first_name' => 'Bob', |
| 942 | ) |
| 943 | ); |
| 944 | |
| 945 | $this->assertNotWPError( $existing_id, 'A WP_Error object was not returned.' ); |
| 946 | $this->assertSame( $existing_id, $user_id, 'The user ID to be updated and the existing user ID do not match.' ); |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | * Tests that `wp_update_user()` rejects a `user_login` that matches an existing `user_email`. |
| 951 | * |
| 952 | * @ticket 57967 |
| 953 | * |
| 954 | * @covers ::wp_update_user |
| 955 | */ |
| 956 | public function test_wp_update_user_should_reject_user_login_that_matches_existing_user_email() { |
| 957 | $user_email_a = 'aaaaa@example.com'; |
| 958 | |
| 959 | $user_id_a = wp_insert_user( |
| 960 | array( |
| 961 | 'user_login' => $user_email_a, |
| 962 | 'user_email' => $user_email_a, |
| 963 | 'user_pass' => 'whatever', |
| 964 | 'user_nicename' => 'whatever', |
| 965 | ) |
| 966 | ); |
| 967 | |
| 968 | $user_email_b = 'bbbbb@example.com'; |
| 969 | |
| 970 | $user_id_b = wp_insert_user( |
| 971 | array( |
| 972 | 'user_login' => $user_email_b, |
| 973 | 'user_email' => $user_email_b, |
| 974 | 'user_pass' => 'whatever', |
| 975 | 'user_nicename' => 'whatever', |
| 976 | ) |
| 977 | ); |
| 978 | |
| 979 | $existing_id_b = wp_update_user( |
| 980 | array( |
| 981 | 'ID' => $user_id_b, |
| 982 | 'user_login' => $user_email_a, |
| 983 | ) |
| 984 | ); |
| 985 | |
| 986 | $this->assertWPError( $existing_id_b, 'A WP_Error object was not returned.' ); |
| 987 | $this->assertSame( 'existing_user_email_as_login', $existing_id_b->get_error_code(), 'An unexpected error code was returned.' ); |
| 988 | } |
| 989 | |