Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php

    r42228 r42343  
    2020    public function test_context_param() {
    2121        // Collection
    22         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );
    23         $response = $this->server->dispatch( $request );
    24         $data = $response->get_data();
     22        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );
     23        $response = $this->server->dispatch( $request );
     24        $data     = $response->get_data();
    2525        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    2626        $this->assertEqualSets( array( 'embed', 'view', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    2727        // Single
    28         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses/publish' );
    29         $response = $this->server->dispatch( $request );
    30         $data = $response->get_data();
     28        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses/publish' );
     29        $response = $this->server->dispatch( $request );
     30        $data     = $response->get_data();
    3131        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    3232        $this->assertEqualSets( array( 'embed', 'view', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     
    3434
    3535    public function test_get_items() {
    36         $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' );
    37         $response = $this->server->dispatch( $request );
    38 
    39         $data = $response->get_data();
     36        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses' );
     37        $response = $this->server->dispatch( $request );
     38
     39        $data     = $response->get_data();
    4040        $statuses = get_post_stati( array( 'public' => true ), 'objects' );
    4141        $this->assertEquals( 1, count( $data ) );
     
    4747        wp_set_current_user( $user_id );
    4848
    49         $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' );
     49        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses' );
    5050        $response = $this->server->dispatch( $request );
    5151
    5252        $data = $response->get_data();
    5353        $this->assertEquals( 6, count( $data ) );
    54         $this->assertEqualSets( array(
    55             'publish',
    56             'private',
    57             'pending',
    58             'draft',
    59             'trash',
    60             'future',
    61         ), array_keys( $data ) );
     54        $this->assertEqualSets(
     55            array(
     56                'publish',
     57                'private',
     58                'pending',
     59                'draft',
     60                'trash',
     61                'future',
     62            ), array_keys( $data )
     63        );
    6264    }
    6365
     
    7981
    8082    public function test_get_item_invalid_status() {
    81         $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/invalid' );
     83        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses/invalid' );
    8284        $response = $this->server->dispatch( $request );
    8385        $this->assertErrorResponse( 'rest_status_invalid', $response, 404 );
     
    8688    public function test_get_item_invalid_access() {
    8789        wp_set_current_user( 0 );
    88         $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/draft' );
     90        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses/draft' );
    8991        $response = $this->server->dispatch( $request );
    9092        $this->assertErrorResponse( 'rest_cannot_read_status', $response, 401 );
     
    9597        wp_set_current_user( $user_id );
    9698
    97         $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/inherit' );
     99        $request  = new WP_REST_Request( 'GET', '/wp/v2/statuses/inherit' );
    98100        $response = $this->server->dispatch( $request );
    99101        $this->assertErrorResponse( 'rest_cannot_read_status', $response, 403 );
     
    101103
    102104    public function test_create_item() {
    103         /** Post statuses can't be created **/
    104         $request = new WP_REST_Request( 'POST', '/wp/v2/statuses' );
     105        /** Post statuses can't be created */
     106        $request  = new WP_REST_Request( 'POST', '/wp/v2/statuses' );
    105107        $response = $this->server->dispatch( $request );
    106108        $this->assertEquals( 404, $response->get_status() );
     
    108110
    109111    public function test_update_item() {
    110         /** Post statuses can't be updated **/
    111         $request = new WP_REST_Request( 'POST', '/wp/v2/statuses/draft' );
     112        /** Post statuses can't be updated */
     113        $request  = new WP_REST_Request( 'POST', '/wp/v2/statuses/draft' );
    112114        $response = $this->server->dispatch( $request );
    113115        $this->assertEquals( 404, $response->get_status() );
     
    115117
    116118    public function test_delete_item() {
    117         /** Post statuses can't be deleted **/
    118         $request = new WP_REST_Request( 'DELETE', '/wp/v2/statuses/draft' );
     119        /** Post statuses can't be deleted */
     120        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/statuses/draft' );
    119121        $response = $this->server->dispatch( $request );
    120122        $this->assertEquals( 404, $response->get_status() );
     
    122124
    123125    public function test_prepare_item() {
    124         $obj = get_post_status_object( 'publish' );
     126        $obj      = get_post_status_object( 'publish' );
    125127        $endpoint = new WP_REST_Post_Statuses_Controller;
    126         $request = new WP_REST_Request;
     128        $request  = new WP_REST_Request;
    127129        $request->set_param( 'context', 'edit' );
    128130        $data = $endpoint->prepare_item_for_response( $obj, $request );
     
    131133
    132134    public function test_get_item_schema() {
    133         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );
    134         $response = $this->server->dispatch( $request );
    135         $data = $response->get_data();
     135        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );
     136        $response   = $this->server->dispatch( $request );
     137        $data       = $response->get_data();
    136138        $properties = $data['schema']['properties'];
    137139        $this->assertEquals( 7, count( $properties ) );
     
    154156        );
    155157
    156         register_rest_field( 'status', 'my_custom_int', array(
    157             'schema'          => $schema,
    158             'get_callback'    => array( $this, 'additional_field_get_callback' ),
    159             'update_callback' => array( $this, 'additional_field_update_callback' ),
    160         ) );
     158        register_rest_field(
     159            'status', 'my_custom_int', array(
     160                'schema'          => $schema,
     161                'get_callback'    => array( $this, 'additional_field_get_callback' ),
     162                'update_callback' => array( $this, 'additional_field_update_callback' ),
     163            )
     164        );
    161165
    162166        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );
    163167
    164168        $response = $this->server->dispatch( $request );
    165         $data = $response->get_data();
     169        $data     = $response->get_data();
    166170
    167171        $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
     
    189193        $this->assertEquals( $status_obj->show_in_admin_all_list, $data['show_in_list'] );
    190194        $this->assertEquals( $status_obj->name, $data['slug'] );
    191         $this->assertEqualSets( array(
    192             'archives',
    193         ), array_keys( $links ) );
     195        $this->assertEqualSets(
     196            array(
     197                'archives',
     198            ), array_keys( $links )
     199        );
    194200    }
    195201
     
    197203        $this->assertEquals( 200, $response->get_status() );
    198204        $data = $response->get_data();
    199         $obj = get_post_status_object( 'publish' );
     205        $obj  = get_post_status_object( 'publish' );
    200206        $this->check_post_status_obj( $obj, $data, $response->get_links() );
    201207    }
Note: See TracChangeset for help on using the changeset viewer.