WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (21 months 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-revisions-controller.php

    r42228 r42343  
    2121        self::$page_id = $factory->post->create( array( 'post_type' => 'page' ) );
    2222
    23         self::$editor_id = $factory->user->create( array(
    24             'role' => 'editor',
    25         ) );
    26         self::$contributor_id = $factory->user->create( array(
    27             'role' => 'contributor',
    28         ) );
    29 
    30         wp_set_current_user( self::$editor_id );
    31         wp_update_post( array( 'post_content' => 'This content is better.', 'ID' => self::$post_id ) );
    32         wp_update_post( array( 'post_content' => 'This content is marvelous.', 'ID' => self::$post_id ) );
     23        self::$editor_id      = $factory->user->create(
     24            array(
     25                'role' => 'editor',
     26            )
     27        );
     28        self::$contributor_id = $factory->user->create(
     29            array(
     30                'role' => 'contributor',
     31            )
     32        );
     33
     34        wp_set_current_user( self::$editor_id );
     35        wp_update_post(
     36            array(
     37                'post_content' => 'This content is better.',
     38                'ID'           => self::$post_id,
     39            )
     40        );
     41        wp_update_post(
     42            array(
     43                'post_content' => 'This content is marvelous.',
     44                'ID'           => self::$post_id,
     45            )
     46        );
    3347        wp_set_current_user( 0 );
    3448    }
     
    4660        parent::setUp();
    4761
    48         $revisions = wp_get_post_revisions( self::$post_id );
    49         $this->revision_1 = array_pop( $revisions );
     62        $revisions          = wp_get_post_revisions( self::$post_id );
     63        $this->revision_1   = array_pop( $revisions );
    5064        $this->revision_id1 = $this->revision_1->ID;
    51         $this->revision_2 = array_pop( $revisions );
     65        $this->revision_2   = array_pop( $revisions );
    5266        $this->revision_id2 = $this->revision_2->ID;
    5367    }
     
    6377    public function test_context_param() {
    6478        // Collection
    65         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    66         $response = $this->server->dispatch( $request );
    67         $data = $response->get_data();
     79        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' );
     80        $response = $this->server->dispatch( $request );
     81        $data     = $response->get_data();
    6882        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    6983        $this->assertEqualSets( array( 'view', 'edit', 'embed' ), $data['endpoints'][0]['args']['context']['enum'] );
    7084        // Single
    71         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_1->ID );
    72         $response = $this->server->dispatch( $request );
    73         $data = $response->get_data();
     85        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_1->ID );
     86        $response = $this->server->dispatch( $request );
     87        $data     = $response->get_data();
    7488        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    7589        $this->assertEqualSets( array( 'view', 'edit', 'embed' ), $data['endpoints'][0]['args']['context']['enum'] );
     
    7892    public function test_get_items() {
    7993        wp_set_current_user( self::$editor_id );
    80         $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    81         $response = $this->server->dispatch( $request );
    82         $data = $response->get_data();
     94        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' );
     95        $response = $this->server->dispatch( $request );
     96        $data     = $response->get_data();
    8397        $this->assertEquals( 200, $response->get_status() );
    8498        $this->assertCount( 2, $data );
     
    94108    public function test_get_items_no_permission() {
    95109        wp_set_current_user( 0 );
    96         $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' );
     110        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    97111        $response = $this->server->dispatch( $request );
    98112
     
    105119    public function test_get_items_missing_parent() {
    106120        wp_set_current_user( self::$editor_id );
    107         $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions' );
     121        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions' );
    108122        $response = $this->server->dispatch( $request );
    109123        $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 );
     
    112126    public function test_get_items_invalid_parent_post_type() {
    113127        wp_set_current_user( self::$editor_id );
    114         $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions' );
     128        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions' );
    115129        $response = $this->server->dispatch( $request );
    116130        $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 );
     
    119133    public function test_get_item() {
    120134        wp_set_current_user( self::$editor_id );
    121         $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
     135        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    122136        $response = $this->server->dispatch( $request );
    123137        $this->assertEquals( 200, $response->get_status() );
     
    137151            'content',
    138152        );
    139         $data = $response->get_data();
     153        $data   = $response->get_data();
    140154        $this->assertEqualSets( $fields, array_keys( $data ) );
    141155        $this->assertSame( self::$editor_id, $data['author'] );
     
    147161        $request->set_param( 'context', 'embed' );
    148162        $response = $this->server->dispatch( $request );
    149         $fields = array(
     163        $fields   = array(
    150164            'author',
    151165            'date',
     
    156170            'excerpt',
    157171        );
    158         $data = $response->get_data();
     172        $data     = $response->get_data();
    159173        $this->assertEqualSets( $fields, array_keys( $data ) );
    160174    }
     
    173187    public function test_get_item_missing_parent() {
    174188        wp_set_current_user( self::$editor_id );
    175         $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions/' . $this->revision_id1 );
     189        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions/' . $this->revision_id1 );
    176190        $response = $this->server->dispatch( $request );
    177191        $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 );
     
    180194    public function test_get_item_invalid_parent_post_type() {
    181195        wp_set_current_user( self::$editor_id );
    182         $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions/' . $this->revision_id1 );
     196        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$page_id . '/revisions/' . $this->revision_id1 );
    183197        $response = $this->server->dispatch( $request );
    184198        $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 );
     
    197211        wp_set_current_user( self::$editor_id );
    198212
    199         $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
     213        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    200214        $response = $this->server->dispatch( $request );
    201215        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
     
    211225    public function test_delete_item_no_permission() {
    212226        wp_set_current_user( self::$contributor_id );
    213         $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
     227        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    214228        $response = $this->server->dispatch( $request );
    215229        $this->assertErrorResponse( 'rest_cannot_read', $response, 403 );
     
    218232    public function test_prepare_item() {
    219233        wp_set_current_user( self::$editor_id );
    220         $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
     234        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    221235        $response = $this->server->dispatch( $request );
    222236        $this->assertEquals( 200, $response->get_status() );
     
    225239
    226240    public function test_get_item_schema() {
    227         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    228         $response = $this->server->dispatch( $request );
    229         $data = $response->get_data();
     241        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' );
     242        $response   = $this->server->dispatch( $request );
     243        $data       = $response->get_data();
    230244        $properties = $data['schema']['properties'];
    231245        $this->assertEquals( 12, count( $properties ) );
     
    245259
    246260    public function test_create_item() {
    247         $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions' );
     261        $request  = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    248262        $response = $this->server->dispatch( $request );
    249263        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
     
    251265
    252266    public function test_update_item() {
    253         $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
     267        $request  = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
    254268        $response = $this->server->dispatch( $request );
    255269        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
     
    265279        );
    266280
    267         register_rest_field( 'post-revision', 'my_custom_int', array(
    268             'schema'          => $schema,
    269             'get_callback'    => array( $this, 'additional_field_get_callback' ),
    270             'update_callback' => array( $this, 'additional_field_update_callback' ),
    271         ) );
     281        register_rest_field(
     282            'post-revision', 'my_custom_int', array(
     283                'schema'          => $schema,
     284                'get_callback'    => array( $this, 'additional_field_get_callback' ),
     285                'update_callback' => array( $this, 'additional_field_update_callback' ),
     286            )
     287        );
    272288
    273289        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/revisions' );
    274290
    275291        $response = $this->server->dispatch( $request );
    276         $data = $response->get_data();
     292        $data     = $response->get_data();
    277293
    278294        $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
     
    300316    protected function check_get_revision_response( $response, $revision ) {
    301317        if ( $response instanceof WP_REST_Response ) {
    302             $links = $response->get_links();
     318            $links    = $response->get_links();
    303319            $response = $response->get_data();
    304320        } else {
     
    329345        $this->assertEquals( $rendered_title, $response['title']['rendered'] );
    330346
    331         $parent = get_post( $revision->post_parent );
     347        $parent            = get_post( $revision->post_parent );
    332348        $parent_controller = new WP_REST_Posts_Controller( $parent->post_type );
    333         $parent_object = get_post_type_object( $parent->post_type );
    334         $parent_base = ! empty( $parent_object->rest_base ) ? $parent_object->rest_base : $parent_object->name;
     349        $parent_object     = get_post_type_object( $parent->post_type );
     350        $parent_base       = ! empty( $parent_object->rest_base ) ? $parent_object->rest_base : $parent_object->name;
    335351        $this->assertEquals( rest_url( '/wp/v2/' . $parent_base . '/' . $revision->post_parent ), $links['parent'][0]['href'] );
    336352    }
     
    341357        $this->server->dispatch( $request );
    342358
    343         $post = get_post();
     359        $post           = get_post();
    344360        $parent_post_id = wp_is_post_revision( $post->ID );
    345361
Note: See TracChangeset for help on using the changeset viewer.