Changeset 47122 for trunk/tests/phpunit/tests/user.php
- Timestamp:
- 01/29/2020 12:43:23 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user.php
r46683 r47122 1 1 <?php 2 2 3 // test functions in wp-includes/user.php4 3 /** 4 * Test functions in wp-includes/user.php 5 * 5 6 * @group user 6 7 */ … … 67 68 68 69 function test_get_users_of_blog() { 69 // add one of each user role70 // Add one of each user role. 70 71 $nusers = array( 71 72 self::$contrib_id, … … 78 79 $user_list = get_users(); 79 80 80 // find the role of each user as returned by get_users_of_blog81 // Find the role of each user as returned by get_users_of_blog(). 81 82 $found = array(); 82 83 foreach ( $user_list as $user ) { 83 // only include the users we just created - there might be some others that existed previously84 // Only include the users we just created - there might be some others that existed previously. 84 85 if ( in_array( $user->ID, $nusers, true ) ) { 85 86 $found[] = $user->ID; … … 87 88 } 88 89 89 // make sure every user we created was returned90 // Make sure every user we created was returned. 90 91 $this->assertEqualSets( $nusers, $found ); 91 92 } 92 93 93 // simple get/set tests for user_option functions94 // Simple get/set tests for user_option functions. 94 95 function test_user_option() { 95 96 $key = rand_str(); 96 97 $val = rand_str(); 97 98 98 // get an option that doesn't exist99 // Get an option that doesn't exist. 99 100 $this->assertFalse( get_user_option( $key, self::$author_id ) ); 100 101 101 // set and get102 // Set and get. 102 103 update_user_option( self::$author_id, $key, $val ); 103 104 $this->assertEquals( $val, get_user_option( $key, self::$author_id ) ); 104 105 105 // change and get again106 // Change and get again. 106 107 $val2 = rand_str(); 107 108 update_user_option( self::$author_id, $key, $val2 ); … … 109 110 } 110 111 111 // simple tests for usermeta functions 112 /** 113 * Simple tests for usermeta functions. 114 */ 112 115 function test_usermeta() { 113 116 $key = 'key'; 114 117 $val = 'value1'; 115 118 116 // get a meta key that doesn't exist119 // Get a meta key that doesn't exist. 117 120 $this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) ); 118 121 119 // set and get122 // Set and get. 120 123 update_user_meta( self::$author_id, $key, $val ); 121 124 $this->assertEquals( $val, get_user_meta( self::$author_id, $key, true ) ); 122 125 123 // change and get again126 // Change and get again. 124 127 $val2 = 'value2'; 125 128 update_user_meta( self::$author_id, $key, $val2 ); 126 129 $this->assertEquals( $val2, get_user_meta( self::$author_id, $key, true ) ); 127 130 128 // delete and get131 // Delete and get. 129 132 delete_user_meta( self::$author_id, $key ); 130 133 $this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) ); 131 134 132 // delete by key AND value135 // Delete by key AND value. 133 136 update_user_meta( self::$author_id, $key, $val ); 134 // incorrect key: key still exists137 // Incorrect key: key still exists. 135 138 delete_user_meta( self::$author_id, $key, rand_str() ); 136 139 $this->assertEquals( $val, get_user_meta( self::$author_id, $key, true ) ); 137 // correct key: deleted140 // Correct key: deleted. 138 141 delete_user_meta( self::$author_id, $key, $val ); 139 142 $this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) ); … … 141 144 } 142 145 143 // test usermeta functions in array mode 146 /** 147 * Test usermeta functions in array mode. 148 */ 144 149 function test_usermeta_array() { 145 // some values to set150 // Some values to set. 146 151 $vals = array( 147 152 rand_str() => 'val-' . rand_str(), … … 150 155 ); 151 156 152 // there is already some stuff in the array157 // There is already some stuff in the array. 153 158 $this->assertTrue( is_array( get_user_meta( self::$author_id ) ) ); 154 159 … … 156 161 update_user_meta( self::$author_id, $k, $v ); 157 162 } 158 // get the complete usermeta array163 // Get the complete usermeta array. 159 164 $out = get_user_meta( self::$author_id ); 160 165 161 // for reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere.162 // so we'll just check to make sure our values are included somewhere.166 // For reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere. 167 // So we'll just check to make sure our values are included somewhere. 163 168 foreach ( $vals as $k => $v ) { 164 169 $this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v ); 165 170 } 166 // delete one key and check again171 // Delete one key and check again. 167 172 $keys = array_keys( $vals ); 168 173 $key_to_delete = array_pop( $keys ); 169 174 delete_user_meta( self::$author_id, $key_to_delete ); 170 175 $out = get_user_meta( self::$author_id ); 171 // make sure that key is excluded from the results176 // Make sure that key is excluded from the results. 172 177 foreach ( $vals as $k => $v ) { 173 178 if ( $k === $key_to_delete ) { … … 179 184 } 180 185 181 // Test property magic functions for property get/set/isset. 186 /** 187 * Test property magic functions for property get/set/isset. 188 */ 182 189 function test_user_properties() { 183 190 $user = new WP_User( self::$author_id ); … … 192 199 $user->$key = 'foo'; 193 200 $this->assertEquals( 'foo', $user->$key ); 194 $this->assertEquals( 'foo', $user->data->$key ); // This will fail with WP < 3.3 201 $this->assertEquals( 'foo', $user->data->$key ); // This will fail with WP < 3.3. 195 202 196 203 foreach ( get_object_vars( $user ) as $key => $value ) { … … 200 207 201 208 /** 202 * Test the magic __unset method209 * Test the magic __unset() method. 203 210 * 204 211 * @ticket 20043 … … 208 215 $user = new WP_User( self::$author_id ); 209 216 210 // Test custom fields 217 // Test custom fields. 211 218 $user->customField = 123; 212 219 $this->assertEquals( $user->customField, 123 ); … … 218 225 219 226 /** 227 * Test 'id' (lowercase). 228 * 220 229 * @depends test_user_unset 221 230 * @expectedDeprecated WP_User->id … … 223 232 */ 224 233 function test_user_unset_lowercase_id( $user ) { 225 // Test 'id' (lowercase)226 234 $id = $user->id; 227 235 unset( $user->id ); … … 231 239 232 240 /** 241 * Test 'ID'. 242 * 233 243 * @depends test_user_unset_lowercase_id 234 244 * @ticket 20043 235 245 */ 236 246 function test_user_unset_uppercase_id( $user ) { 237 // Test 'ID'238 247 $this->assertNotEmpty( $user->ID ); 239 248 unset( $user->ID ); … … 241 250 } 242 251 243 // Test meta property magic functions for property get/set/isset. 252 /** 253 * Test meta property magic functions for property get/set/isset. 254 */ 244 255 function test_user_meta_properties() { 245 256 $user = new WP_User( self::$author_id ); … … 359 370 $this->assertEquals( 'test user', $user->get( 'display_name' ) ); 360 371 361 // Make sure there is no collateral damage to fields not in $user_data 372 // Make sure there is no collateral damage to fields not in $user_data. 362 373 $this->assertEquals( 'about me', $user->get( 'description' ) ); 363 374 364 // Pass as stdClass 375 // Pass as stdClass. 365 376 $user_data = array( 366 377 'ID' => self::$author_id, … … 377 388 $this->assertEquals( 'some test user', $user->get( 'display_name' ) ); 378 389 379 // Test update of fields in _get_additional_user_keys() 390 // Test update of fields in _get_additional_user_keys(). 380 391 $user_data = array( 381 392 'ID' => self::$author_id, … … 453 464 ); 454 465 455 // insert a post and make sure the ID is ok466 // Insert a post and make sure the ID is OK. 456 467 $post_id = wp_insert_post( $post ); 457 468 $this->assertTrue( is_numeric( $post_id ) ); … … 478 489 } 479 490 491 /** 492 * @ticket 23480 493 */ 480 494 function test_user_get_data_by_id() { 481 495 $user = WP_User::get_data_by( 'id', self::$author_id ); … … 570 584 wp_update_user( $user ); 571 585 572 // Reload the data 586 // Reload the data. 573 587 $pwd_after = get_userdata( $testuserid )->user_pass; 574 588 $this->assertEquals( $pwd_before, $pwd_after ); … … 747 761 ); 748 762 749 // Multisite doesn't allow mixed case logins ever 763 // Multisite doesn't allow mixed case logins ever. 750 764 if ( ! is_multisite() ) { 751 765 $data[] = array( 'TestUser' ); … … 1288 1302 $new_email = 'new-admin-email@test.dev'; 1289 1303 1290 // Give the site a name containing HTML entities 1304 // Give the site a name containing HTML entities. 1291 1305 update_option( 'blogname', ''Test' blog's "name" has <html entities> &' ); 1292 1306 … … 1298 1312 $email = $mailer->get_sent(); 1299 1313 1300 // Assert reci epient is correct1314 // Assert recipient is correct. 1301 1315 $this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' ); 1302 1316 1303 // Assert that HTML entites have been decode in body and subject 1317 // Assert that HTML entites have been decode in body and subject. 1304 1318 $this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' ); 1305 1319 $this->assertNotContains( ''Test' blog's "name" has <html entities> &', $email->subject, $email->subject, 'Email subject does contains HTML entities' ); … … 1574 1588 reset_phpmailer_instance(); 1575 1589 1576 // Give the site a name containing HTML entities 1590 // Give the site a name containing HTML entities. 1577 1591 update_option( 'blogname', ''Test' blog's "name" has <html entities> &' ); 1578 1592 … … 1588 1602 $email = $mailer->get_sent(); 1589 1603 1590 // Assert recipient is correct 1604 // Assert recipient is correct. 1591 1605 $this->assertSame( 'new-email@test.dev', $recipient->address, 'User email change confirmation recipient not as expected' ); 1592 1606 1593 // Assert that HTML entites have been decoded in body and subject 1607 // Assert that HTML entites have been decoded in body and subject. 1594 1608 $this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' ); 1595 1609 $this->assertNotContains( ''Test' blog's "name" has <html entities> &', $email->subject, 'Email subject does contains HTML entities' );
Note: See TracChangeset
for help on using the changeset viewer.