WordPress.org

Make WordPress Core

Ticket #42766: 42766.3.diff

File 42766.3.diff, 1.8 KB (added by oolleegg55, 4 years ago)

Add unit test

  • src/wp-admin/includes/user.php

    diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php
    index 269d64fb26..30f29a42ba 100644
    a b function edit_user( $user_id = 0 ) { 
    4545
    4646        $pass1 = $pass2 = '';
    4747        if ( isset( $_POST['pass1'] ) ) {
    48                 $pass1 = $_POST['pass1'];
     48                $pass1 = trim( $_POST['pass1'] );
    4949        }
    5050        if ( isset( $_POST['pass2'] ) ) {
    51                 $pass2 = $_POST['pass2'];
     51                $pass2 = trim( $_POST['pass2'] );
    5252        }
    5353
    5454        if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) {
  • tests/phpunit/tests/user.php

    diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php
    index bcfa036d37..e6c7c5ccb6 100644
    a b class Tests_User extends WP_UnitTestCase { 
    13621362         * Checks that calling edit_user() with no password returns an error when adding, and doesn't when updating.
    13631363         *
    13641364         * @ticket 35715
     1365         * @ticket 42766
    13651366         */
    13661367        function test_edit_user_blank_pw() {
    13671368                $_POST                 = $_GET = $_REQUEST = array();
    class Tests_User extends WP_UnitTestCase { 
    13981399                $this->assertInternalType( 'int', $user_id );
    13991400                $this->assertEquals( 'nickname_updated', $user->nickname );
    14001401
     1402                // Check not to change an old password if a new password contains only spaces. Ticket #42766
     1403                $user           = get_user_by( 'ID', $user_id );
     1404                $old_pass       = $user->user_pass;
     1405                $_POST['pass1'] = $_POST['pass2'] = '  ';
     1406
     1407                $user_id = edit_user( $user_id );
     1408                $user    = get_user_by( 'ID', $user_id );
     1409
     1410                $this->assertInternalType( 'int', $user_id );
     1411                $this->assertEquals( $old_pass, $user->user_pass );
     1412
    14011413                // Check updating user with missing second password.
    14021414                $_POST['nickname'] = 'nickname_updated2';
    14031415                $_POST['pass1']    = 'blank_pass2';