Make WordPress Core


Ignore:
Timestamp:
09/11/2015 01:50:40 AM (11 years ago)
Author:
boonebgorges
Message:

Move wp_delete_user() tests to their own file.

See #33800.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/wpDeleteUser.php

    r34032 r34033  
    11<?php
    22
    3 // test functions in wp-includes/user.php
    43/**
    54 * @group user
    65 */
    7 class Tests_User extends WP_UnitTestCase {
    8 
    9         protected $user_data;
    10 
    11         function setUp() {
    12                 parent::setUp();
    13 
    14                 $this->user_data = array(
    15                         'user_login' => 'user1',
    16                         'user_nicename' => 'userone',
    17                         'user_pass'  => 'password',
    18                         'first_name' => 'John',
    19                         'last_name'  => 'Doe',
    20                         'display_name' => 'John Doe',
    21                         'user_email' => 'blackburn@battlefield3.com',
    22                         'user_url' => 'http://tacos.com'
    23                 );
    24         }
    25 
    26         function test_get_users_of_blog() {
    27                 // add one of each user role
    28                 $nusers = array();
    29                 foreach ( array('administrator', 'editor', 'author', 'contributor', 'subscriber' ) as $role ) {
    30                         $id = $this->factory->user->create( array( 'role' => $role ) );
    31                         $nusers[ $id ] = $id;
    32                 }
    33 
    34                 $user_list = get_users();
    35 
    36                 // find the role of each user as returned by get_users_of_blog
    37                 $found = array();
    38                 foreach ( $user_list as $user ) {
    39                         // only include the users we just created - there might be some others that existed previously
    40                         if ( isset( $nusers[$user->ID] ) ) {
    41                                 $found[ $user->ID] = $user->ID;
    42                         }
    43                 }
    44 
    45                 // make sure every user we created was returned
    46                 $this->assertEquals($nusers, $found);
    47         }
    48 
    49         // simple get/set tests for user_option functions
    50         function test_user_option() {
    51                 $key = rand_str();
    52                 $val = rand_str();
    53 
    54                 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    55 
    56                 // get an option that doesn't exist
    57                 $this->assertFalse(get_user_option($key, $user_id));
    58 
    59                 // set and get
    60                 update_user_option( $user_id, $key, $val );
    61                 $this->assertEquals( $val, get_user_option($key, $user_id) );
    62 
    63                 // change and get again
    64                 $val2 = rand_str();
    65                 update_user_option( $user_id, $key, $val2 );
    66                 $this->assertEquals( $val2, get_user_option($key, $user_id) );
    67 
    68         }
    69 
    70         // simple tests for usermeta functions
    71         function test_usermeta() {
    72 
    73                 $key = rand_str();
    74                 $val = rand_str();
    75 
    76                 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    77 
    78                 // get a meta key that doesn't exist
    79                 $this->assertEquals( '', get_user_meta($user_id, $key, true));
    80 
    81                 // set and get
    82                 update_user_meta( $user_id, $key, $val );
    83                 $this->assertEquals( $val, get_user_meta($user_id, $key, true) );
    84 
    85                 // change and get again
    86                 $val2 = rand_str();
    87                 update_user_meta( $user_id, $key, $val2 );
    88                 $this->assertEquals( $val2, get_user_meta($user_id, $key, true) );
    89 
    90                 // delete and get
    91                 delete_user_meta( $user_id, $key );
    92                 $this->assertEquals( '', get_user_meta($user_id, $key, true) );
    93 
    94                 // delete by key AND value
    95                 update_user_meta( $user_id, $key, $val );
    96                 // incorrect key: key still exists
    97                 delete_user_meta( $user_id, $key, rand_str() );
    98                 $this->assertEquals( $val, get_user_meta($user_id, $key, true) );
    99                 // correct key: deleted
    100                 delete_user_meta( $user_id, $key, $val );
    101                 $this->assertEquals( '', get_user_meta($user_id, $key, true) );
    102 
    103         }
    104 
    105         // test usermeta functions in array mode
    106         function test_usermeta_array() {
    107                 // some values to set
    108                 $vals = array(
    109                         rand_str() => 'val-'.rand_str(),
    110                         rand_str() => 'val-'.rand_str(),
    111                         rand_str() => 'val-'.rand_str(),
    112                 );
    113 
    114                 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    115 
    116                 // there is already some stuff in the array
    117                 $this->assertTrue(is_array(get_user_meta($user_id)));
    118 
    119                 foreach ($vals as $k=>$v)
    120                         update_user_meta( $user_id, $k, $v );
    121 
    122                 // get the complete usermeta array
    123                 $out = get_user_meta($user_id);
    124 
    125                 // for reasons unclear, the resulting array is indexed numerically; meta keys are not included anywhere.
    126                 // so we'll just check to make sure our values are included somewhere.
    127                 foreach ($vals as $k=>$v)
    128                         $this->assertTrue(isset($out[$k]) && $out[$k][0] == $v);
    129 
    130                 // delete one key and check again
    131                 $keys = array_keys( $vals );
    132                 $key_to_delete = array_pop( $keys );
    133                 delete_user_meta($user_id, $key_to_delete);
    134                 $out = get_user_meta($user_id);
    135                 // make sure that key is excluded from the results
    136                 foreach ($vals as $k=>$v) {
    137                         if ($k == $key_to_delete)
    138                                 $this->assertFalse(isset($out[$k]));
    139                         else
    140                         $this->assertTrue(isset($out[$k]) && $out[$k][0] == $v);
    141                 }
    142         }
    143 
    144         // Test property magic functions for property get/set/isset.
    145         function test_user_properties() {
    146                 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    147                 $user = new WP_User( $user_id );
    148 
    149                 foreach ( $user->data as $key => $data ) {
    150                         $this->assertEquals( $data, $user->$key );
    151                 }
    152 
    153                 $this->assertTrue( isset( $user->$key ) );
    154                 $this->assertFalse( isset( $user->fooooooooo ) );
    155 
    156                 $user->$key = 'foo';
    157                 $this->assertEquals( 'foo', $user->$key );
    158                 $this->assertEquals( 'foo', $user->data->$key );  // This will fail with WP < 3.3
    159 
    160                 foreach ( (array) $user as $key => $value ) {
    161                         $this->assertEquals( $value, $user->$key );
    162                 }
    163         }
    164 
    165         // Test meta property magic functions for property get/set/isset.
    166         function test_user_meta_properties() {
    167                 global $wpdb;
    168 
    169                 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    170                 $user = new WP_User( $user_id );
    171 
    172                 update_user_option( $user_id, 'foo', 'foo', true );
    173 
    174                 $this->assertTrue( isset( $user->foo ) );
    175 
    176                 $this->assertEquals( 'foo', $user->foo );
    177         }
    178 
    179         /**
    180          * @expectedDeprecated WP_User->id
    181          */
    182         function test_id_property_back_compat() {
    183                 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    184                 $user = new WP_User( $user_id );
    185 
    186                 $this->assertTrue( isset( $user->id ) );
    187                 $this->assertEquals( $user->ID, $user->id );
    188                 $user->id = 1234;
    189                 $this->assertEquals( $user->ID, $user->id );
    190         }
    191 
    192         /**
    193          * ticket 19265
    194          */
    195         function test_user_level_property_back_compat() {
    196                 $roles = array(
    197                         'administrator' => 10,
    198                         'editor' => 7,
    199                         'author' => 2,
    200                         'contributor' => 1,
    201                         'subscriber' => 0,
    202                 );
    203 
    204                 foreach ( $roles as $role => $level ) {
    205                         $user_id = $this->factory->user->create( array( 'role' => $role ) );
    206                         $user = new WP_User( $user_id );
    207 
    208                         $this->assertTrue( isset( $user->user_level ) );
    209                         $this->assertEquals( $level, $user->user_level );
    210                 }
    211         }
    212 
    213         function test_construction() {
    214                 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    215 
    216                 $user = new WP_User( $user_id );
    217                 $this->assertInstanceOf( 'WP_User', $user );
    218                 $this->assertEquals( $user_id, $user->ID );
    219 
    220                 $user2 = new WP_User( 0,  $user->user_login );
    221                 $this->assertInstanceOf( 'WP_User', $user2 );
    222                 $this->assertEquals( $user_id, $user2->ID );
    223                 $this->assertEquals( $user->user_login, $user2->user_login );
    224 
    225                 $user3 = new WP_User();
    226                 $this->assertInstanceOf( 'WP_User', $user3 );
    227                 $this->assertEquals( 0, $user3->ID );
    228                 $this->assertFalse( isset( $user3->user_login ) );
    229 
    230                 $user3->init( $user->data );
    231                 $this->assertEquals( $user_id, $user3->ID );
    232 
    233                 $user4 = new WP_User( $user->user_login );
    234                 $this->assertInstanceOf( 'WP_User', $user4 );
    235                 $this->assertEquals( $user_id, $user4->ID );
    236                 $this->assertEquals( $user->user_login, $user4->user_login );
    237 
    238                 $user5 = new WP_User( null, $user->user_login );
    239                 $this->assertInstanceOf( 'WP_User', $user5 );
    240                 $this->assertEquals( $user_id, $user5->ID );
    241                 $this->assertEquals( $user->user_login, $user5->user_login );
    242 
    243                 $user6 = new WP_User( $user );
    244                 $this->assertInstanceOf( 'WP_User', $user6 );
    245                 $this->assertEquals( $user_id, $user6->ID );
    246                 $this->assertEquals( $user->user_login, $user6->user_login );
    247 
    248                 $user7 = new WP_User( $user->data );
    249                 $this->assertInstanceOf( 'WP_User', $user7 );
    250                 $this->assertEquals( $user_id, $user7->ID );
    251                 $this->assertEquals( $user->user_login, $user7->user_login );
    252         }
    253 
    254         function test_get() {
    255                 $user_id = $this->factory->user->create( array(
    256                         'role' => 'author',
    257                         'user_login' => 'test_wp_user_get',
    258                         'user_pass' => 'password',
    259                         'user_email' => 'test@test.com',
    260                 ) );
    261 
    262                 $user = new WP_User( $user_id );
    263                 $this->assertEquals( 'test_wp_user_get', $user->get( 'user_login' ) );
    264                 $this->assertEquals( 'test@test.com', $user->get( 'user_email' ) );
    265                 $this->assertEquals( 0, $user->get( 'use_ssl' ) );
    266                 $this->assertEquals( '', $user->get( 'field_that_does_not_exist' ) );
    267 
    268                 update_user_meta( $user_id, 'dashed-key', 'abcdefg' );
    269                 $this->assertEquals( 'abcdefg', $user->get( 'dashed-key' ) );
    270         }
    271 
    272         function test_has_prop() {
    273                 $user_id = $this->factory->user->create( array(
    274                         'role' => 'author',
    275                         'user_login' => 'test_wp_user_has_prop',
    276                         'user_pass' => 'password',
    277                         'user_email' => 'test2@test.com',
    278                 ) );
    279 
    280                 $user = new WP_User( $user_id );
    281                 $this->assertTrue( $user->has_prop( 'user_email') );
    282                 $this->assertTrue( $user->has_prop( 'use_ssl' ) );
    283                 $this->assertFalse( $user->has_prop( 'field_that_does_not_exist' ) );
    284 
    285                 update_user_meta( $user_id, 'dashed-key', 'abcdefg' );
    286                 $this->assertTrue( $user->has_prop( 'dashed-key' ) );
    287         }
    288 
    289         function test_update_user() {
    290                 $user_id = $this->factory->user->create( array(
    291                         'role' => 'author',
    292                         'user_login' => 'test_wp_update_user',
    293                         'user_pass' => 'password',
    294                         'user_email' => 'test3@test.com',
    295                 ) );
    296                 $user = new WP_User( $user_id );
    297 
    298                 update_user_meta( $user_id, 'description', 'about me' );
    299                 $this->assertEquals( 'about me', $user->get( 'description' ) );
    300 
    301                 $user_data = array( 'ID' => $user_id, 'display_name' => 'test user' );
    302                 wp_update_user( $user_data );
    303 
    304                 $user = new WP_User( $user_id );
    305                 $this->assertEquals( 'test user', $user->get( 'display_name' ) );
    306 
    307                 // Make sure there is no collateral damage to fields not in $user_data
    308                 $this->assertEquals( 'about me', $user->get( 'description' ) );
    309 
    310                 // Pass as stdClass
    311                 $user_data = array( 'ID' => $user_id, 'display_name' => 'a test user' );
    312                 wp_update_user( (object) $user_data );
    313 
    314                 $user = new WP_User( $user_id );
    315                 $this->assertEquals( 'a test user', $user->get( 'display_name' ) );
    316 
    317                 // Pass as WP_User
    318                 $user = new WP_User( $user_id );
    319                 $user->display_name = 'some test user';
    320                 wp_update_user( $user );
    321 
    322                 $user = new WP_User( $user_id );
    323                 $this->assertEquals( 'some test user', $user->get( 'display_name' ) );
    324 
    325                 // Test update of fields in _get_additional_user_keys()
    326                 $user_data = array( 'ID' => $user_id, 'use_ssl' => 1, 'show_admin_bar_front' => 1,
    327                                                    'rich_editing' => 1, 'first_name' => 'first', 'last_name' => 'last',
    328                                                    'nickname' => 'nick', 'comment_shortcuts' => 'true', 'admin_color' => 'classic',
    329                                                    'description' => 'describe' );
    330                 wp_update_user( $user_data );
    331 
    332                 $user = new WP_User( $user_id );
    333                 foreach ( $user_data as $key => $value )
    334                         $this->assertEquals( $value, $user->get( $key ), $key );
    335         }
     6class Tests_User_WpDeleteUser extends WP_UnitTestCase {
    3367
    3378        /**
    … …  
    36738                $old_current = get_current_user_id();
    36839
    369                 $this->assertSame( 0, $old_current );
    370 
    371                 // test for "get current user" when not logged in
    372                 $this->assertFalse( is_user_member_of_blog() );
    373 
    37440                $user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) );
    37541                wp_set_current_user( $user_id );
    … …  
    38955
    39056                wp_set_current_user( $old_current );
    391         }
    392 
    393         /**
    394          * ticket 19595
    395          */
    396         function test_global_userdata() {
    397                 global $userdata, $wpdb;
    398 
    399                 $user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) );
    400                 wp_set_current_user( $user_id );
    401 
    402                 $this->assertNotEmpty( $userdata );
    403                 $this->assertInstanceOf( 'WP_User', $userdata );
    404                 $this->assertEquals( $userdata->ID, $user_id );
    405                 $prefix = $wpdb->get_blog_prefix();
    406                 $cap_key = $prefix . 'capabilities';
    407                 $this->assertTrue( isset( $userdata->$cap_key ) );
    408         }
    409 
    410         /**
    411          * ticket 19769
    412          */
    413         function test_global_userdata_is_null_when_logged_out() {
    414                 global $userdata;
    415                 wp_set_current_user(0);
    416                 $this->assertNull( $userdata );
    417         }
    418 
    419         function test_exists() {
    420                 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    421                 $user = new WP_User( $user_id );
    422 
    423                 $this->assertTrue( $user->exists() );
    424 
    425                 $user = new WP_User( 123456789 );
    426 
    427                 $this->assertFalse( $user->exists() );
    428 
    429                 $user = new WP_User( 0 );
    430 
    431                 $this->assertFalse( $user->exists() );
    432         }
    433 
    434         function test_global_authordata() {
    435                 global $authordata, $id;
    436 
    437                 $old_post_id = $id;
    438 
    439                 $user_id = $this->factory->user->create( array( 'role' => 'author' ) );
    440                 $user = new WP_User( $user_id );
    441 
    442                 $post = array(
    443                         'post_author' => $user_id,
    444                         'post_status' => 'publish',
    445                         'post_content' => rand_str(),
    446                         'post_title' => rand_str(),
    447                         'post_type' => 'post'
    448                 );
    449 
    450                 // insert a post and make sure the ID is ok
    451                 $post_id = wp_insert_post( $post );
    452                 $this->assertTrue( is_numeric( $post_id ) );
    453 
    454                 setup_postdata( get_post( $post_id ) );
    455 
    456                 $this->assertNotEmpty( $authordata );
    457                 $this->assertInstanceOf( 'WP_User', $authordata );
    458                 $this->assertEquals( $authordata->ID, $user_id );
    459 
    460                 if ( $old_post_id )
    461                         setup_postdata( get_post( $old_post_id ) );
    46257        }
    46358
    … …  
    517112
    518113        /**
    519          * @ticket 13317
    520          */
    521         function test_get_userdata() {
    522                 $this->assertFalse( get_userdata( 0 ) );
    523                 $this->assertFalse( get_userdata( '0' ) );
    524                 $this->assertFalse( get_userdata( 'string' ) );
    525                 $this->assertFalse( get_userdata( array( 'array' ) ) );
    526         }
    527 
    528         function test_user_get_data_by_id() {
    529                 $user_id   = $this->factory->user->create();
    530 
    531                 $user = WP_User::get_data_by( 'id', $user_id );
    532                 $this->assertInstanceOf( 'stdClass', $user );
    533                 $this->assertEquals( $user_id, $user->ID );
    534 
    535                 // @ticket 23480
    536                 $user = WP_User::get_data_by( 'id', -1 );
    537                 $this->assertEquals( false, $user );
    538 
    539                 $user = WP_User::get_data_by( 'id', 0 );
    540                 $this->assertEquals( false, $user );
    541 
    542                 $user = WP_User::get_data_by( 'id', null );
    543                 $this->assertEquals( false, $user );
    544 
    545                 $user = WP_User::get_data_by( 'id', '' );
    546                 $this->assertEquals( false, $user );
    547 
    548                 $user = WP_User::get_data_by( 'id', false );
    549                 $this->assertEquals( false, $user );
    550 
    551                 $user = WP_User::get_data_by( 'id', @$user->user_nicename );
    552                 $this->assertEquals( false, $user );
    553 
    554                 $user = WP_User::get_data_by( 'id', 99999 );
    555                 $this->assertEquals( false, $user );
    556         }
    557 
    558         /**
    559114         * @ticket 20447
    560115         */
    … …  
    571126                $this->assertEquals( $reassign, $post->post_author );
    572127        }
    573 
    574         /**
    575          * @ticket 21431
    576          */
    577         function test_count_many_users_posts() {
    578                 $user_id_a = $this->factory->user->create( array( 'role' => 'author' ) );
    579                 $user_id_b = $this->factory->user->create( array( 'role' => 'author' ) );
    580                 $post_id_a = $this->factory->post->create( array( 'post_author' => $user_id_a ) );
    581                 $post_id_b = $this->factory->post->create( array( 'post_author' => $user_id_b ) );
    582                 $post_id_c = $this->factory->post->create( array( 'post_author' => $user_id_b, 'post_status' => 'private' ) );
    583 
    584                 wp_set_current_user( $user_id_a );
    585                 $counts = count_many_users_posts( array( $user_id_a, $user_id_b), 'post', false );
    586                 $this->assertEquals( 1, $counts[$user_id_a] );
    587                 $this->assertEquals( 1, $counts[$user_id_b] );
    588 
    589                 $counts = count_many_users_posts( array( $user_id_a, $user_id_b), 'post', true );
    590                 $this->assertEquals( 1, $counts[$user_id_a] );
    591                 $this->assertEquals( 1, $counts[$user_id_b] );
    592 
    593                 wp_set_current_user( $user_id_b );
    594                 $counts = count_many_users_posts( array( $user_id_a, $user_id_b), 'post', false );
    595                 $this->assertEquals( 1, $counts[$user_id_a] );
    596                 $this->assertEquals( 2, $counts[$user_id_b] );
    597 
    598                 $counts = count_many_users_posts( array( $user_id_a, $user_id_b), 'post', true );
    599                 $this->assertEquals( 1, $counts[$user_id_a] );
    600                 $this->assertEquals( 1, $counts[$user_id_b] );
    601         }
    602 
    603         /**
    604          * @ticket 22858
    605          */
    606         function test_wp_update_user_on_nonexistent_users() {
    607                 $user_id = 1;
    608                 // Find me a non-existent user ID.
    609                 while ( get_userdata( $user_id ) )
    610                         ++$user_id;
    611 
    612                 // If this test fails, it will error out for calling the to_array() method on a non-object.
    613                 $this->assertInstanceOf( 'WP_Error', wp_update_user( array( 'ID' => $user_id ) ) );
    614         }
    615 
    616         /**
    617          * @ticket 28315
    618          */
    619         function test_user_meta_error() {
    620                 $id1 = wp_insert_user( array(
    621                         'user_login' => rand_str(),
    622                         'user_pass' => 'password',
    623                         'user_email' => 'taco@burrito.com',
    624                 ) );
    625                 $this->assertEquals( $id1, email_exists( 'taco@burrito.com' ) );
    626 
    627                 $id2 = wp_insert_user( array(
    628                         'user_login' => rand_str(),
    629                         'user_pass' => 'password',
    630                         'user_email' => 'taco@burrito.com',
    631                 ) );
    632 
    633                 if ( ! defined( 'WP_IMPORTING' ) ) {
    634                         $this->assertWPError( $id2 );
    635                 }
    636 
    637                 @update_user_meta( $id2, 'key', 'value' );
    638 
    639                 $metas = array_keys( get_user_meta( 1 ) );
    640                 $this->assertNotContains( 'key', $metas );
    641         }
    642 
    643         /**
    644          * @ticket 30647
    645          */
    646         function test_user_update_email_error() {
    647                 $id1 = wp_insert_user( array(
    648                         'user_login' => rand_str(),
    649                         'user_pass'  => 'password',
    650                         'user_email' => 'blackburn@battlefield3.com',
    651                 ) );
    652                 $this->assertEquals( $id1, email_exists( 'blackburn@battlefield3.com' ) );
    653 
    654                 $id2 = wp_insert_user( array(
    655                         'user_login' => rand_str(),
    656                         'user_pass'  => 'password',
    657                         'user_email' => 'miller@battlefield3.com',
    658                 ) );
    659                 $this->assertEquals( $id2, email_exists( 'miller@battlefield3.com' ) );
    660 
    661                 if( ! is_wp_error( $id2 ) ){
    662                         $return = wp_update_user( array(
    663                                 'ID'         => $id2,
    664                                 'user_email' => 'david@battlefield3.com',
    665                         ) );
    666                         $this->assertEquals( $id2, email_exists( 'david@battlefield3.com' ) );
    667 
    668                         $return = wp_update_user( array(
    669                                 'ID'         => $id2,
    670                                 'user_email' => 'blackburn@battlefield3.com',
    671                         ) );
    672                         if ( ! defined( 'WP_IMPORTING' ) ) {
    673                                 $this->assertWPError( $return );
    674                         }
    675                 }
    676         }
    677 
    678         /**
    679          * @ticket 29696
    680          */
    681         public function test_wp_insert_user_should_sanitize_user_nicename_parameter() {
    682                 $user = $this->factory->user->create_and_get();
    683 
    684                 $userdata = $user->to_array();
    685                 $userdata['user_nicename'] = str_replace( '-', '.', $user->user_nicename );
    686                 wp_insert_user( $userdata );
    687 
    688                 $updated_user = new WP_User( $user->ID );
    689 
    690                 $this->assertSame( $user->user_nicename, $updated_user->user_nicename );
    691         }
    692 
    693         function test_changing_email_invalidates_password_reset_key() {
    694                 global $wpdb;
    695 
    696                 $user = $this->factory->user->create_and_get();
    697                 $wpdb->update( $wpdb->users, array( 'user_activation_key' => 'key' ), array( 'ID' => $user->ID ) );
    698                 clean_user_cache( $user );
    699 
    700                 $user = get_userdata( $user->ID );
    701                 $this->assertEquals( 'key', $user->user_activation_key );
    702 
    703                 // Check that changing something other than the email doesn't remove the key.
    704                 $userdata = array(
    705                         'ID'            => $user->ID,
    706                         'user_nicename' => 'wat',
    707                 );
    708                 wp_update_user( $userdata );
    709 
    710                 $user = get_userdata( $user->ID );
    711                 $this->assertEquals( 'key', $user->user_activation_key );
    712 
    713                 // Now check that changing the email does remove it.
    714                 $userdata = array(
    715                         'ID'            => $user->ID,
    716                         'user_nicename' => 'cat',
    717                         'user_email'    => 'foo@bar.dev',
    718                 );
    719                 wp_update_user( $userdata );
    720 
    721                 $user = get_userdata( $user->ID );
    722                 $this->assertEmpty( $user->user_activation_key );
    723         }
    724 
    725         public function test_search_users_login() {
    726                 $id = $this->factory->user->create( $this->user_data );
    727 
    728                 $users = get_users( array( 'search' => 'user1', 'fields' => 'ID' ) );
    729 
    730                 $this->assertTrue( in_array( $id, $users ) );
    731         }
    732 
    733         public function test_search_users_url() {
    734                 $id = $this->factory->user->create( $this->user_data );
    735 
    736                 $users = get_users( array( 'search' => '*tacos*', 'fields' => 'ID' ) );
    737 
    738                 $this->assertTrue( in_array( $id, $users ) );
    739         }
    740 
    741         public function test_search_users_email() {
    742                 $id = $this->factory->user->create( $this->user_data );
    743 
    744                 $users = get_users( array( 'search' => '*battle*', 'fields' => 'ID' ) );
    745 
    746                 $this->assertTrue( in_array( $id, $users ) );
    747         }
    748 
    749         public function test_search_users_nicename() {
    750                 $id = $this->factory->user->create( $this->user_data );
    751 
    752                 $users = get_users( array( 'search' => '*one*', 'fields' => 'ID' ) );
    753 
    754                 $this->assertTrue( in_array( $id, $users ) );
    755         }
    756 
    757         public function test_search_users_display_name() {
    758                 $id = $this->factory->user->create( $this->user_data );
    759 
    760                 $users = get_users( array( 'search' => '*Doe*', 'fields' => 'ID' ) );
    761 
    762                 $this->assertTrue( in_array( $id, $users ) );
    763         }
    764 
    765         /**
    766          * @ticket 32158
    767          */
    768         function test_email_case() {
    769                 // Create a test user with a lower-case email address.
    770                 $user_id = $this->factory->user->create( array(
    771                         'user_email' => 'test@test.com',
    772                 ) );
    773 
    774                 // Alter the case of the email address (which stays the same).
    775                 $userdata = array(
    776                         'ID' => $user_id,
    777                         'user_email' => 'test@TEST.com',
    778                 );
    779                 $update = wp_update_user( $userdata );
    780 
    781                 $this->assertEquals( $user_id, $update );
    782         }
    783 
    784         /**
    785          * @ticket 32158
    786          */
    787         function test_email_change() {
    788                 // Create a test user.
    789                 $user_id = $this->factory->user->create( array(
    790                         'user_email' => 'test@test.com',
    791                 ) );
    792 
    793                 // Change the email address.
    794                 $userdata = array(
    795                         'ID' => $user_id,
    796                         'user_email' => 'test2@test.com',
    797                 );
    798                 $update = wp_update_user( $userdata );
    799 
    800                 // Was this successful?
    801                 $this->assertEquals( $user_id, $update );
    802 
    803                 // Verify that the email address has been updated.
    804                 $user = get_userdata( $user_id );
    805                 $this->assertEquals( $user->user_email, 'test2@test.com' );
    806         }
    807 
    808128}
Note: See TracChangeset for help on using the changeset viewer.