WordPress.org

Make WordPress Core


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

    r41760 r42343  
    1616
    1717    public static function wpSetUpBeforeClass( $factory ) {
    18         self::$administrator = $factory->user->create( array(
    19             'role' => 'administrator',
    20         ) );
    21         self::$subscriber = $factory->user->create( array(
    22             'role' => 'subscriber',
    23         ) );
     18        self::$administrator = $factory->user->create(
     19            array(
     20                'role' => 'administrator',
     21            )
     22        );
     23        self::$subscriber    = $factory->user->create(
     24            array(
     25                'role' => 'subscriber',
     26            )
     27        );
    2428    }
    2529
     
    3741    public function test_context_param() {
    3842        // Collection
    39         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
    40         $response = $this->server->dispatch( $request );
    41         $data = $response->get_data();
     43        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
     44        $response = $this->server->dispatch( $request );
     45        $data     = $response->get_data();
    4246        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    4347        $this->assertEqualSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    4448        // Single
    4549        $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) );
    46         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories/' . $category1 );
    47         $response = $this->server->dispatch( $request );
    48         $data = $response->get_data();
     50        $request   = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories/' . $category1 );
     51        $response  = $this->server->dispatch( $request );
     52        $data      = $response->get_data();
    4953        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    5054        $this->assertEqualSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     
    5256
    5357    public function test_registered_query_params() {
    54         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
    55         $response = $this->server->dispatch( $request );
    56         $data = $response->get_data();
    57         $keys = array_keys( $data['endpoints'][0]['args'] );
     58        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
     59        $response = $this->server->dispatch( $request );
     60        $data     = $response->get_data();
     61        $keys     = array_keys( $data['endpoints'][0]['args'] );
    5862        sort( $keys );
    59         $this->assertEquals( array(
    60             'context',
    61             'exclude',
    62             'hide_empty',
    63             'include',
    64             'order',
    65             'orderby',
    66             'page',
    67             'parent',
    68             'per_page',
    69             'post',
    70             'search',
    71             'slug',
    72             ), $keys );
     63        $this->assertEquals(
     64            array(
     65                'context',
     66                'exclude',
     67                'hide_empty',
     68                'include',
     69                'order',
     70                'orderby',
     71                'page',
     72                'parent',
     73                'per_page',
     74                'post',
     75                'search',
     76                'slug',
     77            ), $keys
     78        );
    7379    }
    7480
    7581    public function test_get_items() {
    76         $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     82        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    7783        $response = $this->server->dispatch( $request );
    7884        $this->check_get_taxonomy_terms_response( $response );
     
    8894
    8995    public function test_get_items_hide_empty_arg() {
    90         $post_id = $this->factory->post->create();
     96        $post_id   = $this->factory->post->create();
    9197        $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) );
    9298        $category2 = $this->factory->category->create( array( 'name' => 'The Be Sharps' ) );
     
    95101        $request->set_param( 'hide_empty', true );
    96102        $response = $this->server->dispatch( $request );
    97         $data = $response->get_data();
     103        $data     = $response->get_data();
    98104        $this->assertEquals( 2, count( $data ) );
    99105        $this->assertEquals( 'Season 5', $data[0]['name'] );
     
    103109        $request->set_param( 'hide_empty', 'false' );
    104110        $response = $this->server->dispatch( $request );
    105         $data = $response->get_data();
     111        $data     = $response->get_data();
    106112        $this->assertEquals( 3, count( $data ) );
    107113    }
     
    129135        $data = $response->get_data();
    130136
    131         $args = array(
     137        $args       = array(
    132138            'hide_empty' => false,
    133139            'parent'     => 0,
     
    159165        $data = $response->get_data();
    160166
    161         $args = array(
     167        $args       = array(
    162168            'hide_empty' => false,
    163169            'parent'     => 0,
     
    185191        $response = $this->server->dispatch( $request );
    186192        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    187         $data = $response->get_data();
     193        $data        = $response->get_data();
    188194        $first_error = array_shift( $data['data']['params'] );
    189195        $this->assertContains( 'page must be greater than or equal to 1', $first_error );
     
    193199        $id1 = $this->factory->category->create();
    194200        $this->factory->category->create();
    195         $id3 = $this->factory->category->create();
     201        $id3     = $this->factory->category->create();
    196202        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    197203        // Orderby=>asc
    198204        $request->set_param( 'include', array( $id3, $id1 ) );
    199205        $response = $this->server->dispatch( $request );
    200         $data = $response->get_data();
     206        $data     = $response->get_data();
    201207        $this->assertEquals( 2, count( $data ) );
    202208        $this->assertEquals( $id1, $data[0]['id'] );
     
    204210        $request->set_param( 'orderby', 'include' );
    205211        $response = $this->server->dispatch( $request );
    206         $data = $response->get_data();
     212        $data     = $response->get_data();
    207213        $this->assertEquals( 2, count( $data ) );
    208214        $this->assertEquals( $id3, $data[0]['id'] );
     
    210216
    211217    public function test_get_items_exclude_query() {
    212         $id1 = $this->factory->category->create();
    213         $id2 = $this->factory->category->create();
    214         $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    215         $response = $this->server->dispatch( $request );
    216         $data = $response->get_data();
     218        $id1      = $this->factory->category->create();
     219        $id2      = $this->factory->category->create();
     220        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     221        $response = $this->server->dispatch( $request );
     222        $data     = $response->get_data();
    217223        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    218224        $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
    219225        $request->set_param( 'exclude', array( $id2 ) );
    220226        $response = $this->server->dispatch( $request );
    221         $data = $response->get_data();
     227        $data     = $response->get_data();
    222228        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    223229        $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     
    258264        $this->factory->category->create( array( 'name' => 'Banana' ) );
    259265        // defaults to orderby=name, order=asc
    260         $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     266        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    261267        $response = $this->server->dispatch( $request );
    262268        $this->assertEquals( 200, $response->get_status() );
     
    281287        $request->set_param( 'order', 'desc' );
    282288        $response = $this->server->dispatch( $request );
    283         $data = $response->get_data();
     289        $data     = $response->get_data();
    284290        $this->assertEquals( 200, $response->get_status() );
    285291        $this->assertEquals( 'Banana', $data[0]['name'] );
     
    297303        $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) );
    298304        $response = $this->server->dispatch( $request );
    299         $data = $response->get_data();
     305        $data     = $response->get_data();
    300306        $this->assertEquals( 200, $response->get_status() );
    301307        $this->assertEquals( 'taco', $data[0]['slug'] );
     
    305311
    306312    protected function post_with_categories() {
    307         $post_id = $this->factory->post->create();
    308         $category1 = $this->factory->category->create( array(
    309             'name' => 'DC',
    310             'description' => 'Purveyor of fine detective comics',
    311         ) );
    312         $category2 = $this->factory->category->create( array(
    313             'name' => 'Marvel',
    314             'description' => 'Home of the Marvel Universe',
    315         ) );
    316         $category3 = $this->factory->category->create( array(
    317             'name' => 'Image',
    318             'description' => 'American independent comic publisher',
    319         ) );
     313        $post_id   = $this->factory->post->create();
     314        $category1 = $this->factory->category->create(
     315            array(
     316                'name'        => 'DC',
     317                'description' => 'Purveyor of fine detective comics',
     318            )
     319        );
     320        $category2 = $this->factory->category->create(
     321            array(
     322                'name'        => 'Marvel',
     323                'description' => 'Home of the Marvel Universe',
     324            )
     325        );
     326        $category3 = $this->factory->category->create(
     327            array(
     328                'name'        => 'Image',
     329                'description' => 'American independent comic publisher',
     330            )
     331        );
    320332        wp_set_object_terms( $post_id, array( $category1, $category2, $category3 ), 'category' );
    321333
     
    384396        $controller = new WP_REST_Terms_Controller( 'batman' );
    385397        $controller->register_routes();
    386         $term1 = $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'batman' ) );
    387         $term2 = $this->factory->term->create( array( 'name' => 'Mask', 'taxonomy' => 'batman' ) );
    388         $this->factory->term->create( array( 'name' => 'Car', 'taxonomy' => 'batman' ) );
     398        $term1 = $this->factory->term->create(
     399            array(
     400                'name'     => 'Cape',
     401                'taxonomy' => 'batman',
     402            )
     403        );
     404        $term2 = $this->factory->term->create(
     405            array(
     406                'name'     => 'Mask',
     407                'taxonomy' => 'batman',
     408            )
     409        );
     410        $this->factory->term->create(
     411            array(
     412                'name'     => 'Car',
     413                'taxonomy' => 'batman',
     414            )
     415        );
    389416        $post_id = $this->factory->post->create();
    390417        wp_set_object_terms( $post_id, array( $term1, $term2 ), 'batman' );
     
    436463    public function test_get_terms_parent_arg() {
    437464        $category1 = $this->factory->category->create( array( 'name' => 'Parent' ) );
    438         $this->factory->category->create( array( 'name' => 'Child', 'parent' => $category1 ) );
     465        $this->factory->category->create(
     466            array(
     467                'name'   => 'Child',
     468                'parent' => $category1,
     469            )
     470        );
    439471        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    440472        $request->set_param( 'parent', $category1 );
    441473        $response = $this->server->dispatch( $request );
    442         $data = $response->get_data();
     474        $data     = $response->get_data();
    443475        $this->assertEquals( 1, count( $data ) );
    444476        $this->assertEquals( 'Child', $data[0]['name'] );
     
    447479    public function test_get_terms_invalid_parent_arg() {
    448480        $category1 = $this->factory->category->create( array( 'name' => 'Parent' ) );
    449         $this->factory->category->create( array( 'name' => 'Child', 'parent' => $category1 ) );
     481        $this->factory->category->create(
     482            array(
     483                'name'   => 'Child',
     484                'parent' => $category1,
     485            )
     486        );
    450487        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    451488        $request->set_param( 'parent', 'invalid-parent' );
     
    456493    public function test_get_terms_private_taxonomy() {
    457494        register_taxonomy( 'robin', 'post', array( 'public' => false ) );
    458         $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin' ) );
    459         $this->factory->term->create( array( 'name' => 'Mask', 'taxonomy' => 'robin' ) );
    460 
    461         $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin' );
     495        $this->factory->term->create(
     496            array(
     497                'name'     => 'Cape',
     498                'taxonomy' => 'robin',
     499            )
     500        );
     501        $this->factory->term->create(
     502            array(
     503                'name'     => 'Mask',
     504                'taxonomy' => 'robin',
     505            )
     506        );
     507
     508        $request  = new WP_REST_Request( 'GET', '/wp/v2/terms/robin' );
    462509        $response = $this->server->dispatch( $request );
    463510        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
     
    465512
    466513    public function test_get_terms_invalid_taxonomy() {
    467         $request = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy' );
     514        $request  = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy' );
    468515        $response = $this->server->dispatch( $request );
    469516        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
     
    473520        // Start of the index + Uncategorized default term
    474521        for ( $i = 0; $i < 49; $i++ ) {
    475             $this->factory->category->create( array(
    476                 'name'   => "Category {$i}",
    477                 ) );
     522            $this->factory->category->create(
     523                array(
     524                    'name' => "Category {$i}",
     525                )
     526            );
    478527        }
    479         $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    480         $response = $this->server->dispatch( $request );
    481         $headers = $response->get_headers();
     528        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     529        $response = $this->server->dispatch( $request );
     530        $headers  = $response->get_headers();
    482531        $this->assertEquals( 50, $headers['X-WP-Total'] );
    483532        $this->assertEquals( 5, $headers['X-WP-TotalPages'] );
    484533        $this->assertCount( 10, $response->get_data() );
    485         $next_link = add_query_arg( array(
    486             'page'    => 2,
    487             ), rest_url( 'wp/v2/categories' ) );
     534        $next_link = add_query_arg(
     535            array(
     536                'page' => 2,
     537            ), rest_url( 'wp/v2/categories' )
     538        );
    488539        $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) );
    489540        $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    490541        // 3rd page
    491         $this->factory->category->create( array(
    492                 'name'   => 'Category 51',
    493                 ) );
     542        $this->factory->category->create(
     543            array(
     544                'name' => 'Category 51',
     545            )
     546        );
    494547        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
    495548        $request->set_param( 'page', 3 );
    496549        $response = $this->server->dispatch( $request );
    497         $headers = $response->get_headers();
     550        $headers  = $response->get_headers();
    498551        $this->assertEquals( 51, $headers['X-WP-Total'] );
    499552        $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
    500553        $this->assertCount( 10, $response->get_data() );
    501         $prev_link = add_query_arg( array(
    502             'page'    => 2,
    503             ), rest_url( 'wp/v2/categories' ) );
     554        $prev_link = add_query_arg(
     555            array(
     556                'page' => 2,
     557            ), rest_url( 'wp/v2/categories' )
     558        );
    504559        $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    505         $next_link = add_query_arg( array(
    506             'page'    => 4,
    507             ), rest_url( 'wp/v2/categories' ) );
     560        $next_link = add_query_arg(
     561            array(
     562                'page' => 4,
     563            ), rest_url( 'wp/v2/categories' )
     564        );
    508565        $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    509566        // Last page
     
    511568        $request->set_param( 'page', 6 );
    512569        $response = $this->server->dispatch( $request );
    513         $headers = $response->get_headers();
     570        $headers  = $response->get_headers();
    514571        $this->assertEquals( 51, $headers['X-WP-Total'] );
    515572        $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
    516573        $this->assertCount( 1, $response->get_data() );
    517         $prev_link = add_query_arg( array(
    518             'page'    => 5,
    519             ), rest_url( 'wp/v2/categories' ) );
     574        $prev_link = add_query_arg(
     575            array(
     576                'page' => 5,
     577            ), rest_url( 'wp/v2/categories' )
     578        );
    520579        $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    521580        $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) );
     
    524583        $request->set_param( 'page', 8 );
    525584        $response = $this->server->dispatch( $request );
    526         $headers = $response->get_headers();
     585        $headers  = $response->get_headers();
    527586        $this->assertEquals( 51, $headers['X-WP-Total'] );
    528587        $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
    529588        $this->assertCount( 0, $response->get_data() );
    530         $prev_link = add_query_arg( array(
    531             'page'    => 6,
    532             ), rest_url( 'wp/v2/categories' ) );
     589        $prev_link = add_query_arg(
     590            array(
     591                'page' => 6,
     592            ), rest_url( 'wp/v2/categories' )
     593        );
    533594        $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    534595        $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) );
     
    538599        // Start of the index + Uncategorized default term
    539600        for ( $i = 0; $i < 17; $i++ ) {
    540             $this->factory->category->create( array(
    541                 'name'   => "Category {$i}",
    542                 ) );
     601            $this->factory->category->create(
     602                array(
     603                    'name' => "Category {$i}",
     604                )
     605            );
    543606        }
    544607        $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     
    546609        $request->set_param( 'per_page', 100 );
    547610        $response = $this->server->dispatch( $request );
    548         $headers = $response->get_headers();
     611        $headers  = $response->get_headers();
    549612        $this->assertEquals( 18, $headers['X-WP-Total'] );
    550613        $this->assertEquals( 1, $headers['X-WP-TotalPages'] );
     
    554617        $request->set_param( 'per_page', 100 );
    555618        $response = $this->server->dispatch( $request );
    556         $headers = $response->get_headers();
     619        $headers  = $response->get_headers();
    557620        $this->assertEquals( 18, $headers['X-WP-Total'] );
    558621        $this->assertEquals( 1, $headers['X-WP-TotalPages'] );
     
    561624
    562625    public function test_get_item() {
    563         $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' );
     626        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/1' );
    564627        $response = $this->server->dispatch( $request );
    565628        $this->check_get_taxonomy_term_response( $response );
     
    567630
    568631    public function test_get_term_invalid_taxonomy() {
    569         $request = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy/1' );
     632        $request  = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy/1' );
    570633        $response = $this->server->dispatch( $request );
    571634        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
     
    573636
    574637    public function test_get_term_invalid_term() {
    575         $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
     638        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    576639        $response = $this->server->dispatch( $request );
    577640        $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
     
    588651    public function test_get_term_private_taxonomy() {
    589652        register_taxonomy( 'robin', 'post', array( 'public' => false ) );
    590         $term1 = $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin' ) );
    591 
    592         $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin/' . $term1 );
     653        $term1 = $this->factory->term->create(
     654            array(
     655                'name'     => 'Cape',
     656                'taxonomy' => 'robin',
     657            )
     658        );
     659
     660        $request  = new WP_REST_Request( 'GET', '/wp/v2/terms/robin/' . $term1 );
    593661        $response = $this->server->dispatch( $request );
    594662        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
     
    597665    public function test_get_item_incorrect_taxonomy() {
    598666        register_taxonomy( 'robin', 'post' );
    599         $term1 = $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin' ) );
    600         $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $term1 );
     667        $term1    = $this->factory->term->create(
     668            array(
     669                'name'     => 'Cape',
     670                'taxonomy' => 'robin',
     671            )
     672        );
     673        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $term1 );
    601674        $response = $this->server->dispatch( $request );
    602675        $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
     
    612685        $this->assertEquals( 201, $response->get_status() );
    613686        $headers = $response->get_headers();
    614         $data = $response->get_data();
     687        $data    = $response->get_data();
    615688        $this->assertContains( '/wp/v2/categories/' . $data['id'], $headers['Location'] );
    616689        $this->assertEquals( 'My Awesome Term', $data['name'] );
     
    652725    public function test_create_item_missing_arguments() {
    653726        wp_set_current_user( self::$administrator );
    654         $request = new WP_REST_Request( 'POST', '/wp/v2/categories' );
     727        $request  = new WP_REST_Request( 'POST', '/wp/v2/categories' );
    655728        $response = $this->server->dispatch( $request );
    656729        $this->assertErrorResponse( 'rest_missing_callback_param', $response, 400 );
     
    659732    public function test_create_item_with_parent() {
    660733        wp_set_current_user( self::$administrator );
    661         $parent = wp_insert_term( 'test-category', 'category' );
     734        $parent  = wp_insert_term( 'test-category', 'category' );
    662735        $request = new WP_REST_Request( 'POST', '/wp/v2/categories' );
    663736        $request->set_param( 'name', 'My Awesome Term' );
     
    686759            'description' => 'Original Description',
    687760            'slug'        => 'original-slug',
    688             );
    689         $term = get_term_by( 'id', $this->factory->category->create( $orig_args ), 'category' );
    690         $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
     761        );
     762        $term      = get_term_by( 'id', $this->factory->category->create( $orig_args ), 'category' );
     763        $request   = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
    691764        $request->set_param( 'name', 'New Name' );
    692765        $request->set_param( 'description', 'New Description' );
     
    718791    public function test_update_item_incorrect_permissions() {
    719792        wp_set_current_user( self::$subscriber );
    720         $term = get_term_by( 'id', $this->factory->category->create(), 'category' );
     793        $term    = get_term_by( 'id', $this->factory->category->create(), 'category' );
    721794        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
    722795        $request->set_param( 'name', 'Incorrect permissions' );
     
    728801        wp_set_current_user( self::$administrator );
    729802        $parent = get_term_by( 'id', $this->factory->category->create(), 'category' );
    730         $term = get_term_by( 'id', $this->factory->category->create(), 'category' );
     803        $term   = get_term_by( 'id', $this->factory->category->create(), 'category' );
    731804
    732805        $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id );
     
    751824    public function test_delete_item() {
    752825        wp_set_current_user( self::$administrator );
    753         $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
     826        $term    = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
    754827        $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
    755828        $request->set_param( 'force', true );
     
    765838        $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
    766839
    767         $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
     840        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
    768841        $response = $this->server->dispatch( $request );
    769842        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
     
    776849    public function test_delete_item_invalid_taxonomy() {
    777850        wp_set_current_user( self::$administrator );
    778         $request = new WP_REST_Request( 'DELETE', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
     851        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    779852        $response = $this->server->dispatch( $request );
    780853        $this->assertErrorResponse( 'rest_no_route', $response, 404 );
     
    783856    public function test_delete_item_invalid_term() {
    784857        wp_set_current_user( self::$administrator );
    785         $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
     858        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    786859        $response = $this->server->dispatch( $request );
    787860        $this->assertErrorResponse( 'rest_term_invalid', $response, 404 );
     
    790863    public function test_delete_item_incorrect_permissions() {
    791864        wp_set_current_user( self::$subscriber );
    792         $term = get_term_by( 'id', $this->factory->category->create(), 'category' );
    793         $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
     865        $term     = get_term_by( 'id', $this->factory->category->create(), 'category' );
     866        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
    794867        $response = $this->server->dispatch( $request );
    795868        $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
     
    799872        $term = get_term( 1, 'category' );
    800873
    801         $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' );
    802         $response = $this->server->dispatch( $request );
    803         $data = $response->get_data();
     874        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/1' );
     875        $response = $this->server->dispatch( $request );
     876        $data     = $response->get_data();
    804877
    805878        $this->check_taxonomy_term( $term, $data, $response->get_links() );
     
    807880
    808881    public function test_prepare_taxonomy_term_child() {
    809         $child = $this->factory->category->create( array(
    810             'parent' => 1,
    811         ) );
    812         $term = get_term( $child, 'category' );
    813 
    814         $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $child );
    815         $response = $this->server->dispatch( $request );
    816         $data = $response->get_data();
     882        $child = $this->factory->category->create(
     883            array(
     884                'parent' => 1,
     885            )
     886        );
     887        $term  = get_term( $child, 'category' );
     888
     889        $request  = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $child );
     890        $response = $this->server->dispatch( $request );
     891        $data     = $response->get_data();
    817892
    818893        $this->check_taxonomy_term( $term, $data, $response->get_links() );
     
    825900
    826901    public function test_get_item_schema() {
    827         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
    828         $response = $this->server->dispatch( $request );
    829         $data = $response->get_data();
     902        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
     903        $response   = $this->server->dispatch( $request );
     904        $data       = $response->get_data();
    830905        $properties = $data['schema']['properties'];
    831906        $this->assertEquals( 9, count( $properties ) );
     
    851926        );
    852927
    853         register_rest_field( 'category', 'my_custom_int', array(
    854             'schema'          => $schema,
    855             'get_callback'    => array( $this, 'additional_field_get_callback' ),
    856         ) );
     928        register_rest_field(
     929            'category', 'my_custom_int', array(
     930                'schema'       => $schema,
     931                'get_callback' => array( $this, 'additional_field_get_callback' ),
     932            )
     933        );
    857934
    858935        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' );
    859936
    860937        $response = $this->server->dispatch( $request );
    861         $data = $response->get_data();
     938        $data     = $response->get_data();
    862939        $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
    863940        $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] );
    864941
    865942        $category_id = $this->factory->category->create();
    866         $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $category_id );
     943        $request     = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $category_id );
    867944
    868945        $response = $this->server->dispatch( $request );
     
    885962    protected function check_get_taxonomy_terms_response( $response ) {
    886963        $this->assertEquals( 200, $response->get_status() );
    887         $data = $response->get_data();
    888         $args = array(
     964        $data       = $response->get_data();
     965        $args       = array(
    889966            'hide_empty' => false,
    890967        );
     
    904981        $this->assertEquals( $term->slug, $data['slug'] );
    905982        $this->assertEquals( $term->description, $data['description'] );
    906         $this->assertEquals( get_term_link( $term ),  $data['link'] );
     983        $this->assertEquals( get_term_link( $term ), $data['link'] );
    907984        $this->assertEquals( $term->count, $data['count'] );
    908985        $taxonomy = get_taxonomy( $term->taxonomy );
     
    9331010        $this->assertEquals( 200, $response->get_status() );
    9341011
    935         $data = $response->get_data();
     1012        $data     = $response->get_data();
    9361013        $category = get_term( 1, 'category' );
    9371014        $this->check_taxonomy_term( $category, $data, $response->get_links() );
Note: See TracChangeset for help on using the changeset viewer.