Ticket #57394: 57394-tests-updated.diff
File 57394-tests-updated.diff, 3.7 KB (added by , 15 months ago) |
---|
-
src/wp-includes/user.php
diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index 8e230708e4..5e9195ed9d 100644
a b function wp_insert_user( $userdata ) { 2124 2124 return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) ); 2125 2125 } 2126 2126 2127 if ( ! $update && username_exists( $user_login ) ) { 2128 return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); 2127 // Check additional restrictions for new users. 2128 if ( ! $update ) { 2129 2130 // Username must be unique. 2131 if ( username_exists( $user_login ) ) { 2132 return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); 2133 } 2134 2135 // Username must not match an existing user email. 2136 if ( email_exists( $user_login ) ) { 2137 return new WP_Error( 'existing_user_email_as_login', __( 'Sorry, that username is not available.' ) ); 2138 } 2129 2139 } 2130 2140 2131 2141 /** … … function register_new_user( $user_login, $user_email ) { 3354 3364 $sanitized_user_login = ''; 3355 3365 } elseif ( username_exists( $sanitized_user_login ) ) { 3356 3366 $errors->add( 'username_exists', __( '<strong>Error:</strong> This username is already registered. Please choose another one.' ) ); 3367 } elseif ( email_exists( $sanitized_user_login ) ) { 3368 $errors->add( 'username_exists_as_email', __( '<strong>Error:</strong> This username is not available. Please choose another one.' ) ); 3357 3369 } else { 3358 3370 /** This filter is documented in wp-includes/user.php */ 3359 3371 $illegal_user_logins = (array) apply_filters( 'illegal_user_logins', array() ); -
tests/phpunit/tests/user.php
diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index 7157a00cfa..7d47acebc2 100644
a b class Tests_User extends WP_UnitTestCase { 915 915 $this->assertSame( 'user_nicename_too_long', $u->get_error_code() ); 916 916 } 917 917 918 919 /** 920 * Tests that `wp_insert_user()` rejects a 'user_login' that matches an existing user email. 921 * 922 * @ticket 57394 923 * 924 * @covers ::wp_insert_user 925 */ 926 public function test_wp_insert_user_should_reject_user_login_that_matches_existing_user_email() { 927 $existing_email = get_option( 'admin_email' ); 928 $user_id = wp_insert_user( 929 array( 930 'user_login' => $existing_email, 931 'user_email' => 'whatever@example.com', 932 'user_pass' => 'whatever', 933 'user_nicename' => 'whatever', 934 ) 935 ); 936 937 $this->assertWPError( $user_id, 'An error should have been returned as the user_login matches an existing email.' ); 938 $this->assertSame( 'existing_user_email_as_login', $user_id->get_error_code(), 'An incorrect error code was returned.' ); 939 } 940 941 /** 942 * Tests that `wp_update_user()` does not reject a 'user_login' that matches an existing user email. 943 * 944 * @ticket 57394 945 * 946 * @covers ::wp_update_user 947 */ 948 public function test_wp_update_user_should_not_reject_user_login_that_matches_existing_user_email() { 949 $new_email = 'new.email@example.com'; 950 $user_id = wp_insert_user( 951 array( 952 'user_login' => $new_email, 953 'user_email' => $new_email, 954 'user_pass' => 'whatever', 955 'user_nicename' => 'whatever', 956 ) 957 ); 958 959 $this->assertNotWPError( $user_id, 'The test user could not be created.' ); 960 961 $user_id = wp_update_user( 962 array( 963 'ID' => $user_id, 964 'user_login' => $new_email, 965 'user_email' => $new_email, 966 'user_nicename' => 'new-nicename', 967 ) 968 ); 969 970 $this->assertNotWPError( $user_id, 'An error should not have been returned.' ); 971 $this->assertSame( 972 'new-nicename', 973 get_userdata( $user_id )->user_nicename, 974 'The user_nicename should have been updated.' 975 ); 976 } 977 918 978 /** 919 979 * @ticket 33793 920 980 */