Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r48402 r48937  
    169169        $response = rest_get_server()->dispatch( $request );
    170170        $data     = $response->get_data();
    171         $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    172         $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     171        $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
     172        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    173173        // Single.
    174174        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/' . self::$user );
    175175        $response = rest_get_server()->dispatch( $request );
    176176        $data     = $response->get_data();
    177         $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    178         $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     177        $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
     178        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    179179    }
    180180
     
    185185        $keys     = array_keys( $data['endpoints'][0]['args'] );
    186186        sort( $keys );
    187         $this->assertEquals(
     187        $this->assertSame(
    188188            array(
    189189                'context',
     
    211211        $response = rest_get_server()->dispatch( $request );
    212212
    213         $this->assertEquals( 200, $response->get_status() );
     213        $this->assertSame( 200, $response->get_status() );
    214214
    215215        $all_data = $response->get_data();
     
    226226        $response = rest_get_server()->dispatch( $request );
    227227
    228         $this->assertEquals( 200, $response->get_status() );
     228        $this->assertSame( 200, $response->get_status() );
    229229
    230230        $all_data = $response->get_data();
     
    240240        $response = rest_get_server()->dispatch( $request );
    241241
    242         $this->assertEquals( 401, $response->get_status() );
     242        $this->assertSame( 401, $response->get_status() );
    243243
    244244        // Test with a user logged in but without sufficient capabilities;
     
    250250        $response = rest_get_server()->dispatch( $request );
    251251
    252         $this->assertEquals( 403, $response->get_status() );
     252        $this->assertSame( 403, $response->get_status() );
    253253    }
    254254
     
    314314        $response = rest_get_server()->dispatch( $request );
    315315        $headers  = $response->get_headers();
    316         $this->assertEquals( $total_users, $headers['X-WP-Total'] );
    317         $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
     316        $this->assertSame( $total_users, $headers['X-WP-Total'] );
     317        $this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
    318318        $next_link = add_query_arg(
    319319            array(
     
    333333        $response = rest_get_server()->dispatch( $request );
    334334        $headers  = $response->get_headers();
    335         $this->assertEquals( $total_users, $headers['X-WP-Total'] );
    336         $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
     335        $this->assertSame( $total_users, $headers['X-WP-Total'] );
     336        $this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
    337337        $prev_link = add_query_arg(
    338338            array(
     
    355355        $response = rest_get_server()->dispatch( $request );
    356356        $headers  = $response->get_headers();
    357         $this->assertEquals( $total_users, $headers['X-WP-Total'] );
    358         $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
     357        $this->assertSame( $total_users, $headers['X-WP-Total'] );
     358        $this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
    359359        $prev_link = add_query_arg(
    360360            array(
     
    371371        $response = rest_get_server()->dispatch( $request );
    372372        $headers  = $response->get_headers();
    373         $this->assertEquals( $total_users, $headers['X-WP-Total'] );
    374         $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
     373        $this->assertSame( $total_users, $headers['X-WP-Total'] );
     374        $this->assertSame( $total_pages, $headers['X-WP-TotalPages'] );
    375375        $prev_link = add_query_arg(
    376376            array(
     
    388388        $request  = new WP_REST_Request( 'GET', '/wp/v2/users' );
    389389        $response = rest_get_server()->dispatch( $request );
    390         $this->assertEquals( 10, count( $response->get_data() ) );
     390        $this->assertSame( 10, count( $response->get_data() ) );
    391391
    392392        $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    393393        $request->set_param( 'per_page', 5 );
    394394        $response = rest_get_server()->dispatch( $request );
    395         $this->assertEquals( 5, count( $response->get_data() ) );
     395        $this->assertSame( 5, count( $response->get_data() ) );
    396396    }
    397397
     
    403403        $request->set_param( 'page', 2 );
    404404        $response = rest_get_server()->dispatch( $request );
    405         $this->assertEquals( 5, count( $response->get_data() ) );
     405        $this->assertSame( 5, count( $response->get_data() ) );
    406406        $prev_link = add_query_arg(
    407407            array(
     
    428428        $response = rest_get_server()->dispatch( $request );
    429429        $data     = $response->get_data();
    430         $this->assertEquals( $high_id, $data[0]['id'] );
     430        $this->assertSame( $high_id, $data[0]['id'] );
    431431
    432432        $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
     
    436436        $response = rest_get_server()->dispatch( $request );
    437437        $data     = $response->get_data();
    438         $this->assertEquals( $low_id, $data[0]['id'] );
     438        $this->assertSame( $low_id, $data[0]['id'] );
    439439    }
    440440
     
    452452        $response = rest_get_server()->dispatch( $request );
    453453        $data     = $response->get_data();
    454         $this->assertEquals( $high_id, $data[0]['id'] );
     454        $this->assertSame( $high_id, $data[0]['id'] );
    455455
    456456        $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
     
    461461        $response = rest_get_server()->dispatch( $request );
    462462        $data     = $response->get_data();
    463         $this->assertEquals( $low_id, $data[0]['id'] );
     463        $this->assertSame( $low_id, $data[0]['id'] );
    464464    }
    465465
     
    477477        $response = rest_get_server()->dispatch( $request );
    478478        $data     = $response->get_data();
    479         $this->assertEquals( $high_id, $data[0]['id'] );
     479        $this->assertSame( $high_id, $data[0]['id'] );
    480480
    481481        $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
     
    486486        $response = rest_get_server()->dispatch( $request );
    487487        $data     = $response->get_data();
    488         $this->assertEquals( $low_id, $data[0]['id'] );
     488        $this->assertSame( $low_id, $data[0]['id'] );
    489489    }
    490490
     
    502502        $data     = $response->get_data();
    503503
    504         $this->assertEquals( 'taco', $data[0]['slug'] );
    505         $this->assertEquals( 'burrito', $data[1]['slug'] );
    506         $this->assertEquals( 'chalupa', $data[2]['slug'] );
     504        $this->assertSame( 'taco', $data[0]['slug'] );
     505        $this->assertSame( 'burrito', $data[1]['slug'] );
     506        $this->assertSame( 'chalupa', $data[2]['slug'] );
    507507    }
    508508
     
    520520        $response = rest_get_server()->dispatch( $request );
    521521        $data     = $response->get_data();
    522         $this->assertEquals( $high_id, $data[0]['id'] );
     522        $this->assertSame( $high_id, $data[0]['id'] );
    523523
    524524        $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
     
    529529        $response = rest_get_server()->dispatch( $request );
    530530        $data     = $response->get_data();
    531         $this->assertEquals( $low_id, $data[0]['id'] );
     531        $this->assertSame( $low_id, $data[0]['id'] );
    532532    }
    533533
     
    599599        $response = rest_get_server()->dispatch( $request );
    600600        $data     = $response->get_data();
    601         $this->assertEquals( 2, count( $data ) );
    602         $this->assertEquals( $id1, $data[0]['id'] );
     601        $this->assertSame( 2, count( $data ) );
     602        $this->assertSame( $id1, $data[0]['id'] );
    603603
    604604        // 'orderby' => 'include'.
     
    606606        $response = rest_get_server()->dispatch( $request );
    607607        $data     = $response->get_data();
    608         $this->assertEquals( 2, count( $data ) );
    609         $this->assertEquals( $id2, $data[0]['id'] );
     608        $this->assertSame( 2, count( $data ) );
     609        $this->assertSame( $id2, $data[0]['id'] );
    610610
    611611        // Invalid 'include' should error.
     
    619619        $response = rest_get_server()->dispatch( $request );
    620620        $data     = $response->get_data();
    621         $this->assertEquals( 0, count( $data ) );
     621        $this->assertSame( 0, count( $data ) );
    622622
    623623    }
     
    656656        $request->set_param( 'search', 'yololololo' );
    657657        $response = rest_get_server()->dispatch( $request );
    658         $this->assertEquals( 0, count( $response->get_data() ) );
     658        $this->assertSame( 0, count( $response->get_data() ) );
    659659
    660660        $yolo_id = $this->factory->user->create( array( 'display_name' => 'yololololo' ) );
     
    663663        $request->set_param( 'search', 'yololololo' );
    664664        $response = rest_get_server()->dispatch( $request );
    665         $this->assertEquals( 1, count( $response->get_data() ) );
     665        $this->assertSame( 1, count( $response->get_data() ) );
    666666        // Default to wildcard search.
    667667        $adam_id = $this->factory->user->create(
     
    676676        $response = rest_get_server()->dispatch( $request );
    677677        $data     = $response->get_data();
    678         $this->assertEquals( 1, count( $data ) );
    679         $this->assertEquals( $adam_id, $data[0]['id'] );
     678        $this->assertSame( 1, count( $data ) );
     679        $this->assertSame( $adam_id, $data[0]['id'] );
    680680    }
    681681
     
    700700        $response = rest_get_server()->dispatch( $request );
    701701        $data     = $response->get_data();
    702         $this->assertEquals( 1, count( $data ) );
    703         $this->assertEquals( $id2, $data[0]['id'] );
     702        $this->assertSame( 1, count( $data ) );
     703        $this->assertSame( $id2, $data[0]['id'] );
    704704    }
    705705
     
    744744        $request->set_param( 'order', 'asc' );
    745745        $response = rest_get_server()->dispatch( $request );
    746         $this->assertEquals( 200, $response->get_status() );
     746        $this->assertSame( 200, $response->get_status() );
    747747        $data  = $response->get_data();
    748748        $slugs = wp_list_pluck( $data, 'slug' );
    749         $this->assertEquals( array( 'burrito', 'enchilada', 'taco' ), $slugs );
     749        $this->assertSame( array( 'burrito', 'enchilada', 'taco' ), $slugs );
    750750    }
    751751
     
    783783        $request->set_param( 'order', 'desc' );
    784784        $response = rest_get_server()->dispatch( $request );
    785         $this->assertEquals( 200, $response->get_status() );
     785        $this->assertSame( 200, $response->get_status() );
    786786        $data  = $response->get_data();
    787787        $slugs = wp_list_pluck( $data, 'slug' );
    788         $this->assertEquals( array( 'taco', 'enchilada', 'burrito' ), $slugs );
     788        $this->assertSame( array( 'taco', 'enchilada', 'burrito' ), $slugs );
    789789    }
    790790
     
    813813        $response = rest_get_server()->dispatch( $request );
    814814        $data     = $response->get_data();
    815         $this->assertEquals( 3, count( $data ) );
    816         $this->assertEquals( $tango, $data[1]['id'] );
    817         $this->assertEquals( $yolo, $data[2]['id'] );
     815        $this->assertSame( 3, count( $data ) );
     816        $this->assertSame( $tango, $data[1]['id'] );
     817        $this->assertSame( $yolo, $data[2]['id'] );
    818818
    819819        $request->set_param( 'roles', 'author' );
    820820        $response = rest_get_server()->dispatch( $request );
    821821        $data     = $response->get_data();
    822         $this->assertEquals( 1, count( $data ) );
    823         $this->assertEquals( $yolo, $data[0]['id'] );
     822        $this->assertSame( 1, count( $data ) );
     823        $this->assertSame( $yolo, $data[0]['id'] );
    824824
    825825        wp_set_current_user( 0 );
     
    850850        $response = rest_get_server()->dispatch( $request );
    851851        $data     = $response->get_data();
    852         $this->assertEquals( 1, count( $data ) );
    853         $this->assertEquals( $lolz, $data[0]['id'] );
     852        $this->assertSame( 1, count( $data ) );
     853        $this->assertSame( $lolz, $data[0]['id'] );
    854854
    855855        $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
     
    857857        $response = rest_get_server()->dispatch( $request );
    858858        $data     = $response->get_data();
    859         $this->assertEquals( 0, count( $data ) );
    860         $this->assertEquals( array(), $data );
     859        $this->assertSame( 0, count( $data ) );
     860        $this->assertSame( array(), $data );
    861861    }
    862862
     
    868868        $request->set_param( 'search', 'subscriber' );
    869869        $response = rest_get_server()->dispatch( $request );
    870         $this->assertEquals( 200, $response->get_status() );
     870        $this->assertSame( 200, $response->get_status() );
    871871        $this->assertCount( 1, $response->get_data() );
    872872
     
    876876        $request->set_param( 'search', 'subscriber' );
    877877        $response = rest_get_server()->dispatch( $request );
    878         $this->assertEquals( 200, $response->get_status() );
     878        $this->assertSame( 200, $response->get_status() );
    879879        $this->assertCount( 0, $response->get_data() );
    880880    }
     
    930930        $user     = get_user_by( 'id', get_current_user_id() );
    931931        $response = $this->endpoint->prepare_item_for_response( $user, $request );
    932         $this->assertEquals(
     932        $this->assertSame(
    933933            array(
    934934                'id',
     
    953953        // Ignore the subdomain, since get_avatar_url() randomly sets
    954954        // the Gravatar server when building the URL string.
    955         $this->assertEquals( substr( get_avatar_url( $user->user_email ), 9 ), substr( $data['avatar_urls'][96], 9 ) );
     955        $this->assertSame( substr( get_avatar_url( $user->user_email ), 9 ), substr( $data['avatar_urls'][96], 9 ) );
    956956    }
    957957
     
    10051005        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) );
    10061006        $response = rest_get_server()->dispatch( $request );
    1007         $this->assertEquals( 200, $response->get_status() );
     1007        $this->assertSame( 200, $response->get_status() );
    10081008    }
    10091009
     
    10131013        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_true'] ) );
    10141014        $response = rest_get_server()->dispatch( $request );
    1015         $this->assertEquals( 200, $response->get_status() );
     1015        $this->assertSame( 200, $response->get_status() );
    10161016    }
    10171017
     
    10191019        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$authors['r_true_p_false'] ) );
    10201020        $response = rest_get_server()->dispatch( $request );
    1021         $this->assertEquals( 200, $response->get_status() );
     1021        $this->assertSame( 200, $response->get_status() );
    10221022    }
    10231023
     
    10451045        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', self::$editor ) );
    10461046        $response = rest_get_server()->dispatch( $request );
    1047         $this->assertEquals( 200, $response->get_status() );
     1047        $this->assertSame( 200, $response->get_status() );
    10481048    }
    10491049
     
    10851085        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) );
    10861086        $response = rest_get_server()->dispatch( $request );
    1087         $this->assertEquals( 401, $response->get_status() );
     1087        $this->assertSame( 401, $response->get_status() );
    10881088
    10891089        $this->post_id = $this->factory->post->create(
     
    11351135        $request  = new WP_REST_Request( 'GET', '/wp/v2/users/me' );
    11361136        $response = rest_get_server()->dispatch( $request );
    1137         $this->assertEquals( 200, $response->get_status() );
     1137        $this->assertSame( 200, $response->get_status() );
    11381138        $this->check_get_user_response( $response, 'view' );
    11391139
     
    11421142
    11431143        $links = $response->get_links();
    1144         $this->assertEquals( rest_url( 'wp/v2/users/' . self::$user ), $links['self'][0]['href'] );
     1144        $this->assertSame( rest_url( 'wp/v2/users/' . self::$user ), $links['self'][0]['href'] );
    11451145    }
    11461146
     
    11761176
    11771177        $data = $response->get_data();
    1178         $this->assertEquals( 'http://example.com', $data['url'] );
    1179         $this->assertEquals( array( 'editor' ), $data['roles'] );
     1178        $this->assertSame( 'http://example.com', $data['url'] );
     1179        $this->assertSame( array( 'editor' ), $data['roles'] );
    11801180        $this->check_add_edit_user_response( $response );
    11811181    }
     
    12151215            $this->assertCount( 1, $data['additional_errors'] );
    12161216            $error = $data['additional_errors'][0];
    1217             $this->assertEquals( 'user_name', $error['code'] );
    1218             $this->assertEquals( 'Usernames can only contain lowercase letters (a-z) and numbers.', $error['message'] );
     1217            $this->assertSame( 'user_name', $error['code'] );
     1218            $this->assertSame( 'Usernames can only contain lowercase letters (a-z) and numbers.', $error['message'] );
    12191219        } else {
    12201220            $this->assertInternalType( 'array', $data['data']['params'] );
    12211221            $errors = $data['data']['params'];
    12221222            $this->assertInternalType( 'string', $errors['username'] );
    1223             $this->assertEquals( 'This username is invalid because it uses illegal characters. Please enter a valid username.', $errors['username'] );
     1223            $this->assertSame( 'This username is invalid because it uses illegal characters. Please enter a valid username.', $errors['username'] );
    12241224        }
    12251225    }
     
    12611261        $errors = $data['data']['params'];
    12621262        $this->assertInternalType( 'string', $errors['username'] );
    1263         $this->assertEquals( 'Sorry, that username is not allowed.', $errors['username'] );
     1263        $this->assertSame( 'Sorry, that username is not allowed.', $errors['username'] );
    12641264    }
    12651265
     
    13891389            $this->assertContains( $error['code'], array( 'user_name', 'user_email' ) );
    13901390            if ( 'user_name' === $error['code'] ) {
    1391                 $this->assertEquals( 'Sorry, that username already exists!', $error['message'] );
     1391                $this->assertSame( 'Sorry, that username already exists!', $error['message'] );
    13921392            } else {
    1393                 $this->assertEquals( 'Sorry, that email address is already used!', $error['message'] );
     1393                $this->assertSame( 'Sorry, that email address is already used!', $error['message'] );
    13941394            }
    13951395        }
     
    15251525        // Check that the name has been updated correctly.
    15261526        $new_data = $response->get_data();
    1527         $this->assertEquals( 'New Name', $new_data['first_name'] );
     1527        $this->assertSame( 'New Name', $new_data['first_name'] );
    15281528        $user = get_userdata( $user_id );
    1529         $this->assertEquals( 'New Name', $user->first_name );
    1530 
    1531         $this->assertEquals( 'http://google.com', $new_data['url'] );
    1532         $this->assertEquals( 'http://google.com', $user->user_url );
    1533         $this->assertEquals( 'de_DE', $user->locale );
     1529        $this->assertSame( 'New Name', $user->first_name );
     1530
     1531        $this->assertSame( 'http://google.com', $new_data['url'] );
     1532        $this->assertSame( 'http://google.com', $user->user_url );
     1533        $this->assertSame( 'de_DE', $user->locale );
    15341534
    15351535        // Check that we haven't inadvertently changed the user's password,
    15361536        // as per https://core.trac.wordpress.org/ticket/21429
    1537         $this->assertEquals( $pw_before, $user->user_pass );
     1537        $this->assertSame( $pw_before, $user->user_pass );
    15381538    }
    15391539
     
    15511551        // even if no DB rows are updated.
    15521552        $response = rest_get_server()->dispatch( $request );
    1553         $this->assertEquals( 200, $response->get_status() );
    1554 
    1555         $response = rest_get_server()->dispatch( $request );
    1556         $this->assertEquals( 200, $response->get_status() );
     1553        $this->assertSame( 200, $response->get_status() );
     1554
     1555        $response = rest_get_server()->dispatch( $request );
     1556        $this->assertSame( 200, $response->get_status() );
    15571557    }
    15581558
     
    15791579        $response = rest_get_server()->dispatch( $request );
    15801580        $this->assertInstanceOf( 'WP_Error', $response->as_error() );
    1581         $this->assertEquals( 'rest_user_invalid_email', $response->as_error()->get_error_code() );
     1581        $this->assertSame( 'rest_user_invalid_email', $response->as_error()->get_error_code() );
    15821582    }
    15831583
     
    15971597        $data     = $response->get_data();
    15981598
    1599         $this->assertEquals( 200, $response->get_status() );
    1600         $this->assertEquals( $updated_email_with_case_change, $data['email'] );
     1599        $this->assertSame( 200, $response->get_status() );
     1600        $this->assertSame( $updated_email_with_case_change, $data['email'] );
    16011601    }
    16021602
     
    16171617        $data     = $response->get_data();
    16181618
    1619         $this->assertEquals( 400, $response->get_status() );
     1619        $this->assertSame( 400, $response->get_status() );
    16201620        $this->assertSame( 'rest_user_invalid_email', $data['code'] );
    16211621    }
     
    16371637        $response = rest_get_server()->dispatch( $request );
    16381638        $this->assertInstanceOf( 'WP_Error', $response->as_error() );
    1639         $this->assertEquals( 'rest_invalid_param', $response->as_error()->get_error_code() );
     1639        $this->assertSame( 'rest_invalid_param', $response->as_error()->get_error_code() );
    16401640    }
    16411641
     
    16581658
    16591659        $user = get_userdata( $user_id );
    1660         $this->assertEquals( 'en_US', $user->locale );
     1660        $this->assertSame( 'en_US', $user->locale );
    16611661    }
    16621662
     
    16831683
    16841684        $data = $response->get_data();
    1685         $this->assertEquals( get_locale(), $data['locale'] );
     1685        $this->assertSame( get_locale(), $data['locale'] );
    16861686        $user = get_userdata( $user_id );
    1687         $this->assertEquals( '', $user->locale );
     1687        $this->assertSame( '', $user->locale );
    16881688    }
    16891689
     
    17101710        $response = rest_get_server()->dispatch( $request );
    17111711        $this->assertInstanceOf( 'WP_Error', $response->as_error() );
    1712         $this->assertEquals( 'rest_user_invalid_argument', $response->as_error()->get_error_code() );
     1712        $this->assertSame( 'rest_user_invalid_argument', $response->as_error()->get_error_code() );
    17131713    }
    17141714
     
    17351735        $response = rest_get_server()->dispatch( $request );
    17361736        $this->assertInstanceOf( 'WP_Error', $response->as_error() );
    1737         $this->assertEquals( 'rest_user_invalid_slug', $response->as_error()->get_error_code() );
     1737        $this->assertSame( 'rest_user_invalid_slug', $response->as_error()->get_error_code() );
    17381738    }
    17391739
     
    17721772        // Check that the name has been updated correctly.
    17731773        $new_data = $response->get_data();
    1774         $this->assertEquals( 'JSON Name', $new_data['first_name'] );
    1775         $this->assertEquals( 'New Last', $new_data['last_name'] );
     1774        $this->assertSame( 'JSON Name', $new_data['first_name'] );
     1775        $this->assertSame( 'New Last', $new_data['last_name'] );
    17761776        $user = get_userdata( $user_id );
    1777         $this->assertEquals( 'JSON Name', $user->first_name );
    1778         $this->assertEquals( 'New Last', $user->last_name );
     1777        $this->assertSame( 'JSON Name', $user->first_name );
     1778        $this->assertSame( 'New Last', $user->last_name );
    17791779
    17801780        // Check that we haven't inadvertently changed the user's password,
    17811781        // as per https://core.trac.wordpress.org/ticket/21429
    1782         $this->assertEquals( $pw_before, $user->user_pass );
     1782        $this->assertSame( $pw_before, $user->user_pass );
    17831783    }
    17841784
     
    17961796        $new_data = $response->get_data();
    17971797
    1798         $this->assertEquals( 'editor', $new_data['roles'][0] );
     1798        $this->assertSame( 'editor', $new_data['roles'][0] );
    17991799        $this->assertNotEquals( 'administrator', $new_data['roles'][0] );
    18001800
     
    18171817        $new_data = $response->get_data();
    18181818
    1819         $this->assertEquals( array( 'author', 'editor' ), $new_data['roles'] );
     1819        $this->assertSame( array( 'author', 'editor' ), $new_data['roles'] );
    18201820
    18211821        $user = get_userdata( $user_id );
     
    18911891
    18921892        $new_data = $response->get_data();
    1893         $this->assertEquals( 'editor', $new_data['roles'][0] );
     1893        $this->assertSame( 'editor', $new_data['roles'][0] );
    18941894        $this->assertNotEquals( 'administrator', $new_data['roles'][0] );
    18951895
     
    19051905
    19061906        $new_data = $response->get_data();
    1907         $this->assertEquals( 'editor', $new_data['roles'][0] );
     1907        $this->assertSame( 'editor', $new_data['roles'][0] );
    19081908        $this->assertNotEquals( 'administrator', $new_data['roles'][0] );
    19091909    }
     
    20132013        $request->set_param( 'roles', array( 'editor' ) );
    20142014        $response = rest_get_server()->dispatch( $request );
    2015         $this->assertEquals( 200, $response->get_status() );
     2015        $this->assertSame( 200, $response->get_status() );
    20162016
    20172017        $new_data = $response->get_data();
    2018         $this->assertEquals( 'editor', $new_data['roles'][0] );
     2018        $this->assertSame( 'editor', $new_data['roles'][0] );
    20192019    }
    20202020
     
    20452045            $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
    20462046        } else {
    2047             $this->assertEquals( 200, $response->get_status() );
     2047            $this->assertSame( 200, $response->get_status() );
    20482048
    20492049            $new_data = $response->get_data();
    2050             $this->assertEquals( 'editor', $new_data['roles'][0] );
     2050            $this->assertSame( 'editor', $new_data['roles'][0] );
    20512051        }
    20522052    }
     
    20792079            $request->set_param( 'email', 'cbg@androidsdungeon.com' );
    20802080            $response = rest_get_server()->dispatch( $request );
    2081             $this->assertEquals( 201, $response->get_status() );
     2081            $this->assertSame( 201, $response->get_status() );
    20822082            $actual_output = $response->get_data();
    20832083
    20842084            // Compare expected API output to actual API output.
    2085             $this->assertEquals( $expected_output['username'], $actual_output['username'] );
    2086             $this->assertEquals( $expected_output['name'], $actual_output['name'] );
    2087             $this->assertEquals( $expected_output['first_name'], $actual_output['first_name'] );
    2088             $this->assertEquals( $expected_output['last_name'], $actual_output['last_name'] );
    2089             $this->assertEquals( $expected_output['url'], $actual_output['url'] );
    2090             $this->assertEquals( $expected_output['description'], $actual_output['description'] );
    2091             $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] );
     2085            $this->assertSame( $expected_output['username'], $actual_output['username'] );
     2086            $this->assertSame( $expected_output['name'], $actual_output['name'] );
     2087            $this->assertSame( $expected_output['first_name'], $actual_output['first_name'] );
     2088            $this->assertSame( $expected_output['last_name'], $actual_output['last_name'] );
     2089            $this->assertSame( $expected_output['url'], $actual_output['url'] );
     2090            $this->assertSame( $expected_output['description'], $actual_output['description'] );
     2091            $this->assertSame( $expected_output['nickname'], $actual_output['nickname'] );
    20922092
    20932093            // Compare expected API output to WP internal values.
    20942094            $user = get_userdata( $actual_output['id'] );
    2095             $this->assertEquals( $expected_output['username'], $user->user_login );
    2096             $this->assertEquals( $expected_output['name'], $user->display_name );
    2097             $this->assertEquals( $expected_output['first_name'], $user->first_name );
    2098             $this->assertEquals( $expected_output['last_name'], $user->last_name );
    2099             $this->assertEquals( $expected_output['url'], $user->user_url );
    2100             $this->assertEquals( $expected_output['description'], $user->description );
    2101             $this->assertEquals( $expected_output['nickname'], $user->nickname );
     2095            $this->assertSame( $expected_output['username'], $user->user_login );
     2096            $this->assertSame( $expected_output['name'], $user->display_name );
     2097            $this->assertSame( $expected_output['first_name'], $user->first_name );
     2098            $this->assertSame( $expected_output['last_name'], $user->last_name );
     2099            $this->assertSame( $expected_output['url'], $user->user_url );
     2100            $this->assertSame( $expected_output['description'], $user->description );
     2101            $this->assertSame( $expected_output['nickname'], $user->nickname );
    21022102            $this->assertTrue( wp_check_password( addslashes( $expected_output['password'] ), $user->user_pass ) );
    21032103
     
    21132113        }
    21142114        $response = rest_get_server()->dispatch( $request );
    2115         $this->assertEquals( 200, $response->get_status() );
     2115        $this->assertSame( 200, $response->get_status() );
    21162116        $actual_output = $response->get_data();
    21172117
    21182118        // Compare expected API output to actual API output.
    21192119        if ( isset( $expected_output['username'] ) ) {
    2120             $this->assertEquals( $expected_output['username'], $actual_output['username'] );
    2121         }
    2122         $this->assertEquals( $expected_output['name'], $actual_output['name'] );
    2123         $this->assertEquals( $expected_output['first_name'], $actual_output['first_name'] );
    2124         $this->assertEquals( $expected_output['last_name'], $actual_output['last_name'] );
    2125         $this->assertEquals( $expected_output['url'], $actual_output['url'] );
    2126         $this->assertEquals( $expected_output['description'], $actual_output['description'] );
    2127         $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] );
     2120            $this->assertSame( $expected_output['username'], $actual_output['username'] );
     2121        }
     2122        $this->assertSame( $expected_output['name'], $actual_output['name'] );
     2123        $this->assertSame( $expected_output['first_name'], $actual_output['first_name'] );
     2124        $this->assertSame( $expected_output['last_name'], $actual_output['last_name'] );
     2125        $this->assertSame( $expected_output['url'], $actual_output['url'] );
     2126        $this->assertSame( $expected_output['description'], $actual_output['description'] );
     2127        $this->assertSame( $expected_output['nickname'], $actual_output['nickname'] );
    21282128
    21292129        // Compare expected API output to WP internal values.
    21302130        $user = get_userdata( $actual_output['id'] );
    21312131        if ( isset( $expected_output['username'] ) ) {
    2132             $this->assertEquals( $expected_output['username'], $user->user_login );
    2133         }
    2134         $this->assertEquals( $expected_output['name'], $user->display_name );
    2135         $this->assertEquals( $expected_output['first_name'], $user->first_name );
    2136         $this->assertEquals( $expected_output['last_name'], $user->last_name );
    2137         $this->assertEquals( $expected_output['url'], $user->user_url );
    2138         $this->assertEquals( $expected_output['description'], $user->description );
    2139         $this->assertEquals( $expected_output['nickname'], $user->nickname );
     2132            $this->assertSame( $expected_output['username'], $user->user_login );
     2133        }
     2134        $this->assertSame( $expected_output['name'], $user->display_name );
     2135        $this->assertSame( $expected_output['first_name'], $user->first_name );
     2136        $this->assertSame( $expected_output['last_name'], $user->last_name );
     2137        $this->assertSame( $expected_output['url'], $user->user_url );
     2138        $this->assertSame( $expected_output['description'], $user->description );
     2139        $this->assertSame( $expected_output['nickname'], $user->nickname );
    21402140        $this->assertTrue( wp_check_password( addslashes( $expected_output['password'] ), $user->user_pass ) );
    21412141    }
     
    21442144        wp_set_current_user( self::$editor );
    21452145
    2146         $this->assertEquals( ! is_multisite(), current_user_can( 'unfiltered_html' ) );
     2146        $this->assertSame( ! is_multisite(), current_user_can( 'unfiltered_html' ) );
    21472147        $this->verify_user_roundtrip(
    21482148            array(
     
    22972297        }
    22982298
    2299         $this->assertEquals( 200, $response->get_status() );
     2299        $this->assertSame( 200, $response->get_status() );
    23002300        $data = $response->get_data();
    23012301        $this->assertTrue( $data['deleted'] );
    2302         $this->assertEquals( 'Deleted User', $data['previous']['name'] );
     2302        $this->assertSame( 'Deleted User', $data['previous']['name'] );
    23032303    }
    23042304
     
    23562356        }
    23572357
    2358         $this->assertEquals( 200, $response->get_status() );
     2358        $this->assertSame( 200, $response->get_status() );
    23592359        $data = $response->get_data();
    23602360        $this->assertTrue( $data['deleted'] );
    2361         $this->assertEquals( 'Deleted User', $data['previous']['name'] );
     2361        $this->assertSame( 'Deleted User', $data['previous']['name'] );
    23622362    }
    23632363
     
    24602460        }
    24612461
    2462         $this->assertEquals( 200, $response->get_status() );
     2462        $this->assertSame( 200, $response->get_status() );
    24632463
    24642464        // Check that the post has been updated correctly.
     
    25282528
    25292529        $test_post = get_post( $test_post );
    2530         $this->assertEquals( 'trash', $test_post->post_status );
     2530        $this->assertSame( 'trash', $test_post->post_status );
    25312531    }
    25322532
     
    25562556
    25572557        $test_post = get_post( $test_post );
    2558         $this->assertEquals( 'trash', $test_post->post_status );
     2558        $this->assertSame( 'trash', $test_post->post_status );
    25592559    }
    25602560
     
    25842584
    25852585        $test_post = get_post( $test_post );
    2586         $this->assertEquals( 'trash', $test_post->post_status );
     2586        $this->assertSame( 'trash', $test_post->post_status );
    25872587    }
    25882588
     
    26212621        $properties = $data['schema']['properties'];
    26222622
    2623         $this->assertEquals( 19, count( $properties ) );
     2623        $this->assertSame( 19, count( $properties ) );
    26242624        $this->assertArrayHasKey( 'avatar_urls', $properties );
    26252625        $this->assertArrayHasKey( 'capabilities', $properties );
     
    26852685
    26862686        $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
    2687         $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] );
     2687        $this->assertSame( $schema, $data['schema']['properties']['my_custom_int'] );
    26882688
    26892689        wp_set_current_user( 1 );
     
    29102910        $response = rest_get_server()->dispatch( $request );
    29112911
    2912         $this->assertEquals( 200, $response->get_status() );
     2912        $this->assertSame( 200, $response->get_status() );
    29132913
    29142914        $data = $response->get_data();
     
    29172917        $meta = (array) $data['meta'];
    29182918        $this->assertArrayHasKey( $meta_key, $meta );
    2919         $this->assertEquals( $expected, $meta[ $meta_key ] );
     2919        $this->assertSame( $expected, $meta[ $meta_key ] );
    29202920    }
    29212921
     
    30223022
    30233023    protected function check_user_data( $user, $data, $context, $links ) {
    3024         $this->assertEquals( $user->ID, $data['id'] );
    3025         $this->assertEquals( $user->display_name, $data['name'] );
    3026         $this->assertEquals( $user->user_url, $data['url'] );
    3027         $this->assertEquals( $user->description, $data['description'] );
    3028         $this->assertEquals( get_author_posts_url( $user->ID ), $data['link'] );
     3024        $this->assertSame( $user->ID, $data['id'] );
     3025        $this->assertSame( $user->display_name, $data['name'] );
     3026        $this->assertSame( $user->user_url, $data['url'] );
     3027        $this->assertSame( $user->description, $data['description'] );
     3028        $this->assertSame( get_author_posts_url( $user->ID ), $data['link'] );
    30293029        $this->assertArrayHasKey( 'avatar_urls', $data );
    3030         $this->assertEquals( $user->user_nicename, $data['slug'] );
     3030        $this->assertSame( $user->user_nicename, $data['slug'] );
    30313031
    30323032        if ( 'edit' === $context ) {
    3033             $this->assertEquals( $user->first_name, $data['first_name'] );
    3034             $this->assertEquals( $user->last_name, $data['last_name'] );
    3035             $this->assertEquals( $user->nickname, $data['nickname'] );
    3036             $this->assertEquals( $user->user_email, $data['email'] );
     3033            $this->assertSame( $user->first_name, $data['first_name'] );
     3034            $this->assertSame( $user->last_name, $data['last_name'] );
     3035            $this->assertSame( $user->nickname, $data['nickname'] );
     3036            $this->assertSame( $user->user_email, $data['email'] );
    30373037            $this->assertEquals( (object) $user->allcaps, $data['capabilities'] );
    30383038            $this->assertEquals( (object) $user->caps, $data['extra_capabilities'] );
    3039             $this->assertEquals( gmdate( 'c', strtotime( $user->user_registered ) ), $data['registered_date'] );
    3040             $this->assertEquals( $user->user_login, $data['username'] );
    3041             $this->assertEquals( $user->roles, $data['roles'] );
    3042             $this->assertEquals( get_user_locale( $user ), $data['locale'] );
     3039            $this->assertSame( gmdate( 'c', strtotime( $user->user_registered ) ), $data['registered_date'] );
     3040            $this->assertSame( $user->user_login, $data['username'] );
     3041            $this->assertSame( $user->roles, $data['roles'] );
     3042            $this->assertSame( get_user_locale( $user ), $data['locale'] );
    30433043        }
    30443044
     
    30683068
    30693069    protected function check_get_user_response( $response, $context = 'view' ) {
    3070         $this->assertEquals( 200, $response->get_status() );
     3070        $this->assertSame( 200, $response->get_status() );
    30713071
    30723072        $data     = $response->get_data();
     
    30773077    protected function check_add_edit_user_response( $response, $update = false ) {
    30783078        if ( $update ) {
    3079             $this->assertEquals( 200, $response->get_status() );
     3079            $this->assertSame( 200, $response->get_status() );
    30803080        } else {
    3081             $this->assertEquals( 201, $response->get_status() );
     3081            $this->assertSame( 201, $response->get_status() );
    30823082        }
    30833083
Note: See TracChangeset for help on using the changeset viewer.