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-attachments-controller.php

    r46657 r47122  
    8888    public static function disposition_provider() {
    8989        return array(
    90             // Types
     90            // Types.
    9191            array( 'attachment; filename="foo.jpg"', 'foo.jpg' ),
    9292            array( 'inline; filename="foo.jpg"', 'foo.jpg' ),
    9393            array( 'form-data; filename="foo.jpg"', 'foo.jpg' ),
    9494
    95             // Formatting
     95            // Formatting.
    9696            array( 'attachment; filename="foo.jpg"', 'foo.jpg' ),
    9797            array( 'attachment; filename=foo.jpg', 'foo.jpg' ),
     
    104104            array( 'attachment; filename = my foo picture.jpg', 'my foo picture.jpg' ),
    105105
    106             // Extensions
     106            // Extensions.
    107107            array( 'form-data; name="myfile"; filename="foo.jpg"', 'foo.jpg' ),
    108108            array( 'form-data; name="myfile"; filename="foo.jpg"; something="else"', 'foo.jpg' ),
     
    110110            array( 'form-data; name=myfile; filename=my foo.jpg; something=else', 'my foo.jpg' ),
    111111
    112             // Invalid
     112            // Invalid.
    113113            array( 'filename="foo.jpg"', null ),
    114114            array( 'filename-foo.jpg', null ),
     
    128128
    129129    public function test_context_param() {
    130         // Collection
     130        // Collection.
    131131        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/media' );
    132132        $response = rest_get_server()->dispatch( $request );
     
    134134        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    135135        $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    136         // Single
     136        // Single.
    137137        $attachment_id = $this->factory->attachment->create_object(
    138138            $this->test_file,
     
    330330        $data     = $response->get_data();
    331331        $this->assertEquals( $id1, $data[0]['id'] );
    332         // media_type=video
     332        // 'media_type' => 'video'.
    333333        $request->set_param( 'media_type', 'video' );
    334334        $response = rest_get_server()->dispatch( $request );
    335335        $this->assertCount( 0, $response->get_data() );
    336         // media_type=image
     336        // 'media_type' => 'image'.
    337337        $request->set_param( 'media_type', 'image' );
    338338        $response = rest_get_server()->dispatch( $request );
     
    353353        $data     = $response->get_data();
    354354        $this->assertEquals( $id1, $data[0]['id'] );
    355         // mime_type=image/png
     355        // 'mime_type' => 'image/png'.
    356356        $request->set_param( 'mime_type', 'image/png' );
    357357        $response = rest_get_server()->dispatch( $request );
    358358        $this->assertCount( 0, $response->get_data() );
    359         // mime_type=image/jpeg
     359        // 'mime_type' => 'image/jpeg'.
    360360        $request->set_param( 'mime_type', 'image/jpeg' );
    361361        $response = rest_get_server()->dispatch( $request );
     
    382382            )
    383383        );
    384         // all attachments
     384        // All attachments.
    385385        $request  = new WP_REST_Request( 'GET', '/wp/v2/media' );
    386386        $response = rest_get_server()->dispatch( $request );
    387387        $this->assertEquals( 2, count( $response->get_data() ) );
    388388        $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
    389         // attachments without a parent
     389        // Attachments without a parent.
    390390        $request->set_param( 'parent', 0 );
    391391        $response = rest_get_server()->dispatch( $request );
     
    393393        $this->assertEquals( 1, count( $data ) );
    394394        $this->assertEquals( $attachment_id2, $data[0]['id'] );
    395         // attachments with parent=post_id
     395        // Attachments with parent=post_id.
    396396        $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
    397397        $request->set_param( 'parent', $post_id );
     
    400400        $this->assertEquals( 1, count( $data ) );
    401401        $this->assertEquals( $attachment_id, $data[0]['id'] );
    402         // attachments with invalid parent
     402        // Attachments with invalid parent.
    403403        $request = new WP_REST_Request( 'GET', '/wp/v2/media' );
    404404        $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
     
    428428
    429429    public function test_get_items_private_status() {
    430         // Logged out users can't make the request
     430        // Logged out users can't make the request.
    431431        wp_set_current_user( 0 );
    432432        $attachment_id1 = $this->factory->attachment->create_object(
     
    443443        $response = rest_get_server()->dispatch( $request );
    444444        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    445         // Properly authorized users can make the request
     445        // Properly authorized users can make the request.
    446446        wp_set_current_user( self::$editor_id );
    447447        $response = rest_get_server()->dispatch( $request );
     
    452452
    453453    public function test_get_items_multiple_statuses() {
    454         // Logged out users can't make the request
     454        // Logged out users can't make the request.
    455455        wp_set_current_user( 0 );
    456456        $attachment_id1 = $this->factory->attachment->create_object(
     
    476476        $response = rest_get_server()->dispatch( $request );
    477477        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    478         // Properly authorized users can make the request
     478        // Properly authorized users can make the request.
    479479        wp_set_current_user( self::$editor_id );
    480480        $response = rest_get_server()->dispatch( $request );
     
    969969
    970970    public function verify_attachment_roundtrip( $input = array(), $expected_output = array() ) {
    971         // Create the post
     971        // Create the post.
    972972        $request = new WP_REST_Request( 'POST', '/wp/v2/media' );
    973973        $request->set_header( 'Content-Type', 'image/jpeg' );
     
    982982        $actual_output = $response->get_data();
    983983
    984         // Remove <p class="attachment"> from rendered description
    985         // see https://core.trac.wordpress.org/ticket/38679
     984        // Remove <p class="attachment"> from rendered description.
     985        // See https://core.trac.wordpress.org/ticket/38679
    986986        $content = $actual_output['description']['rendered'];
    987987        $content = explode( "\n", trim( $content ) );
     
    991991        }
    992992
    993         // Compare expected API output to actual API output
     993        // Compare expected API output to actual API output.
    994994        $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] );
    995995        $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );
     
    999999        $this->assertEquals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) );
    10001000
    1001         // Compare expected API output to WP internal values
     1001        // Compare expected API output to WP internal values.
    10021002        $post = get_post( $actual_output['id'] );
    10031003        $this->assertEquals( $expected_output['title']['raw'], $post->post_title );
     
    10051005        $this->assertEquals( $expected_output['caption']['raw'], $post->post_excerpt );
    10061006
    1007         // Update the post
     1007        // Update the post.
    10081008        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/media/%d', $actual_output['id'] ) );
    10091009        foreach ( $input as $name => $value ) {
     
    10141014        $actual_output = $response->get_data();
    10151015
    1016         // Remove <p class="attachment"> from rendered description
    1017         // see https://core.trac.wordpress.org/ticket/38679
     1016        // Remove <p class="attachment"> from rendered description.
     1017        // See https://core.trac.wordpress.org/ticket/38679
    10181018        $content = $actual_output['description']['rendered'];
    10191019        $content = explode( "\n", trim( $content ) );
     
    10231023        }
    10241024
    1025         // Compare expected API output to actual API output
     1025        // Compare expected API output to actual API output.
    10261026        $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] );
    10271027        $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );
     
    10311031        $this->assertEquals( $expected_output['caption']['rendered'], trim( $actual_output['caption']['rendered'] ) );
    10321032
    1033         // Compare expected API output to WP internal values
     1033        // Compare expected API output to WP internal values.
    10341034        $post = get_post( $actual_output['id'] );
    10351035        $this->assertEquals( $expected_output['title']['raw'], $post->post_title );
     
    12481248        );
    12491249
    1250         // Attempt trashing
     1250        // Attempt trashing.
    12511251        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/media/' . $attachment_id );
    12521252        $response = rest_get_server()->dispatch( $request );
     
    12571257        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    12581258
    1259         // Ensure the post still exists
     1259        // Ensure the post still exists.
    12601260        $post = get_post( $attachment_id );
    12611261        $this->assertNotEmpty( $post );
Note: See TracChangeset for help on using the changeset viewer.