Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (5 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/rest-api/rest-users-controller.php

    r47012 r47122  
    165165
    166166    public function test_context_param() {
    167         // Collection
     167        // Collection.
    168168        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
    169169        $response = rest_get_server()->dispatch( $request );
     
    171171        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    172172        $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    173         // Single
     173        // Single.
    174174        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/' . self::$user );
    175175        $response = rest_get_server()->dispatch( $request );
     
    664664        $response = rest_get_server()->dispatch( $request );
    665665        $this->assertEquals( 1, count( $response->get_data() ) );
    666         // default to wildcard search
     666        // Default to wildcard search.
    667667        $adam_id = $this->factory->user->create(
    668668            array(
     
    789789    }
    790790
    791     // Note: Do not test using editor role as there is an editor role created in testing and it makes it hard to test this functionality.
     791    /**
     792     * Note: Do not test using editor role as there is an editor role created in testing,
     793     * and it makes it hard to test this functionality.
     794     */
    792795    public function test_get_items_roles() {
    793796        wp_set_current_user( self::$user );
     
    948951
    949952        $user = get_user_by( 'id', self::$editor );
    950         /**
    951          * Ignore the subdomain, since 'get_avatar_url randomly sets the Gravatar
    952          * server when building the url string.
    953          */
     953        // Ignore the subdomain, since get_avatar_url() randomly sets
     954        // the Gravatar server when building the URL string.
    954955        $this->assertEquals( substr( get_avatar_url( $user->user_email ), 9 ), substr( $data['avatar_urls'][96], 9 ) );
    955956    }
     
    11971198        );
    11981199
    1199         // Username rules are different (more strict) for multisite; see `wpmu_validate_user_signup`
     1200        // Username rules are different (more strict) for multisite; see `wpmu_validate_user_signup`.
    12001201        if ( is_multisite() ) {
    12011202            $params['username'] = 'no-dashes-allowed';
     
    15221523        $this->check_add_edit_user_response( $response, true );
    15231524
    1524         // Check that the name has been updated correctly
     1525        // Check that the name has been updated correctly.
    15251526        $new_data = $response->get_data();
    15261527        $this->assertEquals( 'New Name', $new_data['first_name'] );
     
    15471548        $request->set_param( 'slug', $user->user_nicename );
    15481549
    1549         // Run twice to make sure that the update still succeeds even if no DB
    1550         // rows are updated.
     1550        // Run twice to make sure that the update still succeeds
     1551        // even if no DB rows are updated.
    15511552        $response = rest_get_server()->dispatch( $request );
    15521553        $this->assertEquals( 200, $response->get_status() );
     
    17691770        $this->check_add_edit_user_response( $response, true );
    17701771
    1771         // Check that the name has been updated correctly
     1772        // Check that the name has been updated correctly.
    17721773        $new_data = $response->get_data();
    17731774        $this->assertEquals( 'JSON Name', $new_data['first_name'] );
     
    20362037
    20372038        if ( is_multisite() ) {
    2038             // Site administrators can promote users, as verified by the
    2039             // previous test, but they cannot perform other user-editing
    2040             // operations.  This also tests the branch of logic that verifies
    2041             // that no parameters other than 'id' and 'roles' are specified for
    2042             // a roles update.
     2039            /*
     2040             * Site administrators can promote users, as verified by the previous test,
     2041             * but they cannot perform other user-editing operations.
     2042             * This also tests the branch of logic that verifies that no parameters
     2043             * other than 'id' and 'roles' are specified for a roles update.
     2044             */
    20432045            $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 );
    20442046        } else {
     
    20672069    public function verify_user_roundtrip( $input = array(), $expected_output = array() ) {
    20682070        if ( isset( $input['id'] ) ) {
    2069             // Existing user; don't try to create one
     2071            // Existing user; don't try to create one.
    20702072            $user_id = $input['id'];
    20712073        } else {
    2072             // Create a new user
     2074            // Create a new user.
    20732075            $request = new WP_REST_Request( 'POST', '/wp/v2/users' );
    20742076            foreach ( $input as $name => $value ) {
     
    20802082            $actual_output = $response->get_data();
    20812083
    2082             // Compare expected API output to actual API output
     2084            // Compare expected API output to actual API output.
    20832085            $this->assertEquals( $expected_output['username'], $actual_output['username'] );
    20842086            $this->assertEquals( $expected_output['name'], $actual_output['name'] );
     
    20892091            $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] );
    20902092
    2091             // Compare expected API output to WP internal values
     2093            // Compare expected API output to WP internal values.
    20922094            $user = get_userdata( $actual_output['id'] );
    20932095            $this->assertEquals( $expected_output['username'], $user->user_login );
     
    21032105        }
    21042106
    2105         // Update the user
     2107        // Update the user.
    21062108        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', $user_id ) );
    21072109        foreach ( $input as $name => $value ) {
     
    21142116        $actual_output = $response->get_data();
    21152117
    2116         // Compare expected API output to actual API output
     2118        // Compare expected API output to actual API output.
    21172119        if ( isset( $expected_output['username'] ) ) {
    21182120            $this->assertEquals( $expected_output['username'], $actual_output['username'] );
     
    21252127        $this->assertEquals( $expected_output['nickname'], $actual_output['nickname'] );
    21262128
    2127         // Compare expected API output to WP internal values
     2129        // Compare expected API output to WP internal values.
    21282130        $user = get_userdata( $actual_output['id'] );
    21292131        if ( isset( $expected_output['username'] ) ) {
     
    23882390        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    23892391
    2390         // Ensure the user still exists
     2392        // Ensure the user still exists.
    23912393        $user = get_user_by( 'id', $user_id );
    23922394        $this->assertNotEmpty( $user );
     
    24602462        $this->assertEquals( 200, $response->get_status() );
    24612463
    2462         // Check that the post has been updated correctly
     2464        // Check that the post has been updated correctly.
    24632465        $post = get_post( $test_post );
    24642466        $this->assertEquals( $reassign_id, $post->post_author );
Note: See TracChangeset for help on using the changeset viewer.