Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

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

    r46683 r47122  
    11<?php
    22
    3 // test functions in wp-includes/user.php
    43/**
     4 * Test functions in wp-includes/user.php
     5 *
    56 * @group user
    67 */
     
    6768
    6869    function test_get_users_of_blog() {
    69         // add one of each user role
     70        // Add one of each user role.
    7071        $nusers = array(
    7172            self::$contrib_id,
     
    7879        $user_list = get_users();
    7980
    80         // find the role of each user as returned by get_users_of_blog
     81        // Find the role of each user as returned by get_users_of_blog().
    8182        $found = array();
    8283        foreach ( $user_list as $user ) {
    83             // only include the users we just created - there might be some others that existed previously
     84            // Only include the users we just created - there might be some others that existed previously.
    8485            if ( in_array( $user->ID, $nusers, true ) ) {
    8586                $found[] = $user->ID;
     
    8788        }
    8889
    89         // make sure every user we created was returned
     90        // Make sure every user we created was returned.
    9091        $this->assertEqualSets( $nusers, $found );
    9192    }
    9293
    93     // simple get/set tests for user_option functions
     94    // Simple get/set tests for user_option functions.
    9495    function test_user_option() {
    9596        $key = rand_str();
    9697        $val = rand_str();
    9798
    98         // get an option that doesn't exist
     99        // Get an option that doesn't exist.
    99100        $this->assertFalse( get_user_option( $key, self::$author_id ) );
    100101
    101         // set and get
     102        // Set and get.
    102103        update_user_option( self::$author_id, $key, $val );
    103104        $this->assertEquals( $val, get_user_option( $key, self::$author_id ) );
    104105
    105         // change and get again
     106        // Change and get again.
    106107        $val2 = rand_str();
    107108        update_user_option( self::$author_id, $key, $val2 );
     
    109110    }
    110111
    111     // simple tests for usermeta functions
     112    /**
     113     * Simple tests for usermeta functions.
     114     */
    112115    function test_usermeta() {
    113116        $key = 'key';
    114117        $val = 'value1';
    115118
    116         // get a meta key that doesn't exist
     119        // Get a meta key that doesn't exist.
    117120        $this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) );
    118121
    119         // set and get
     122        // Set and get.
    120123        update_user_meta( self::$author_id, $key, $val );
    121124        $this->assertEquals( $val, get_user_meta( self::$author_id, $key, true ) );
    122125
    123         // change and get again
     126        // Change and get again.
    124127        $val2 = 'value2';
    125128        update_user_meta( self::$author_id, $key, $val2 );
    126129        $this->assertEquals( $val2, get_user_meta( self::$author_id, $key, true ) );
    127130
    128         // delete and get
     131        // Delete and get.
    129132        delete_user_meta( self::$author_id, $key );
    130133        $this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) );
    131134
    132         // delete by key AND value
     135        // Delete by key AND value.
    133136        update_user_meta( self::$author_id, $key, $val );
    134         // incorrect key: key still exists
     137        // Incorrect key: key still exists.
    135138        delete_user_meta( self::$author_id, $key, rand_str() );
    136139        $this->assertEquals( $val, get_user_meta( self::$author_id, $key, true ) );
    137         // correct key: deleted
     140        // Correct key: deleted.
    138141        delete_user_meta( self::$author_id, $key, $val );
    139142        $this->assertEquals( '', get_user_meta( self::$author_id, $key, true ) );
     
    141144    }
    142145
    143     // test usermeta functions in array mode
     146    /**
     147     * Test usermeta functions in array mode.
     148     */
    144149    function test_usermeta_array() {
    145         // some values to set
     150        // Some values to set.
    146151        $vals = array(
    147152            rand_str() => 'val-' . rand_str(),
     
    150155        );
    151156
    152         // there is already some stuff in the array
     157        // There is already some stuff in the array.
    153158        $this->assertTrue( is_array( get_user_meta( self::$author_id ) ) );
    154159
     
    156161            update_user_meta( self::$author_id, $k, $v );
    157162        }
    158         // get the complete usermeta array
     163        // Get the complete usermeta array.
    159164        $out = get_user_meta( self::$author_id );
    160165
    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.
    163168        foreach ( $vals as $k => $v ) {
    164169            $this->assertTrue( isset( $out[ $k ] ) && $out[ $k ][0] === $v );
    165170        }
    166         // delete one key and check again
     171        // Delete one key and check again.
    167172        $keys          = array_keys( $vals );
    168173        $key_to_delete = array_pop( $keys );
    169174        delete_user_meta( self::$author_id, $key_to_delete );
    170175        $out = get_user_meta( self::$author_id );
    171         // make sure that key is excluded from the results
     176        // Make sure that key is excluded from the results.
    172177        foreach ( $vals as $k => $v ) {
    173178            if ( $k === $key_to_delete ) {
     
    179184    }
    180185
    181     // Test property magic functions for property get/set/isset.
     186    /**
     187     * Test property magic functions for property get/set/isset.
     188     */
    182189    function test_user_properties() {
    183190        $user = new WP_User( self::$author_id );
     
    192199        $user->$key = 'foo';
    193200        $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.
    195202
    196203        foreach ( get_object_vars( $user ) as $key => $value ) {
     
    200207
    201208    /**
    202      * Test the magic __unset method
     209     * Test the magic __unset() method.
    203210     *
    204211     * @ticket 20043
     
    208215        $user = new WP_User( self::$author_id );
    209216
    210         // Test custom fields
     217        // Test custom fields.
    211218        $user->customField = 123;
    212219        $this->assertEquals( $user->customField, 123 );
     
    218225
    219226    /**
     227     * Test 'id' (lowercase).
     228     *
    220229     * @depends test_user_unset
    221230     * @expectedDeprecated WP_User->id
     
    223232     */
    224233    function test_user_unset_lowercase_id( $user ) {
    225         // Test 'id' (lowercase)
    226234        $id = $user->id;
    227235        unset( $user->id );
     
    231239
    232240    /**
     241     * Test 'ID'.
     242     *
    233243     * @depends test_user_unset_lowercase_id
    234244     * @ticket 20043
    235245     */
    236246    function test_user_unset_uppercase_id( $user ) {
    237         // Test 'ID'
    238247        $this->assertNotEmpty( $user->ID );
    239248        unset( $user->ID );
     
    241250    }
    242251
    243     // Test meta property magic functions for property get/set/isset.
     252    /**
     253     * Test meta property magic functions for property get/set/isset.
     254     */
    244255    function test_user_meta_properties() {
    245256        $user = new WP_User( self::$author_id );
     
    359370        $this->assertEquals( 'test user', $user->get( 'display_name' ) );
    360371
    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.
    362373        $this->assertEquals( 'about me', $user->get( 'description' ) );
    363374
    364         // Pass as stdClass
     375        // Pass as stdClass.
    365376        $user_data = array(
    366377            'ID'           => self::$author_id,
     
    377388        $this->assertEquals( 'some test user', $user->get( 'display_name' ) );
    378389
    379         // Test update of fields in _get_additional_user_keys()
     390        // Test update of fields in _get_additional_user_keys().
    380391        $user_data = array(
    381392            'ID'                   => self::$author_id,
     
    453464        );
    454465
    455         // insert a post and make sure the ID is ok
     466        // Insert a post and make sure the ID is OK.
    456467        $post_id = wp_insert_post( $post );
    457468        $this->assertTrue( is_numeric( $post_id ) );
     
    478489    }
    479490
     491    /**
     492     * @ticket 23480
     493     */
    480494    function test_user_get_data_by_id() {
    481495        $user = WP_User::get_data_by( 'id', self::$author_id );
     
    570584        wp_update_user( $user );
    571585
    572         // Reload the data
     586        // Reload the data.
    573587        $pwd_after = get_userdata( $testuserid )->user_pass;
    574588        $this->assertEquals( $pwd_before, $pwd_after );
     
    747761        );
    748762
    749         // Multisite doesn't allow mixed case logins ever
     763        // Multisite doesn't allow mixed case logins ever.
    750764        if ( ! is_multisite() ) {
    751765            $data[] = array( 'TestUser' );
     
    12881302        $new_email      = 'new-admin-email@test.dev';
    12891303
    1290         // Give the site a name containing HTML entities
     1304        // Give the site a name containing HTML entities.
    12911305        update_option( 'blogname', '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;' );
    12921306
     
    12981312        $email     = $mailer->get_sent();
    12991313
    1300         // Assert reciepient is correct
     1314        // Assert recipient is correct.
    13011315        $this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' );
    13021316
    1303         // Assert that HTML entites have been decode in body and subject
     1317        // Assert that HTML entites have been decode in body and subject.
    13041318        $this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' );
    13051319        $this->assertNotContains( '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;', $email->subject, $email->subject, 'Email subject does contains HTML entities' );
     
    15741588        reset_phpmailer_instance();
    15751589
    1576         // Give the site a name containing HTML entities
     1590        // Give the site a name containing HTML entities.
    15771591        update_option( 'blogname', '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;' );
    15781592
     
    15881602        $email     = $mailer->get_sent();
    15891603
    1590         // Assert recipient is correct
     1604        // Assert recipient is correct.
    15911605        $this->assertSame( 'new-email@test.dev', $recipient->address, 'User email change confirmation recipient not as expected' );
    15921606
    1593         // Assert that HTML entites have been decoded in body and subject
     1607        // Assert that HTML entites have been decoded in body and subject.
    15941608        $this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' );
    15951609        $this->assertNotContains( '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;', $email->subject, 'Email subject does contains HTML entities' );
Note: See TracChangeset for help on using the changeset viewer.