Changeset 48937 for trunk/tests/phpunit/tests/user.php
- Timestamp:
- 09/02/2020 12:35:36 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user.php
r48100 r48937 102 102 // Set and get. 103 103 update_user_option( self::$author_id, $key, $val ); 104 $this->assert Equals( $val, get_user_option( $key, self::$author_id ) );104 $this->assertSame( $val, get_user_option( $key, self::$author_id ) ); 105 105 106 106 // Change and get again. 107 107 $val2 = rand_str(); 108 108 update_user_option( self::$author_id, $key, $val2 ); 109 $this->assert Equals( $val2, get_user_option( $key, self::$author_id ) );109 $this->assertSame( $val2, get_user_option( $key, self::$author_id ) ); 110 110 } 111 111 … … 118 118 119 119 // Get a meta key that doesn't exist. 120 $this->assert Equals( '', get_user_meta( self::$author_id, $key, true ) );120 $this->assertSame( '', get_user_meta( self::$author_id, $key, true ) ); 121 121 122 122 // Set and get. 123 123 update_user_meta( self::$author_id, $key, $val ); 124 $this->assert Equals( $val, get_user_meta( self::$author_id, $key, true ) );124 $this->assertSame( $val, get_user_meta( self::$author_id, $key, true ) ); 125 125 126 126 // Change and get again. 127 127 $val2 = 'value2'; 128 128 update_user_meta( self::$author_id, $key, $val2 ); 129 $this->assert Equals( $val2, get_user_meta( self::$author_id, $key, true ) );129 $this->assertSame( $val2, get_user_meta( self::$author_id, $key, true ) ); 130 130 131 131 // Delete and get. 132 132 delete_user_meta( self::$author_id, $key ); 133 $this->assert Equals( '', get_user_meta( self::$author_id, $key, true ) );133 $this->assertSame( '', get_user_meta( self::$author_id, $key, true ) ); 134 134 135 135 // Delete by key AND value. … … 137 137 // Incorrect key: key still exists. 138 138 delete_user_meta( self::$author_id, $key, rand_str() ); 139 $this->assert Equals( $val, get_user_meta( self::$author_id, $key, true ) );139 $this->assertSame( $val, get_user_meta( self::$author_id, $key, true ) ); 140 140 // Correct key: deleted. 141 141 delete_user_meta( self::$author_id, $key, $val ); 142 $this->assert Equals( '', get_user_meta( self::$author_id, $key, true ) );142 $this->assertSame( '', get_user_meta( self::$author_id, $key, true ) ); 143 143 144 144 } … … 198 198 199 199 $user->$key = 'foo'; 200 $this->assert Equals( 'foo', $user->$key );201 $this->assert Equals( 'foo', $user->data->$key ); // This will fail with WP < 3.3.200 $this->assertSame( 'foo', $user->$key ); 201 $this->assertSame( 'foo', $user->data->$key ); // This will fail with WP < 3.3. 202 202 203 203 foreach ( get_object_vars( $user ) as $key => $value ) { 204 $this->assert Equals( $value, $user->$key );204 $this->assertSame( $value, $user->$key ); 205 205 } 206 206 } … … 217 217 // Test custom fields. 218 218 $user->customField = 123; 219 $this->assert Equals( $user->customField, 123 );219 $this->assertSame( $user->customField, 123 ); 220 220 unset( $user->customField ); 221 221 $this->assertFalse( isset( $user->customField ) ); … … 260 260 $this->assertTrue( isset( $user->foo ) ); 261 261 262 $this->assert Equals( 'foo', $user->foo );262 $this->assertSame( 'foo', $user->foo ); 263 263 } 264 264 … … 270 270 271 271 $this->assertTrue( isset( $user->id ) ); 272 $this->assert Equals( $user->ID, $user->id );272 $this->assertSame( $user->ID, $user->id ); 273 273 $user->id = 1234; 274 $this->assert Equals( $user->ID, $user->id );274 $this->assertSame( $user->ID, $user->id ); 275 275 } 276 276 … … 298 298 $user = new WP_User( self::$author_id ); 299 299 $this->assertInstanceOf( 'WP_User', $user ); 300 $this->assert Equals( self::$author_id, $user->ID );300 $this->assertSame( self::$author_id, $user->ID ); 301 301 302 302 $user2 = new WP_User( 0, $user->user_login ); 303 303 $this->assertInstanceOf( 'WP_User', $user2 ); 304 $this->assert Equals( self::$author_id, $user2->ID );305 $this->assert Equals( $user->user_login, $user2->user_login );304 $this->assertSame( self::$author_id, $user2->ID ); 305 $this->assertSame( $user->user_login, $user2->user_login ); 306 306 307 307 $user3 = new WP_User(); 308 308 $this->assertInstanceOf( 'WP_User', $user3 ); 309 $this->assert Equals( 0, $user3->ID );309 $this->assertSame( 0, $user3->ID ); 310 310 $this->assertFalse( isset( $user3->user_login ) ); 311 311 312 312 $user3->init( $user->data ); 313 $this->assert Equals( self::$author_id, $user3->ID );313 $this->assertSame( self::$author_id, $user3->ID ); 314 314 315 315 $user4 = new WP_User( $user->user_login ); 316 316 $this->assertInstanceOf( 'WP_User', $user4 ); 317 $this->assert Equals( self::$author_id, $user4->ID );318 $this->assert Equals( $user->user_login, $user4->user_login );317 $this->assertSame( self::$author_id, $user4->ID ); 318 $this->assertSame( $user->user_login, $user4->user_login ); 319 319 320 320 $user5 = new WP_User( null, $user->user_login ); 321 321 $this->assertInstanceOf( 'WP_User', $user5 ); 322 $this->assert Equals( self::$author_id, $user5->ID );323 $this->assert Equals( $user->user_login, $user5->user_login );322 $this->assertSame( self::$author_id, $user5->ID ); 323 $this->assertSame( $user->user_login, $user5->user_login ); 324 324 325 325 $user6 = new WP_User( $user ); 326 326 $this->assertInstanceOf( 'WP_User', $user6 ); 327 $this->assert Equals( self::$author_id, $user6->ID );328 $this->assert Equals( $user->user_login, $user6->user_login );327 $this->assertSame( self::$author_id, $user6->ID ); 328 $this->assertSame( $user->user_login, $user6->user_login ); 329 329 330 330 $user7 = new WP_User( $user->data ); 331 331 $this->assertInstanceOf( 'WP_User', $user7 ); 332 $this->assert Equals( self::$author_id, $user7->ID );333 $this->assert Equals( $user->user_login, $user7->user_login );332 $this->assertSame( self::$author_id, $user7->ID ); 333 $this->assertSame( $user->user_login, $user7->user_login ); 334 334 } 335 335 336 336 function test_get() { 337 337 $user = new WP_User( self::$author_id ); 338 $this->assert Equals( 'author_login', $user->get( 'user_login' ) );339 $this->assert Equals( 'author@email.com', $user->get( 'user_email' ) );338 $this->assertSame( 'author_login', $user->get( 'user_login' ) ); 339 $this->assertSame( 'author@email.com', $user->get( 'user_email' ) ); 340 340 $this->assertEquals( 0, $user->get( 'use_ssl' ) ); 341 $this->assert Equals( '', $user->get( 'field_that_does_not_exist' ) );341 $this->assertSame( '', $user->get( 'field_that_does_not_exist' ) ); 342 342 343 343 update_user_meta( self::$author_id, 'dashed-key', 'abcdefg' ); 344 $this->assert Equals( 'abcdefg', $user->get( 'dashed-key' ) );344 $this->assertSame( 'abcdefg', $user->get( 'dashed-key' ) ); 345 345 } 346 346 … … 359 359 360 360 update_user_meta( self::$author_id, 'description', 'about me' ); 361 $this->assert Equals( 'about me', $user->get( 'description' ) );361 $this->assertSame( 'about me', $user->get( 'description' ) ); 362 362 363 363 $user_data = array( … … 368 368 369 369 $user = new WP_User( self::$author_id ); 370 $this->assert Equals( 'test user', $user->get( 'display_name' ) );370 $this->assertSame( 'test user', $user->get( 'display_name' ) ); 371 371 372 372 // Make sure there is no collateral damage to fields not in $user_data. 373 $this->assert Equals( 'about me', $user->get( 'description' ) );373 $this->assertSame( 'about me', $user->get( 'description' ) ); 374 374 375 375 // Pass as stdClass. … … 381 381 382 382 $user = new WP_User( self::$author_id ); 383 $this->assert Equals( 'a test user', $user->get( 'display_name' ) );383 $this->assertSame( 'a test user', $user->get( 'display_name' ) ); 384 384 385 385 $user->display_name = 'some test user'; 386 386 wp_update_user( $user ); 387 387 388 $this->assert Equals( 'some test user', $user->get( 'display_name' ) );388 $this->assertSame( 'some test user', $user->get( 'display_name' ) ); 389 389 390 390 // Test update of fields in _get_additional_user_keys(). … … 420 420 $this->assertNotEmpty( $userdata ); 421 421 $this->assertInstanceOf( 'WP_User', $userdata ); 422 $this->assert Equals( $userdata->ID, self::$sub_id );422 $this->assertSame( $userdata->ID, self::$sub_id ); 423 423 $prefix = $wpdb->get_blog_prefix(); 424 424 $cap_key = $prefix . 'capabilities'; … … 472 472 $this->assertNotEmpty( $authordata ); 473 473 $this->assertInstanceOf( 'WP_User', $authordata ); 474 $this->assert Equals( $authordata->ID, self::$author_id );474 $this->assertSame( $authordata->ID, self::$author_id ); 475 475 476 476 if ( $old_post_id ) { … … 499 499 // @ticket 23480 500 500 $user1 = WP_User::get_data_by( 'id', -1 ); 501 $this->assert Equals( false,$user1 );501 $this->assertFalse( $user1 ); 502 502 503 503 $user2 = WP_User::get_data_by( 'id', 0 ); 504 $this->assert Equals( false,$user2 );504 $this->assertFalse( $user2 ); 505 505 506 506 $user3 = WP_User::get_data_by( 'id', null ); 507 $this->assert Equals( false,$user3 );507 $this->assertFalse( $user3 ); 508 508 509 509 $user4 = WP_User::get_data_by( 'id', '' ); 510 $this->assert Equals( false,$user4 );510 $this->assertFalse( $user4 ); 511 511 512 512 $user5 = WP_User::get_data_by( 'id', false ); 513 $this->assert Equals( false,$user5 );513 $this->assertFalse( $user5 ); 514 514 515 515 $user6 = WP_User::get_data_by( 'id', $user->user_nicename ); 516 $this->assert Equals( false,$user6 );516 $this->assertFalse( $user6 ); 517 517 518 518 $user7 = WP_User::get_data_by( 'id', 99999 ); 519 $this->assert Equals( false,$user7 );519 $this->assertFalse( $user7 ); 520 520 } 521 521 … … 586 586 // Reload the data. 587 587 $pwd_after = get_userdata( $testuserid )->user_pass; 588 $this->assert Equals( $pwd_before, $pwd_after );588 $this->assertSame( $pwd_before, $pwd_after ); 589 589 } 590 590 … … 625 625 ) 626 626 ); 627 $this->assert Equals( $id1, email_exists( 'taco@burrito.com' ) );627 $this->assertSame( $id1, email_exists( 'taco@burrito.com' ) ); 628 628 629 629 $id2 = wp_insert_user( … … 656 656 ) 657 657 ); 658 $this->assert Equals( $id1, email_exists( 'blackburn@battlefield4.com' ) );658 $this->assertSame( $id1, email_exists( 'blackburn@battlefield4.com' ) ); 659 659 660 660 $id2 = wp_insert_user( … … 665 665 ) 666 666 ); 667 $this->assert Equals( $id2, email_exists( 'miller@battlefield4.com' ) );667 $this->assertSame( $id2, email_exists( 'miller@battlefield4.com' ) ); 668 668 669 669 if ( ! is_wp_error( $id2 ) ) { … … 674 674 ) 675 675 ); 676 $this->assert Equals( $id2, email_exists( 'david@battlefield4.com' ) );676 $this->assertSame( $id2, email_exists( 'david@battlefield4.com' ) ); 677 677 678 678 $return = wp_update_user( … … 704 704 $response = wp_insert_user( $user_data ); 705 705 $this->assertInstanceOf( 'WP_Error', $response ); 706 $this->assert Equals( 'invalid_username', $response->get_error_code() );706 $this->assertSame( 'invalid_username', $response->get_error_code() ); 707 707 708 708 remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); … … 724 724 $response = register_new_user( $user_login, $user_email ); 725 725 $this->assertInstanceOf( 'WP_Error', $response ); 726 $this->assert Equals( 'invalid_username', $response->get_error_code() );726 $this->assertSame( 'invalid_username', $response->get_error_code() ); 727 727 728 728 remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); … … 747 747 $response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] ); 748 748 $this->assertInstanceOf( 'WP_Error', $response['errors'] ); 749 $this->assert Equals( 'user_name', $response['errors']->get_error_code() );749 $this->assertSame( 'user_name', $response['errors']->get_error_code() ); 750 750 751 751 remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) ); … … 753 753 $response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] ); 754 754 $this->assertInstanceOf( 'WP_Error', $response['errors'] ); 755 $this->assert Equals( 0, count( $response['errors']->get_error_codes() ) );755 $this->assertSame( 0, count( $response['errors']->get_error_codes() ) ); 756 756 } 757 757 … … 816 816 817 817 $user_id = wp_insert_user( $user_details ); 818 $this->assert Equals( $user_id, email_exists( $user_details['user_email'] ) );818 $this->assertSame( $user_id, email_exists( $user_details['user_email'] ) ); 819 819 820 820 // Check that providing an empty password doesn't remove a user's password. … … 1045 1045 1046 1046 $user = get_userdata( $user->ID ); 1047 $this->assert Equals( 'key', $user->user_activation_key );1047 $this->assertSame( 'key', $user->user_activation_key ); 1048 1048 1049 1049 // Check that changing something other than the email doesn't remove the key. … … 1055 1055 1056 1056 $user = get_userdata( $user->ID ); 1057 $this->assert Equals( 'key', $user->user_activation_key );1057 $this->assertSame( 'key', $user->user_activation_key ); 1058 1058 1059 1059 // Now check that changing the email does remove it. … … 1077 1077 1078 1078 $user = get_userdata( $user->ID ); 1079 $this->assert Equals( 'key', $user->user_activation_key );1079 $this->assertSame( 'key', $user->user_activation_key ); 1080 1080 1081 1081 $userdata = array( … … 1155 1155 $update = wp_update_user( $userdata ); 1156 1156 1157 $this->assert Equals( self::$editor_id, $update );1157 $this->assertSame( self::$editor_id, $update ); 1158 1158 } 1159 1159 … … 1170 1170 1171 1171 // Was this successful? 1172 $this->assert Equals( self::$editor_id, $update );1172 $this->assertSame( self::$editor_id, $update ); 1173 1173 1174 1174 // Verify that the email address has been updated. 1175 1175 $user = get_userdata( self::$editor_id ); 1176 $this->assert Equals( $user->user_email, 'test2@test.com' );1176 $this->assertSame( $user->user_email, 'test2@test.com' ); 1177 1177 } 1178 1178 … … 1469 1469 1470 1470 $this->assertInstanceOf( 'WP_Error', $response ); 1471 $this->assert Equals( 'pass', $response->get_error_code() );1471 $this->assertSame( 'pass', $response->get_error_code() ); 1472 1472 1473 1473 // Check new user with password set. … … 1480 1480 $this->assertInternalType( 'int', $user_id ); 1481 1481 $this->assertInstanceOf( 'WP_User', $user ); 1482 $this->assert Equals( 'nickname1', $user->nickname );1482 $this->assertSame( 'nickname1', $user->nickname ); 1483 1483 1484 1484 // Check updating user with empty password. … … 1490 1490 1491 1491 $this->assertInternalType( 'int', $user_id ); 1492 $this->assert Equals( 'nickname_updated', $user->nickname );1492 $this->assertSame( 'nickname_updated', $user->nickname ); 1493 1493 1494 1494 // Check updating user with missing second password. … … 1500 1500 1501 1501 $this->assertInstanceOf( 'WP_Error', $response ); 1502 $this->assert Equals( 'pass', $response->get_error_code() );1503 $this->assert Equals( 'nickname_updated', $user->nickname );1502 $this->assertSame( 'pass', $response->get_error_code() ); 1503 $this->assertSame( 'nickname_updated', $user->nickname ); 1504 1504 1505 1505 // Check updating user with empty password via `check_passwords` action. … … 1509 1509 1510 1510 $this->assertInternalType( 'int', $user_id ); 1511 $this->assert Equals( 'nickname_updated2', $user->nickname );1511 $this->assertSame( 'nickname_updated2', $user->nickname ); 1512 1512 } 1513 1513 … … 1548 1548 // The new email address gets put into user_meta. 1549 1549 $new_email_meta = get_user_meta( $user->ID, '_new_email', true ); 1550 $this->assert Equals( 'after@example.com', $new_email_meta['newemail'] );1550 $this->assertSame( 'after@example.com', $new_email_meta['newemail'] ); 1551 1551 1552 1552 // The email address of the user doesn't change. $_POST['email'] should be the email address pre-update. 1553 $this->assert Equals( $_POST['email'], $user->user_email );1553 $this->assertSame( $_POST['email'], $user->user_email ); 1554 1554 } 1555 1555 … … 1588 1588 1589 1589 // $_POST['email'] should be the email address posted from the form. 1590 $this->assert Equals( $_POST['email'], 'after@example.com' );1590 $this->assertSame( $_POST['email'], 'after@example.com' ); 1591 1591 } 1592 1592 … … 1724 1724 1725 1725 // Contains 'Community Events Location'. 1726 $this->assert Equals( 'Community Events Location', $actual['data'][1]['group_label'] );1726 $this->assertSame( 'Community Events Location', $actual['data'][1]['group_label'] ); 1727 1727 1728 1728 // Contains location IP. 1729 $this->assert Equals( 'IP', $actual['data'][1]['data'][0]['name'] );1730 $this->assert Equals( '0.0.0.0', $actual['data'][1]['data'][0]['value'] );1729 $this->assertSame( 'IP', $actual['data'][1]['data'][0]['name'] ); 1730 $this->assertSame( '0.0.0.0', $actual['data'][1]['data'][0]['value'] ); 1731 1731 } 1732 1732 … … 1753 1753 1754 1754 // Contains 'Community Events Location'. 1755 $this->assert Equals( 'Community Events Location', $actual['data'][1]['group_label'] );1755 $this->assertSame( 'Community Events Location', $actual['data'][1]['group_label'] ); 1756 1756 1757 1757 // Contains location city. 1758 $this->assert Equals( 'City', $actual['data'][1]['data'][0]['name'] );1759 $this->assert Equals( 'Cincinnati', $actual['data'][1]['data'][0]['value'] );1758 $this->assertSame( 'City', $actual['data'][1]['data'][0]['name'] ); 1759 $this->assertSame( 'Cincinnati', $actual['data'][1]['data'][0]['value'] ); 1760 1760 1761 1761 // Contains location country. 1762 $this->assert Equals( 'Country', $actual['data'][1]['data'][1]['name'] );1763 $this->assert Equals( 'US', $actual['data'][1]['data'][1]['value'] );1762 $this->assertSame( 'Country', $actual['data'][1]['data'][1]['name'] ); 1763 $this->assertSame( 'US', $actual['data'][1]['data'][1]['value'] ); 1764 1764 1765 1765 // Contains location latitude. 1766 $this->assert Equals( 'Latitude', $actual['data'][1]['data'][2]['name'] );1767 $this->assert Equals( '39.1271100', $actual['data'][1]['data'][2]['value'] );1766 $this->assertSame( 'Latitude', $actual['data'][1]['data'][2]['name'] ); 1767 $this->assertSame( '39.1271100', $actual['data'][1]['data'][2]['value'] ); 1768 1768 1769 1769 // Contains location longitude. 1770 $this->assert Equals( 'Longitude', $actual['data'][1]['data'][3]['name'] );1771 $this->assert Equals( '-84.5143900', $actual['data'][1]['data'][3]['value'] );1770 $this->assertSame( 'Longitude', $actual['data'][1]['data'][3]['name'] ); 1771 $this->assertSame( '-84.5143900', $actual['data'][1]['data'][3]['value'] ); 1772 1772 1773 1773 } … … 1797 1797 1798 1798 // Contains Session Tokens. 1799 $this->assert Equals( 'Session Tokens', $actual['data'][1]['group_label'] );1799 $this->assertSame( 'Session Tokens', $actual['data'][1]['group_label'] ); 1800 1800 1801 1801 // Contains Expiration. 1802 $this->assert Equals( 'Expiration', $actual['data'][1]['data'][0]['name'] );1803 $this->assert Equals( 'January 31, 2020 09:13 AM', $actual['data'][1]['data'][0]['value'] );1802 $this->assertSame( 'Expiration', $actual['data'][1]['data'][0]['name'] ); 1803 $this->assertSame( 'January 31, 2020 09:13 AM', $actual['data'][1]['data'][0]['value'] ); 1804 1804 1805 1805 // Contains IP. 1806 $this->assert Equals( 'IP', $actual['data'][1]['data'][1]['name'] );1807 $this->assert Equals( '0.0.0.0', $actual['data'][1]['data'][1]['value'] );1806 $this->assertSame( 'IP', $actual['data'][1]['data'][1]['name'] ); 1807 $this->assertSame( '0.0.0.0', $actual['data'][1]['data'][1]['value'] ); 1808 1808 1809 1809 // Contains IP. 1810 $this->assert Equals( 'User Agent', $actual['data'][1]['data'][2]['name'] );1811 $this->assert Equals( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36', $actual['data'][1]['data'][2]['value'] );1810 $this->assertSame( 'User Agent', $actual['data'][1]['data'][2]['name'] ); 1811 $this->assertSame( 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36', $actual['data'][1]['data'][2]['value'] ); 1812 1812 1813 1813 // Contains IP. 1814 $this->assert Equals( 'Last Login', $actual['data'][1]['data'][3]['name'] );1815 $this->assert Equals( 'January 29, 2020 09:13 AM', $actual['data'][1]['data'][3]['value'] );1814 $this->assertSame( 'Last Login', $actual['data'][1]['data'][3]['name'] ); 1815 $this->assertSame( 'January 29, 2020 09:13 AM', $actual['data'][1]['data'][3]['value'] ); 1816 1816 } 1817 1817
Note: See TracChangeset
for help on using the changeset viewer.