Make WordPress Core

Changeset 33115


Ignore:
Timestamp:
07/07/2015 07:28:46 PM (9 years ago)
Author:
wonderboymusic
Message:

In wp_insert_user(), comparing an email address against the user's old email address should not be case-sensitive.

Adds unit tests.

Props tyxla.
Fixes #32158.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r33023 r33115  
    19461946     * accordingly.
    19471947     */
    1948     if ( ( ! $update || ( ! empty( $old_user_data ) && $user_email !== $old_user_data->user_email ) )
     1948    if ( ( ! $update || ( ! empty( $old_user_data ) && 0 !== strcasecmp( $user_email, $old_user_data->user_email ) ) )
    19491949        && ! defined( 'WP_IMPORTING' )
    19501950        && email_exists( $user_email )
  • trunk/tests/phpunit/tests/user.php

    r32980 r33115  
    757757        $this->assertTrue( in_array( $id, $users ) );
    758758    }
     759
     760    /**
     761     * @ticket 32158
     762     */
     763    function test_email_case() {
     764        // Create a test user with a lower-case email address.
     765        $user_id = $this->factory->user->create( array(
     766            'user_email' => 'test@test.com',
     767        ) );
     768
     769        // Alter the case of the email address (which stays the same).
     770        $userdata = array(
     771            'ID' => $user_id,
     772            'user_email' => 'test@TEST.com',
     773        );
     774        $update = wp_update_user( $userdata );
     775
     776        $this->assertEquals( $user_id, $update );
     777    }
     778
     779    /**
     780     * @ticket 32158
     781     */
     782    function test_email_change() {
     783        // Create a test user.
     784        $user_id = $this->factory->user->create( array(
     785            'user_email' => 'test@test.com',
     786        ) );
     787
     788        // Change the email address.
     789        $userdata = array(
     790            'ID' => $user_id,
     791            'user_email' => 'test2@test.com',
     792        );
     793        $update = wp_update_user( $userdata );
     794
     795        // Was this successful?
     796        $this->assertEquals( $user_id, $update );
     797
     798        // Verify that the email address has been updated.
     799        $user = get_userdata( $user_id );
     800        $this->assertEquals( $user->user_email, 'test2@test.com' );
     801    }
     802
    759803}
Note: See TracChangeset for help on using the changeset viewer.