Make WordPress Core


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

    r42056 r42343  
    2626        self::$post_id = $factory->post->create();
    2727
    28         self::$superadmin_id = $factory->user->create( array(
    29             'role'       => 'administrator',
    30             'user_login' => 'superadmin',
    31         ) );
    32         self::$editor_id = $factory->user->create( array(
    33             'role' => 'editor',
    34         ) );
    35         self::$author_id = $factory->user->create( array(
    36             'role' => 'author',
    37         ) );
    38         self::$contributor_id = $factory->user->create( array(
    39             'role' => 'contributor',
    40         ) );
     28        self::$superadmin_id  = $factory->user->create(
     29            array(
     30                'role'       => 'administrator',
     31                'user_login' => 'superadmin',
     32            )
     33        );
     34        self::$editor_id      = $factory->user->create(
     35            array(
     36                'role' => 'editor',
     37            )
     38        );
     39        self::$author_id      = $factory->user->create(
     40            array(
     41                'role' => 'author',
     42            )
     43        );
     44        self::$contributor_id = $factory->user->create(
     45            array(
     46                'role' => 'contributor',
     47            )
     48        );
    4149
    4250        if ( is_multisite() ) {
     
    6775    public function setUp() {
    6876        parent::setUp();
    69         register_post_type( 'youseeme', array( 'supports' => array(), 'show_in_rest' => true ) );
     77        register_post_type(
     78            'youseeme', array(
     79                'supports'     => array(),
     80                'show_in_rest' => true,
     81            )
     82        );
    7083        add_filter( 'rest_pre_dispatch', array( $this, 'wpSetUpBeforeRequest' ), 10, 3 );
    7184        add_filter( 'posts_clauses', array( $this, 'save_posts_clauses' ), 10, 2 );
     
    108121    public function test_context_param() {
    109122        // Collection
    110         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    111         $response = $this->server->dispatch( $request );
    112         $data = $response->get_data();
     123        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
     124        $response = $this->server->dispatch( $request );
     125        $data     = $response->get_data();
    113126        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    114127        $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    115128        // Single
    116         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id );
    117         $response = $this->server->dispatch( $request );
    118         $data = $response->get_data();
     129        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id );
     130        $response = $this->server->dispatch( $request );
     131        $data     = $response->get_data();
    119132        $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] );
    120133        $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     
    122135
    123136    public function test_registered_query_params() {
    124         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    125         $response = $this->server->dispatch( $request );
    126         $data = $response->get_data();
    127         $keys = array_keys( $data['endpoints'][0]['args'] );
     137        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
     138        $response = $this->server->dispatch( $request );
     139        $data     = $response->get_data();
     140        $keys     = array_keys( $data['endpoints'][0]['args'] );
    128141        sort( $keys );
    129         $this->assertEquals( array(
    130             'after',
    131             'author',
    132             'author_exclude',
    133             'before',
    134             'categories',
    135             'categories_exclude',
    136             'context',
    137             'exclude',
    138             'include',
    139             'offset',
    140             'order',
    141             'orderby',
    142             'page',
    143             'per_page',
    144             'search',
    145             'slug',
    146             'status',
    147             'sticky',
    148             'tags',
    149             'tags_exclude',
    150             ), $keys );
     142        $this->assertEquals(
     143            array(
     144                'after',
     145                'author',
     146                'author_exclude',
     147                'before',
     148                'categories',
     149                'categories_exclude',
     150                'context',
     151                'exclude',
     152                'include',
     153                'offset',
     154                'order',
     155                'orderby',
     156                'page',
     157                'per_page',
     158                'search',
     159                'slug',
     160                'status',
     161                'sticky',
     162                'tags',
     163                'tags_exclude',
     164            ), $keys
     165        );
    151166    }
    152167
    153168    public function test_registered_get_item_params() {
    154         $request = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    155         $response = $this->server->dispatch( $request );
    156         $data = $response->get_data();
    157         $keys = array_keys( $data['endpoints'][0]['args'] );
     169        $request  = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     170        $response = $this->server->dispatch( $request );
     171        $data     = $response->get_data();
     172        $keys     = array_keys( $data['endpoints'][0]['args'] );
    158173        sort( $keys );
    159174        $this->assertEquals( array( 'context', 'id', 'password' ), $keys );
     
    161176
    162177    public function test_get_items() {
    163         $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     178        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    164179        $response = $this->server->dispatch( $request );
    165180
     
    174189    public function test_get_items_empty_query() {
    175190        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    176         $request->set_query_params( array(
    177             'author' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER,
    178         ) );
     191        $request->set_query_params(
     192            array(
     193                'author' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER,
     194            )
     195        );
    179196        $response = $this->server->dispatch( $request );
    180197
     
    187204        $this->factory->post->create( array( 'post_author' => self::$author_id ) );
    188205        // All 3 posts
    189         $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     206        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    190207        $response = $this->server->dispatch( $request );
    191208        $this->assertEquals( 200, $response->get_status() );
     
    213230        $this->factory->post->create( array( 'post_author' => self::$author_id ) );
    214231        // All 3 posts
    215         $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     232        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    216233        $response = $this->server->dispatch( $request );
    217234        $this->assertEquals( 200, $response->get_status() );
     
    245262        $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    246263        $this->factory->post->create( array( 'post_status' => 'publish' ) );
    247         $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     264        $id3     = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    248265        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    249266        // Orderby=>desc
    250267        $request->set_param( 'include', array( $id1, $id3 ) );
    251268        $response = $this->server->dispatch( $request );
    252         $data = $response->get_data();
     269        $data     = $response->get_data();
    253270        $this->assertEquals( 2, count( $data ) );
    254271        $this->assertEquals( $id3, $data[0]['id'] );
     
    257274        $request->set_param( 'orderby', 'include' );
    258275        $response = $this->server->dispatch( $request );
    259         $data = $response->get_data();
     276        $data     = $response->get_data();
    260277        $this->assertEquals( 2, count( $data ) );
    261278        $this->assertEquals( $id1, $data[0]['id'] );
     
    269286
    270287    public function test_get_items_orderby_author_query() {
    271         $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id ) );
    272         $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id ) );
    273         $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$author_id ) );
     288        $id2 = $this->factory->post->create(
     289            array(
     290                'post_status' => 'publish',
     291                'post_author' => self::$editor_id,
     292            )
     293        );
     294        $id3 = $this->factory->post->create(
     295            array(
     296                'post_status' => 'publish',
     297                'post_author' => self::$editor_id,
     298            )
     299        );
     300        $id1 = $this->factory->post->create(
     301            array(
     302                'post_status' => 'publish',
     303                'post_author' => self::$author_id,
     304            )
     305        );
    274306
    275307        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     
    278310
    279311        $response = $this->server->dispatch( $request );
    280         $data = $response->get_data();
     312        $data     = $response->get_data();
    281313
    282314        $this->assertEquals( 200, $response->get_status() );
     
    302334
    303335        $response = $this->server->dispatch( $request );
    304         $data = $response->get_data();
     336        $data     = $response->get_data();
    305337
    306338        $this->assertEquals( 200, $response->get_status() );
     
    313345
    314346    public function test_get_items_orderby_parent_query() {
    315         $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) );
    316         $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) );
    317         $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', 'post_parent' => $id1 ) );
     347        $id1 = $this->factory->post->create(
     348            array(
     349                'post_status' => 'publish',
     350                'post_type'   => 'page',
     351            )
     352        );
     353        $id2 = $this->factory->post->create(
     354            array(
     355                'post_status' => 'publish',
     356                'post_type'   => 'page',
     357            )
     358        );
     359        $id3 = $this->factory->post->create(
     360            array(
     361                'post_status' => 'publish',
     362                'post_type'   => 'page',
     363                'post_parent' => $id1,
     364            )
     365        );
    318366
    319367        $request = new WP_REST_Request( 'GET', '/wp/v2/pages' );
     
    322370
    323371        $response = $this->server->dispatch( $request );
    324         $data = $response->get_data();
     372        $data     = $response->get_data();
    325373
    326374        $this->assertEquals( 200, $response->get_status() );
     
    335383
    336384    public function test_get_items_exclude_query() {
    337         $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    338         $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    339         $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    340         $response = $this->server->dispatch( $request );
    341         $data = $response->get_data();
     385        $id1      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     386        $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     387        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     388        $response = $this->server->dispatch( $request );
     389        $data     = $response->get_data();
    342390        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    343391        $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     
    345393        $request->set_param( 'exclude', array( $id2 ) );
    346394        $response = $this->server->dispatch( $request );
    347         $data = $response->get_data();
     395        $data     = $response->get_data();
    348396        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    349397        $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     
    351399        $request->set_param( 'exclude', "$id2" );
    352400        $response = $this->server->dispatch( $request );
    353         $data = $response->get_data();
     401        $data     = $response->get_data();
    354402        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    355403        $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     
    364412            $this->factory->post->create( array( 'post_status' => 'publish' ) );
    365413        }
    366         $this->factory->post->create( array( 'post_title' => 'Search Result', 'post_status' => 'publish' ) );
    367         $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     414        $this->factory->post->create(
     415            array(
     416                'post_title'  => 'Search Result',
     417                'post_status' => 'publish',
     418            )
     419        );
     420        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    368421        $response = $this->server->dispatch( $request );
    369422        $this->assertEquals( 7, count( $response->get_data() ) );
     
    371424        $request->set_param( 'search', 'Search Result' );
    372425        $response = $this->server->dispatch( $request );
    373         $data = $response->get_data();
     426        $data     = $response->get_data();
    374427        $this->assertEquals( 1, count( $data ) );
    375428        $this->assertEquals( 'Search Result', $data[0]['title']['rendered'] );
     
    377430
    378431    public function test_get_items_slug_query() {
    379         $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) );
    380         $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) );
     432        $this->factory->post->create(
     433            array(
     434                'post_title'  => 'Apple',
     435                'post_status' => 'publish',
     436            )
     437        );
     438        $this->factory->post->create(
     439            array(
     440                'post_title'  => 'Banana',
     441                'post_status' => 'publish',
     442            )
     443        );
    381444        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    382445        $request->set_param( 'slug', 'apple' );
     
    389452
    390453    public function test_get_items_multiple_slugs_array_query() {
    391         $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) );
    392         $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) );
    393         $this->factory->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish' ) );
     454        $this->factory->post->create(
     455            array(
     456                'post_title'  => 'Apple',
     457                'post_status' => 'publish',
     458            )
     459        );
     460        $this->factory->post->create(
     461            array(
     462                'post_title'  => 'Banana',
     463                'post_status' => 'publish',
     464            )
     465        );
     466        $this->factory->post->create(
     467            array(
     468                'post_title'  => 'Peach',
     469                'post_status' => 'publish',
     470            )
     471        );
    394472        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    395473        $request->set_param( 'slug', array( 'banana', 'peach' ) );
     
    407485
    408486    public function test_get_items_multiple_slugs_string_query() {
    409         $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) );
    410         $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) );
    411         $this->factory->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish' ) );
     487        $this->factory->post->create(
     488            array(
     489                'post_title'  => 'Apple',
     490                'post_status' => 'publish',
     491            )
     492        );
     493        $this->factory->post->create(
     494            array(
     495                'post_title'  => 'Banana',
     496                'post_status' => 'publish',
     497            )
     498        );
     499        $this->factory->post->create(
     500            array(
     501                'post_title'  => 'Peach',
     502                'post_status' => 'publish',
     503            )
     504        );
    412505        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    413506        $request->set_param( 'slug', 'apple,banana' );
     
    507600
    508601    public function test_get_items_status_without_permissions() {
    509         $draft_id = $this->factory->post->create( array(
    510             'post_status' => 'draft',
    511         ) );
     602        $draft_id = $this->factory->post->create(
     603            array(
     604                'post_status' => 'draft',
     605            )
     606        );
    512607        wp_set_current_user( 0 );
    513608
    514         $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     609        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    515610        $response = $this->server->dispatch( $request );
    516611
     
    524619
    525620    public function test_get_items_order_and_orderby() {
    526         $this->factory->post->create( array( 'post_title' => 'Apple Pie', 'post_status' => 'publish' ) );
    527         $this->factory->post->create( array( 'post_title' => 'Apple Sauce', 'post_status' => 'publish' ) );
    528         $this->factory->post->create( array( 'post_title' => 'Apple Cobbler', 'post_status' => 'publish' ) );
    529         $this->factory->post->create( array( 'post_title' => 'Apple Coffee Cake', 'post_status' => 'publish' ) );
     621        $this->factory->post->create(
     622            array(
     623                'post_title'  => 'Apple Pie',
     624                'post_status' => 'publish',
     625            )
     626        );
     627        $this->factory->post->create(
     628            array(
     629                'post_title'  => 'Apple Sauce',
     630                'post_status' => 'publish',
     631            )
     632        );
     633        $this->factory->post->create(
     634            array(
     635                'post_title'  => 'Apple Cobbler',
     636                'post_status' => 'publish',
     637            )
     638        );
     639        $this->factory->post->create(
     640            array(
     641                'post_title'  => 'Apple Coffee Cake',
     642                'post_status' => 'publish',
     643            )
     644        );
    530645        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    531646        $request->set_param( 'search', 'Apple' );
     
    533648        $request->set_param( 'orderby', 'title' );
    534649        $response = $this->server->dispatch( $request );
    535         $data = $response->get_data();
     650        $data     = $response->get_data();
    536651        $this->assertEquals( 'Apple Sauce', $data[0]['title']['rendered'] );
    537652        $this->assertPostsOrderedBy( '{posts}.post_title DESC' );
     
    539654        $request->set_param( 'order', 'asc' );
    540655        $response = $this->server->dispatch( $request );
    541         $data = $response->get_data();
     656        $data     = $response->get_data();
    542657        $this->assertEquals( 'Apple Cobbler', $data[0]['title']['rendered'] );
    543658        $this->assertPostsOrderedBy( '{posts}.post_title ASC' );
     
    564679
    565680    public function test_get_items_with_orderby_id() {
    566         $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-13 02:26:48' ) );
    567         $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-12 02:26:48' ) );
    568         $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-11 02:26:48' ) );
     681        $id1 = $this->factory->post->create(
     682            array(
     683                'post_status' => 'publish',
     684                'post_date'   => '2016-01-13 02:26:48',
     685            )
     686        );
     687        $id2 = $this->factory->post->create(
     688            array(
     689                'post_status' => 'publish',
     690                'post_date'   => '2016-01-12 02:26:48',
     691            )
     692        );
     693        $id3 = $this->factory->post->create(
     694            array(
     695                'post_status' => 'publish',
     696                'post_date'   => '2016-01-11 02:26:48',
     697            )
     698        );
    569699
    570700        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     
    573703
    574704        $response = $this->server->dispatch( $request );
    575         $data = $response->get_data();
     705        $data     = $response->get_data();
    576706
    577707        // Default ORDER is DESC.
     
    583713
    584714    public function test_get_items_with_orderby_slug() {
    585         $id1 = $this->factory->post->create( array( 'post_title' => 'ABC', 'post_name' => 'xyz', 'post_status' => 'publish' ) );
    586         $id2 = $this->factory->post->create( array( 'post_title' => 'XYZ', 'post_name' => 'abc', 'post_status' => 'publish' ) );
     715        $id1 = $this->factory->post->create(
     716            array(
     717                'post_title'  => 'ABC',
     718                'post_name'   => 'xyz',
     719                'post_status' => 'publish',
     720            )
     721        );
     722        $id2 = $this->factory->post->create(
     723            array(
     724                'post_title'  => 'XYZ',
     725                'post_name'   => 'abc',
     726                'post_status' => 'publish',
     727            )
     728        );
    587729
    588730        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     
    591733
    592734        $response = $this->server->dispatch( $request );
    593         $data = $response->get_data();
     735        $data     = $response->get_data();
    594736
    595737        // Default ORDER is DESC.
     
    602744        $slugs = array( 'burrito', 'taco', 'chalupa' );
    603745        foreach ( $slugs as $slug ) {
    604             $this->factory->post->create( array( 'post_title' => $slug, 'post_name' => $slug, 'post_status' => 'publish' ) );
     746            $this->factory->post->create(
     747                array(
     748                    'post_title'  => $slug,
     749                    'post_name'   => $slug,
     750                    'post_status' => 'publish',
     751                )
     752            );
    605753        }
    606754
     
    610758
    611759        $response = $this->server->dispatch( $request );
    612         $data = $response->get_data();
     760        $data     = $response->get_data();
    613761
    614762        $this->assertEquals( 'taco', $data[0]['slug'] );
     
    618766
    619767    public function test_get_items_with_orderby_relevance() {
    620         $id1 = $this->factory->post->create( array( 'post_title' => 'Title is more relevant', 'post_content' => 'Content is', 'post_status' => 'publish' ) );
    621         $id2 = $this->factory->post->create( array( 'post_title' => 'Title is', 'post_content' => 'Content is less relevant', 'post_status' => 'publish' ) );
     768        $id1     = $this->factory->post->create(
     769            array(
     770                'post_title'   => 'Title is more relevant',
     771                'post_content' => 'Content is',
     772                'post_status'  => 'publish',
     773            )
     774        );
     775        $id2     = $this->factory->post->create(
     776            array(
     777                'post_title'   => 'Title is',
     778                'post_content' => 'Content is less relevant',
     779                'post_status'  => 'publish',
     780            )
     781        );
    622782        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    623783        $request->set_param( 'orderby', 'relevance' );
     
    633793
    634794    public function test_get_items_with_orderby_relevance_two_terms() {
    635         $id1 = $this->factory->post->create( array( 'post_title' => 'Title is more relevant', 'post_content' => 'Content is', 'post_status' => 'publish' ) );
    636         $id2 = $this->factory->post->create( array( 'post_title' => 'Title is', 'post_content' => 'Content is less relevant', 'post_status' => 'publish' ) );
     795        $id1     = $this->factory->post->create(
     796            array(
     797                'post_title'   => 'Title is more relevant',
     798                'post_content' => 'Content is',
     799                'post_status'  => 'publish',
     800            )
     801        );
     802        $id2     = $this->factory->post->create(
     803            array(
     804                'post_title'   => 'Title is',
     805                'post_content' => 'Content is less relevant',
     806                'post_status'  => 'publish',
     807            )
     808        );
    637809        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    638810        $request->set_param( 'orderby', 'relevance' );
     
    655827
    656828    public function test_get_items_offset_query() {
    657         $id1 = self::$post_id;
    658         $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    659         $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    660         $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     829        $id1     = self::$post_id;
     830        $id2     = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     831        $id3     = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     832        $id4     = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    661833        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    662834        $request->set_param( 'offset', 1 );
     
    689861
    690862        $response = $this->server->dispatch( $request );
    691         $data = $response->get_data();
     863        $data     = $response->get_data();
    692864        $this->assertCount( 1, $data );
    693865        $this->assertEquals( $id1, $data[0]['id'] );
     
    706878
    707879        $response = $this->server->dispatch( $request );
    708         $data = $response->get_data();
     880        $data     = $response->get_data();
    709881        $this->assertCount( 3, $data );
    710882        $this->assertEquals( $id4, $data[0]['id'] );
     
    714886
    715887    public function test_get_items_tags_and_categories_query() {
    716         $id1 = self::$post_id;
    717         $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    718         $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    719         $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    720         $tag = wp_insert_term( 'My Tag', 'post_tag' );
     888        $id1      = self::$post_id;
     889        $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     890        $id3      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     891        $id4      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     892        $tag      = wp_insert_term( 'My Tag', 'post_tag' );
    721893        $category = wp_insert_term( 'My Category', 'category' );
    722894
     
    738910
    739911    public function test_get_items_tags_and_categories_exclude_query() {
    740         $id1 = self::$post_id;
    741         $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    742         $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    743         $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    744         $tag = wp_insert_term( 'My Tag', 'post_tag' );
     912        $id1      = self::$post_id;
     913        $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     914        $id3      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     915        $id4      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     916        $tag      = wp_insert_term( 'My Tag', 'post_tag' );
    745917        $category = wp_insert_term( 'My Category', 'category' );
    746918
     
    754926
    755927        $response = $this->server->dispatch( $request );
    756         $data = $response->get_data();
     928        $data     = $response->get_data();
    757929        $this->assertCount( 1, $data );
    758930        $this->assertEquals( $id2, $data[0]['id'] );
     
    776948
    777949        $posts = $response->get_data();
    778         $post = $posts[0];
     950        $post  = $posts[0];
    779951        $this->assertEquals( $id2, $post['id'] );
    780952
     
    815987
    816988        $posts = $response->get_data();
    817         $post = $posts[0];
     989        $post  = $posts[0];
    818990        $this->assertEquals( $id1, $post['id'] );
    819991
     
    8711043
    8721044        $posts = $response->get_data();
    873         $post = $posts[0];
     1045        $post  = $posts[0];
    8741046        $this->assertEquals( $id1, $post['id'] );
    8751047
     
    8921064
    8931065        $posts = $response->get_data();
    894         $post = $posts[0];
     1066        $post  = $posts[0];
    8951067        $this->assertEquals( $id1, $post['id'] );
    8961068
     
    9131085
    9141086        $posts = $response->get_data();
    915         $ids = wp_list_pluck( $posts, 'id' );
     1087        $ids   = wp_list_pluck( $posts, 'id' );
    9161088        sort( $ids );
    9171089        $this->assertEquals( array( $id1, $id2 ), $ids );
     
    9231095        // Start of the index
    9241096        for ( $i = 0; $i < 49; $i++ ) {
    925             $this->factory->post->create( array(
    926                 'post_title'   => "Post {$i}",
    927                 ) );
     1097            $this->factory->post->create(
     1098                array(
     1099                    'post_title' => "Post {$i}",
     1100                )
     1101            );
    9281102        }
    929         $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    930         $response = $this->server->dispatch( $request );
    931         $headers = $response->get_headers();
     1103        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1104        $response = $this->server->dispatch( $request );
     1105        $headers  = $response->get_headers();
    9321106        $this->assertEquals( 50, $headers['X-WP-Total'] );
    9331107        $this->assertEquals( 5, $headers['X-WP-TotalPages'] );
    934         $next_link = add_query_arg( array(
    935             'page'    => 2,
    936             ), rest_url( '/wp/v2/posts' ) );
     1108        $next_link = add_query_arg(
     1109            array(
     1110                'page' => 2,
     1111            ), rest_url( '/wp/v2/posts' )
     1112        );
    9371113        $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) );
    9381114        $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    9391115        // 3rd page
    940         $this->factory->post->create( array(
    941                 'post_title'   => 'Post 51',
    942                 ) );
     1116        $this->factory->post->create(
     1117            array(
     1118                'post_title' => 'Post 51',
     1119            )
     1120        );
    9431121        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    9441122        $request->set_param( 'page', 3 );
    9451123        $response = $this->server->dispatch( $request );
    946         $headers = $response->get_headers();
     1124        $headers  = $response->get_headers();
    9471125        $this->assertEquals( 51, $headers['X-WP-Total'] );
    9481126        $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
    949         $prev_link = add_query_arg( array(
    950             'page'    => 2,
    951             ), rest_url( '/wp/v2/posts' ) );
     1127        $prev_link = add_query_arg(
     1128            array(
     1129                'page' => 2,
     1130            ), rest_url( '/wp/v2/posts' )
     1131        );
    9521132        $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    953         $next_link = add_query_arg( array(
    954             'page'    => 4,
    955             ), rest_url( '/wp/v2/posts' ) );
     1133        $next_link = add_query_arg(
     1134            array(
     1135                'page' => 4,
     1136            ), rest_url( '/wp/v2/posts' )
     1137        );
    9561138        $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    9571139        // Last page
     
    9591141        $request->set_param( 'page', 6 );
    9601142        $response = $this->server->dispatch( $request );
    961         $headers = $response->get_headers();
     1143        $headers  = $response->get_headers();
    9621144        $this->assertEquals( 51, $headers['X-WP-Total'] );
    9631145        $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
    964         $prev_link = add_query_arg( array(
    965             'page'    => 5,
    966             ), rest_url( '/wp/v2/posts' ) );
     1146        $prev_link = add_query_arg(
     1147            array(
     1148                'page' => 5,
     1149            ), rest_url( '/wp/v2/posts' )
     1150        );
    9671151        $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    9681152        $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) );
     
    9721156        $request->set_param( 'page', 8 );
    9731157        $response = $this->server->dispatch( $request );
    974         $headers = $response->get_headers();
     1158        $headers  = $response->get_headers();
    9751159        $this->assertErrorResponse( 'rest_post_invalid_page_number', $response, 400 );
    9761160
    9771161        // With query params.
    9781162        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    979         $request->set_query_params( array( 'per_page' => 5, 'page' => 2 ) );
    980         $response = $this->server->dispatch( $request );
    981         $headers = $response->get_headers();
     1163        $request->set_query_params(
     1164            array(
     1165                'per_page' => 5,
     1166                'page'     => 2,
     1167            )
     1168        );
     1169        $response = $this->server->dispatch( $request );
     1170        $headers  = $response->get_headers();
    9821171        $this->assertEquals( 51, $headers['X-WP-Total'] );
    9831172        $this->assertEquals( 11, $headers['X-WP-TotalPages'] );
    984         $prev_link = add_query_arg( array(
    985             'per_page' => 5,
    986             'page'     => 1,
    987             ), rest_url( '/wp/v2/posts' ) );
     1173        $prev_link = add_query_arg(
     1174            array(
     1175                'per_page' => 5,
     1176                'page'     => 1,
     1177            ), rest_url( '/wp/v2/posts' )
     1178        );
    9881179        $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    989         $next_link = add_query_arg( array(
    990             'per_page' => 5,
    991             'page'     => 3,
    992             ), rest_url( '/wp/v2/posts' ) );
     1180        $next_link = add_query_arg(
     1181            array(
     1182                'per_page' => 5,
     1183                'page'     => 3,
     1184            ), rest_url( '/wp/v2/posts' )
     1185        );
    9931186        $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    9941187    }
     
    9981191        wp_set_current_user( 0 );
    9991192        $draft_id = $this->factory->post->create( array( 'post_status' => 'draft' ) );
    1000         $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1193        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    10011194        $request->set_param( 'status', 'draft' );
    10021195        $response = $this->server->dispatch( $request );
     
    10061199        wp_set_current_user( self::$editor_id );
    10071200        $response = $this->server->dispatch( $request );
    1008         $data = $response->get_data();
     1201        $data     = $response->get_data();
    10091202        $this->assertCount( 1, $data );
    10101203        $this->assertEquals( $draft_id, $data[0]['id'] );
     
    10531246        $request->set_param( 'before', '2016-01-17T00:00:00Z' );
    10541247        $response = $this->server->dispatch( $request );
    1055         $data = $response->get_data();
     1248        $data     = $response->get_data();
    10561249        $this->assertCount( 1, $data );
    10571250        $this->assertEquals( $post2, $data[0]['id'] );
     
    10591252
    10601253    public function test_get_items_all_post_formats() {
    1061         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    1062         $response = $this->server->dispatch( $request );
    1063         $data = $response->get_data();
     1254        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
     1255        $response = $this->server->dispatch( $request );
     1256        $data     = $response->get_data();
    10641257
    10651258        $formats = array_values( get_post_format_slugs() );
     
    10691262
    10701263    public function test_get_item() {
    1071         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1264        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    10721265        $response = $this->server->dispatch( $request );
    10731266
     
    10761269
    10771270    public function test_get_item_links() {
    1078         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1271        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    10791272        $response = $this->server->dispatch( $request );
    10801273
     
    10971290
    10981291        $term_links = $links['https://api.w.org/term'];
    1099         $tag_link = $cat_link = $format_link = null;
     1292        $tag_link   = $cat_link = $format_link = null;
    11001293        foreach ( $term_links as $link ) {
    11011294            if ( 'post_tag' === $link['attributes']['taxonomy'] ) {
     
    11191312
    11201313    public function test_get_item_links_no_author() {
    1121         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1122         $response = $this->server->dispatch( $request );
    1123         $links = $response->get_links();
     1314        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1315        $response = $this->server->dispatch( $request );
     1316        $links    = $response->get_links();
    11241317        $this->assertFalse( isset( $links['author'] ) );
    1125         wp_update_post( array( 'ID' => self::$post_id, 'post_author' => self::$author_id ) );
    1126         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1127         $response = $this->server->dispatch( $request );
    1128         $links = $response->get_links();
     1318        wp_update_post(
     1319            array(
     1320                'ID'          => self::$post_id,
     1321                'post_author' => self::$author_id,
     1322            )
     1323        );
     1324        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1325        $response = $this->server->dispatch( $request );
     1326        $links    = $response->get_links();
    11291327        $this->assertEquals( rest_url( '/wp/v2/users/' . self::$author_id ), $links['author'][0]['href'] );
    11301328    }
    11311329
    11321330    public function test_get_post_without_permission() {
    1133         $draft_id = $this->factory->post->create( array(
    1134             'post_status' => 'draft',
    1135         ) );
     1331        $draft_id = $this->factory->post->create(
     1332            array(
     1333                'post_status' => 'draft',
     1334            )
     1335        );
    11361336        wp_set_current_user( 0 );
    11371337
    1138         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $draft_id ) );
     1338        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $draft_id ) );
    11391339        $response = $this->server->dispatch( $request );
    11401340
     
    11431343
    11441344    public function test_get_post_invalid_id() {
    1145         $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
     1345        $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    11461346        $response = $this->server->dispatch( $request );
    11471347
     
    11511351    public function test_get_post_list_context_with_permission() {
    11521352        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    1153         $request->set_query_params( array(
    1154             'context' => 'edit',
    1155         ) );
     1353        $request->set_query_params(
     1354            array(
     1355                'context' => 'edit',
     1356            )
     1357        );
    11561358
    11571359        wp_set_current_user( self::$editor_id );
     
    11651367        wp_set_current_user( 0 );
    11661368        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    1167         $request->set_query_params( array(
    1168             'context' => 'edit',
    1169         ) );
     1369        $request->set_query_params(
     1370            array(
     1371                'context' => 'edit',
     1372            )
     1373        );
    11701374        $response = $this->server->dispatch( $request );
    11711375
     
    11761380        wp_set_current_user( 0 );
    11771381        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1178         $request->set_query_params( array(
    1179             'context' => 'edit',
    1180         ) );
     1382        $request->set_query_params(
     1383            array(
     1384                'context' => 'edit',
     1385            )
     1386        );
    11811387        $response = $this->server->dispatch( $request );
    11821388
     
    11851391
    11861392    public function test_get_post_with_password() {
    1187         $post_id = $this->factory->post->create( array(
    1188             'post_password' => '$inthebananastand',
    1189         ) );
    1190 
    1191         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
     1393        $post_id = $this->factory->post->create(
     1394            array(
     1395                'post_password' => '$inthebananastand',
     1396            )
     1397        );
     1398
     1399        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    11921400        $response = $this->server->dispatch( $request );
    11931401
     
    12021410
    12031411    public function test_get_post_with_password_using_password() {
    1204         $post_id = $this->factory->post->create( array(
    1205             'post_password' => '$inthebananastand',
    1206             'post_content'  => 'Some secret content.',
    1207             'post_excerpt'  => 'Some secret excerpt.',
    1208         ) );
    1209 
    1210         $post = get_post( $post_id );
     1412        $post_id = $this->factory->post->create(
     1413            array(
     1414                'post_password' => '$inthebananastand',
     1415                'post_content'  => 'Some secret content.',
     1416                'post_excerpt'  => 'Some secret excerpt.',
     1417            )
     1418        );
     1419
     1420        $post    = get_post( $post_id );
    12111421        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    12121422        $request->set_param( 'password', '$inthebananastand' );
     
    12231433
    12241434    public function test_get_post_with_password_using_incorrect_password() {
    1225         $post_id = $this->factory->post->create( array(
    1226             'post_password' => '$inthebananastand',
    1227         ) );
    1228 
    1229         $post = get_post( $post_id );
     1435        $post_id = $this->factory->post->create(
     1436            array(
     1437                'post_password' => '$inthebananastand',
     1438            )
     1439        );
     1440
     1441        $post    = get_post( $post_id );
    12301442        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    12311443        $request->set_param( 'password', 'wrongpassword' );
     
    12361448
    12371449    public function test_get_post_with_password_without_permission() {
    1238         $post_id = $this->factory->post->create( array(
    1239             'post_password' => '$inthebananastand',
    1240             'post_content'  => 'Some secret content.',
    1241             'post_excerpt'  => 'Some secret excerpt.',
    1242         ) );
    1243         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    1244         $response = $this->server->dispatch( $request );
    1245         $data = $response->get_data();
     1450        $post_id  = $this->factory->post->create(
     1451            array(
     1452                'post_password' => '$inthebananastand',
     1453                'post_content'  => 'Some secret content.',
     1454                'post_excerpt'  => 'Some secret excerpt.',
     1455            )
     1456        );
     1457        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
     1458        $response = $this->server->dispatch( $request );
     1459        $data     = $response->get_data();
    12461460        $this->check_get_post_response( $response, 'view' );
    12471461        $this->assertEquals( '', $data['content']['rendered'] );
     
    12551469        register_post_status( 'testprivtatus', array( 'public' => false ) );
    12561470        // Public status
    1257         wp_update_post( array( 'ID' => self::$post_id, 'post_status' => 'testpubstatus' ) );
    1258         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1471        wp_update_post(
     1472            array(
     1473                'ID'          => self::$post_id,
     1474                'post_status' => 'testpubstatus',
     1475            )
     1476        );
     1477        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    12591478        $response = $this->server->dispatch( $request );
    12601479        $this->assertEquals( 200, $response->get_status() );
    12611480        // Private status
    1262         wp_update_post( array( 'ID' => self::$post_id, 'post_status' => 'testprivtatus' ) );
    1263         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1481        wp_update_post(
     1482            array(
     1483                'ID'          => self::$post_id,
     1484                'post_status' => 'testprivtatus',
     1485            )
     1486        );
     1487        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    12641488        $response = $this->server->dispatch( $request );
    12651489        $this->assertEquals( 403, $response->get_status() );
     
    12981522
    12991523        $cases_short = array(
    1300             'set date without timezone' => array(
     1524            'set date without timezone'     => array(
    13011525                'statuses' => $all_statuses,
    13021526                'params'   => array(
     
    13041528                    'date'            => '2016-12-12T14:00:00',
    13051529                ),
    1306                 'results' => array(
    1307                     'date'            => '2016-12-12T14:00:00',
    1308                     'date_gmt'        => '2016-12-12T19:00:00',
     1530                'results'  => array(
     1531                    'date'     => '2016-12-12T14:00:00',
     1532                    'date_gmt' => '2016-12-12T19:00:00',
    13091533                ),
    13101534            ),
     
    13151539                    'date_gmt'        => '2016-12-12T19:00:00',
    13161540                ),
    1317                 'results' => array(
    1318                     'date'            => '2016-12-12T14:00:00',
    1319                     'date_gmt'        => '2016-12-12T19:00:00',
     1541                'results'  => array(
     1542                    'date'     => '2016-12-12T14:00:00',
     1543                    'date_gmt' => '2016-12-12T19:00:00',
    13201544                ),
    13211545            ),
    1322             'set date with timezone' => array(
     1546            'set date with timezone'        => array(
    13231547                'statuses' => array( 'draft', 'publish' ),
    13241548                'params'   => array(
     
    13261550                    'date'            => '2016-12-12T18:00:00-01:00',
    13271551                ),
    1328                 'results' => array(
    1329                     'date'            => '2016-12-12T14:00:00',
    1330                     'date_gmt'        => '2016-12-12T19:00:00',
     1552                'results'  => array(
     1553                    'date'     => '2016-12-12T14:00:00',
     1554                    'date_gmt' => '2016-12-12T19:00:00',
    13311555                ),
    13321556            ),
    1333             'set date_gmt with timezone' => array(
     1557            'set date_gmt with timezone'    => array(
    13341558                'statuses' => array( 'draft', 'publish' ),
    13351559                'params'   => array(
     
    13371561                    'date_gmt'        => '2016-12-12T18:00:00-01:00',
    13381562                ),
    1339                 'results' => array(
    1340                     'date'            => '2016-12-12T14:00:00',
    1341                     'date_gmt'        => '2016-12-12T19:00:00',
     1563                'results'  => array(
     1564                    'date'     => '2016-12-12T14:00:00',
     1565                    'date_gmt' => '2016-12-12T19:00:00',
    13421566                ),
    13431567            ),
     
    14001624        // reregister the route as we now have a template available.
    14011625        $GLOBALS['wp_rest_server']->override_by_default = true;
    1402         $controller = new WP_REST_Posts_Controller( 'post' );
     1626        $controller                                     = new WP_REST_Posts_Controller( 'post' );
    14031627        $controller->register_routes();
    14041628        $GLOBALS['wp_rest_server']->override_by_default = false;
    14051629
    14061630        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1407         $params = $this->set_post_data( array(
    1408             'template' => 'post-my-test-template.php',
    1409         ) );
    1410         $request->set_body_params( $params );
    1411         $response = $this->server->dispatch( $request );
    1412 
    1413         $data = $response->get_data();
     1631        $params  = $this->set_post_data(
     1632            array(
     1633                'template' => 'post-my-test-template.php',
     1634            )
     1635        );
     1636        $request->set_body_params( $params );
     1637        $response = $this->server->dispatch( $request );
     1638
     1639        $data          = $response->get_data();
    14141640        $post_template = get_page_template_slug( get_post( $data['id'] ) );
    14151641
     
    14271653
    14281654        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1429         $params = $this->set_post_data( array(
    1430             'template' => 'post-my-test-template.php',
    1431         ) );
     1655        $params  = $this->set_post_data(
     1656            array(
     1657                'template' => 'post-my-test-template.php',
     1658            )
     1659        );
    14321660        $request->set_body_params( $params );
    14331661        $response = $this->server->dispatch( $request );
     
    14451673
    14461674        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    1447         $params = $this->set_post_data( array(
    1448             'template' => '',
    1449         ) );
    1450         $request->set_body_params( $params );
    1451         $response = $this->server->dispatch( $request );
    1452 
    1453         $data = $response->get_data();
     1675        $params  = $this->set_post_data(
     1676            array(
     1677                'template' => '',
     1678            )
     1679        );
     1680        $request->set_body_params( $params );
     1681        $response = $this->server->dispatch( $request );
     1682
     1683        $data          = $response->get_data();
    14541684        $post_template = get_page_template_slug( get_post( $data['id'] ) );
    14551685
     
    14741704
    14751705        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1476         $params = $this->set_post_data( array(
    1477             'id' => '3',
    1478         ) );
     1706        $params  = $this->set_post_data(
     1707            array(
     1708                'id' => '3',
     1709            )
     1710        );
    14791711        $request->set_body_params( $params );
    14801712        $response = $this->server->dispatch( $request );
     
    14881720
    14891721        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1490         $params = $this->set_post_data( array(
    1491             // This results in a special `post_date_gmt` value of
    1492             // '0000-00-00 00:00:00'.  See #38883.
    1493             'status' => 'pending',
    1494         ) );
     1722        $params  = $this->set_post_data(
     1723            array(
     1724                // This results in a special `post_date_gmt` value of
     1725                // '0000-00-00 00:00:00'.  See #38883.
     1726                'status' => 'pending',
     1727            )
     1728        );
    14951729
    14961730        $request->set_body_params( $params );
     
    15121746
    15131747        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1514         $params = $this->set_post_data( array(
    1515             'sticky' => true,
    1516         ) );
     1748        $params  = $this->set_post_data(
     1749            array(
     1750                'sticky' => true,
     1751            )
     1752        );
    15171753        $request->set_body_params( $params );
    15181754        $response = $this->server->dispatch( $request );
     
    15281764
    15291765        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1530         $params = $this->set_post_data( array(
    1531             'sticky' => true,
    1532             'status' => 'pending',
    1533         ) );
     1766        $params  = $this->set_post_data(
     1767            array(
     1768                'sticky' => true,
     1769                'status' => 'pending',
     1770            )
     1771        );
    15341772        $request->set_body_params( $params );
    15351773        $response = $this->server->dispatch( $request );
     
    15421780
    15431781        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1544         $params = $this->set_post_data(array(
    1545             'author' => self::$editor_id,
    1546         ));
     1782        $params  = $this->set_post_data(
     1783            array(
     1784                'author' => self::$editor_id,
     1785            )
     1786        );
    15471787        $request->set_body_params( $params );
    15481788        $response = $this->server->dispatch( $request );
     
    15551795
    15561796        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1557         $params = $this->set_post_data( array(
    1558             'status' => 'draft',
    1559         ) );
     1797        $params  = $this->set_post_data(
     1798            array(
     1799                'status' => 'draft',
     1800            )
     1801        );
    15601802        $request->set_body_params( $params );
    15611803        $response = $this->server->dispatch( $request );
     
    15681810
    15691811        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1570         $params = $this->set_post_data( array(
    1571             'status' => 'draft',
    1572         ) );
    1573         $request->set_body_params( $params );
    1574         $response = $this->server->dispatch( $request );
    1575 
    1576         $data = $response->get_data();
     1812        $params  = $this->set_post_data(
     1813            array(
     1814                'status' => 'draft',
     1815            )
     1816        );
     1817        $request->set_body_params( $params );
     1818        $response = $this->server->dispatch( $request );
     1819
     1820        $data     = $response->get_data();
    15771821        $new_post = get_post( $data['id'] );
    15781822        $this->assertEquals( 'draft', $data['status'] );
     
    15801824        // Confirm dates are shimmed for gmt_offset
    15811825        $post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) );
    1582         $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) );
     1826        $post_date_gmt     = date( 'Y-m-d H:i:s', strtotime( $new_post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) );
    15831827
    15841828        $this->assertEquals( mysql_to_rfc3339( $post_modified_gmt ), $data['modified_gmt'] );
     
    15901834
    15911835        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1592         $params = $this->set_post_data( array(
    1593             'status' => 'private',
    1594         ) );
    1595         $request->set_body_params( $params );
    1596         $response = $this->server->dispatch( $request );
    1597 
    1598         $data = $response->get_data();
     1836        $params  = $this->set_post_data(
     1837            array(
     1838                'status' => 'private',
     1839            )
     1840        );
     1841        $request->set_body_params( $params );
     1842        $response = $this->server->dispatch( $request );
     1843
     1844        $data     = $response->get_data();
    15991845        $new_post = get_post( $data['id'] );
    16001846        $this->assertEquals( 'private', $data['status'] );
     
    16111857
    16121858        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1613         $params = $this->set_post_data( array(
    1614             'status' => 'private',
    1615             'author' => self::$author_id,
    1616         ) );
     1859        $params  = $this->set_post_data(
     1860            array(
     1861                'status' => 'private',
     1862                'author' => self::$author_id,
     1863            )
     1864        );
    16171865        $request->set_body_params( $params );
    16181866        $response = $this->server->dispatch( $request );
     
    16301878
    16311879        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1632         $params = $this->set_post_data( array(
    1633             'status' => 'publish',
    1634         ) );
     1880        $params  = $this->set_post_data(
     1881            array(
     1882                'status' => 'publish',
     1883            )
     1884        );
    16351885        $request->set_body_params( $params );
    16361886        $response = $this->server->dispatch( $request );
     
    16431893
    16441894        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1645         $params = $this->set_post_data( array(
    1646             'status' => 'teststatus',
    1647         ) );
     1895        $params  = $this->set_post_data(
     1896            array(
     1897                'status' => 'teststatus',
     1898            )
     1899        );
    16481900        $request->set_body_params( $params );
    16491901        $response = $this->server->dispatch( $request );
     
    16561908
    16571909        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1658         $params = $this->set_post_data( array(
    1659             'format' => 'gallery',
    1660         ) );
    1661         $request->set_body_params( $params );
    1662         $response = $this->server->dispatch( $request );
    1663 
    1664         $data = $response->get_data();
     1910        $params  = $this->set_post_data(
     1911            array(
     1912                'format' => 'gallery',
     1913            )
     1914        );
     1915        $request->set_body_params( $params );
     1916        $response = $this->server->dispatch( $request );
     1917
     1918        $data     = $response->get_data();
    16651919        $new_post = get_post( $data['id'] );
    16661920        $this->assertEquals( 'gallery', $data['format'] );
     
    16721926
    16731927        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1674         $params = $this->set_post_data( array(
    1675             'format' => 'standard',
    1676         ) );
    1677         $request->set_body_params( $params );
    1678         $response = $this->server->dispatch( $request );
    1679 
    1680         $data = $response->get_data();
     1928        $params  = $this->set_post_data(
     1929            array(
     1930                'format' => 'standard',
     1931            )
     1932        );
     1933        $request->set_body_params( $params );
     1934        $response = $this->server->dispatch( $request );
     1935
     1936        $data     = $response->get_data();
    16811937        $new_post = get_post( $data['id'] );
    16821938        $this->assertEquals( 'standard', $data['format'] );
     
    16881944
    16891945        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1690         $params = $this->set_post_data( array(
    1691             'format' => 'testformat',
    1692         ) );
     1946        $params  = $this->set_post_data(
     1947            array(
     1948                'format' => 'testformat',
     1949            )
     1950        );
    16931951        $request->set_body_params( $params );
    16941952        $response = $this->server->dispatch( $request );
     
    17061964
    17071965        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1708         $params = $this->set_post_data( array(
    1709             'format' => 'link',
    1710         ) );
     1966        $params  = $this->set_post_data(
     1967            array(
     1968                'format' => 'link',
     1969            )
     1970        );
    17111971        $request->set_body_params( $params );
    17121972        $response = $this->server->dispatch( $request );
     
    17191979    public function test_create_update_post_with_featured_media() {
    17201980
    1721         $file = DIR_TESTDATA . '/images/canola.jpg';
    1722         $this->attachment_id = $this->factory->attachment->create_object( $file, 0, array(
    1723             'post_mime_type' => 'image/jpeg',
    1724             'menu_order' => rand( 1, 100 ),
    1725         ) );
     1981        $file                = DIR_TESTDATA . '/images/canola.jpg';
     1982        $this->attachment_id = $this->factory->attachment->create_object(
     1983            $file, 0, array(
     1984                'post_mime_type' => 'image/jpeg',
     1985                'menu_order'     => rand( 1, 100 ),
     1986            )
     1987        );
    17261988
    17271989        wp_set_current_user( self::$editor_id );
    17281990
    17291991        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1730         $params = $this->set_post_data( array(
    1731             'featured_media' => $this->attachment_id,
    1732         ) );
    1733         $request->set_body_params( $params );
    1734         $response = $this->server->dispatch( $request );
    1735         $data = $response->get_data();
     1992        $params  = $this->set_post_data(
     1993            array(
     1994                'featured_media' => $this->attachment_id,
     1995            )
     1996        );
     1997        $request->set_body_params( $params );
     1998        $response = $this->server->dispatch( $request );
     1999        $data     = $response->get_data();
    17362000        $new_post = get_post( $data['id'] );
    17372001        $this->assertEquals( $this->attachment_id, $data['featured_media'] );
     
    17392003
    17402004        $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . $new_post->ID );
    1741         $params = $this->set_post_data( array(
    1742             'featured_media' => 0,
    1743         ) );
    1744         $request->set_body_params( $params );
    1745         $response = $this->server->dispatch( $request );
    1746         $data = $response->get_data();
     2005        $params  = $this->set_post_data(
     2006            array(
     2007                'featured_media' => 0,
     2008            )
     2009        );
     2010        $request->set_body_params( $params );
     2011        $response = $this->server->dispatch( $request );
     2012        $data     = $response->get_data();
    17472013        $this->assertEquals( 0, $data['featured_media'] );
    17482014        $this->assertEquals( 0, (int) get_post_thumbnail_id( $new_post->ID ) );
     
    17532019
    17542020        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1755         $params = $this->set_post_data( array(
    1756             'author' => -1,
    1757         ) );
     2021        $params  = $this->set_post_data(
     2022            array(
     2023                'author' => -1,
     2024            )
     2025        );
    17582026        $request->set_body_params( $params );
    17592027        $response = $this->server->dispatch( $request );
     
    17662034
    17672035        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1768         $params = $this->set_post_data( array(
    1769             'author' => self::$editor_id,
    1770         ) );
     2036        $params  = $this->set_post_data(
     2037            array(
     2038                'author' => self::$editor_id,
     2039            )
     2040        );
    17712041        $request->set_body_params( $params );
    17722042        $response = $this->server->dispatch( $request );
     
    17792049
    17802050        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1781         $params = $this->set_post_data( array(
    1782             'password' => 'testing',
    1783         ) );
     2051        $params  = $this->set_post_data(
     2052            array(
     2053                'password' => 'testing',
     2054            )
     2055        );
    17842056        $request->set_body_params( $params );
    17852057        $response = $this->server->dispatch( $request );
     
    17932065
    17942066        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1795         $params = $this->set_post_data( array(
    1796             'password' => '0',
    1797         ) );
     2067        $params  = $this->set_post_data(
     2068            array(
     2069                'password' => '0',
     2070            )
     2071        );
    17982072        $request->set_body_params( $params );
    17992073        $response = $this->server->dispatch( $request );
     
    18082082
    18092083        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1810         $params = $this->set_post_data( array(
    1811             'password' => '',
    1812             'sticky'   => true,
    1813         ) );
     2084        $params  = $this->set_post_data(
     2085            array(
     2086                'password' => '',
     2087                'sticky'   => true,
     2088            )
     2089        );
    18142090        $request->set_body_params( $params );
    18152091        $response = $this->server->dispatch( $request );
     
    18242100
    18252101        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1826         $params = $this->set_post_data( array(
    1827             'password' => '123',
    1828             'sticky'   => true,
    1829         ) );
     2102        $params  = $this->set_post_data(
     2103            array(
     2104                'password' => '123',
     2105                'sticky'   => true,
     2106            )
     2107        );
    18302108        $request->set_body_params( $params );
    18312109        $response = $this->server->dispatch( $request );
     
    18382116
    18392117        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1840         $params = $this->set_post_data( array(
    1841             'date' => '2010-01-01T02:00:00Z',
    1842         ) );
    1843         $request->set_body_params( $params );
    1844         $response = $this->server->dispatch( $request );
    1845 
    1846         $data = $response->get_data();
     2118        $params  = $this->set_post_data(
     2119            array(
     2120                'date' => '2010-01-01T02:00:00Z',
     2121            )
     2122        );
     2123        $request->set_body_params( $params );
     2124        $response = $this->server->dispatch( $request );
     2125
     2126        $data     = $response->get_data();
    18472127        $new_post = get_post( $data['id'] );
    1848         $time = gmmktime( 2, 0, 0, 1, 1, 2010 );
     2128        $time     = gmmktime( 2, 0, 0, 1, 1, 2010 );
    18492129        $this->assertEquals( '2010-01-01T02:00:00', $data['date'] );
    18502130        $this->assertEquals( $time, strtotime( $new_post->post_date ) );
     
    18552135
    18562136        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1857         $params = $this->set_post_data( array(
    1858             'date' => '2010-01-01T02:00:00-10:00',
    1859         ) );
    1860         $request->set_body_params( $params );
    1861         $response = $this->server->dispatch( $request );
    1862 
    1863         $data = $response->get_data();
     2137        $params  = $this->set_post_data(
     2138            array(
     2139                'date' => '2010-01-01T02:00:00-10:00',
     2140            )
     2141        );
     2142        $request->set_body_params( $params );
     2143        $response = $this->server->dispatch( $request );
     2144
     2145        $data     = $response->get_data();
    18642146        $new_post = get_post( $data['id'] );
    1865         $time = gmmktime( 12, 0, 0, 1, 1, 2010 );
     2147        $time     = gmmktime( 12, 0, 0, 1, 1, 2010 );
    18662148
    18672149        $this->assertEquals( '2010-01-01T12:00:00', $data['date'] );
     
    18982180
    18992181        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1900         $params = $this->set_post_data( array(
    1901             'date' => '2010-60-01T02:00:00Z',
    1902         ) );
     2182        $params  = $this->set_post_data(
     2183            array(
     2184                'date' => '2010-60-01T02:00:00Z',
     2185            )
     2186        );
    19032187        $request->set_body_params( $params );
    19042188        $response = $this->server->dispatch( $request );
     
    19112195
    19122196        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1913         $params = $this->set_post_data( array(
    1914             'date_gmt' => '2010-60-01T02:00:00',
    1915         ) );
     2197        $params  = $this->set_post_data(
     2198            array(
     2199                'date_gmt' => '2010-60-01T02:00:00',
     2200            )
     2201        );
    19162202        $request->set_body_params( $params );
    19172203        $response = $this->server->dispatch( $request );
     
    19242210
    19252211        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1926         $params = $this->set_post_data( array(
    1927             'title' => "Rob O'Rourke's Diary",
    1928         ) );
     2212        $params  = $this->set_post_data(
     2213            array(
     2214                'title' => "Rob O'Rourke's Diary",
     2215            )
     2216        );
    19292217        $request->set_body_params( $params );
    19302218        $response = $this->server->dispatch( $request );
     
    19362224        wp_set_current_user( self::$editor_id );
    19372225        $category = wp_insert_term( 'Test Category', 'category' );
    1938         $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1939         $params = $this->set_post_data( array(
    1940             'password'   => 'testing',
    1941             'categories' => array(
    1942                 $category['term_id']
    1943             ),
    1944         ) );
     2226        $request  = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     2227        $params   = $this->set_post_data(
     2228            array(
     2229                'password'   => 'testing',
     2230                'categories' => array(
     2231                    $category['term_id'],
     2232                ),
     2233            )
     2234        );
    19452235        $request->set_body_params( $params );
    19462236        $response = $this->server->dispatch( $request );
     
    19522242    public function test_create_post_with_categories_as_csv() {
    19532243        wp_set_current_user( self::$editor_id );
    1954         $category = wp_insert_term( 'Chicken', 'category' );
     2244        $category  = wp_insert_term( 'Chicken', 'category' );
    19552245        $category2 = wp_insert_term( 'Ribs', 'category' );
    1956         $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1957         $params = $this->set_post_data( array(
    1958             'categories' => $category['term_id'] . ',' . $category2['term_id'],
    1959         ) );
     2246        $request   = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     2247        $params    = $this->set_post_data(
     2248            array(
     2249                'categories' => $category['term_id'] . ',' . $category2['term_id'],
     2250            )
     2251        );
    19602252        $request->set_body_params( $params );
    19612253        $response = $this->server->dispatch( $request );
     
    19682260        wp_set_current_user( self::$editor_id );
    19692261        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1970         $params = $this->set_post_data( array(
    1971             'password'   => 'testing',
    1972             'categories' => array(
    1973                 REST_TESTS_IMPOSSIBLY_HIGH_NUMBER
    1974             ),
    1975         ) );
     2262        $params  = $this->set_post_data(
     2263            array(
     2264                'password'   => 'testing',
     2265                'categories' => array(
     2266                    REST_TESTS_IMPOSSIBLY_HIGH_NUMBER,
     2267                ),
     2268            )
     2269        );
    19762270        $request->set_body_params( $params );
    19772271        $response = $this->server->dispatch( $request );
     
    19852279     */
    19862280    public function test_create_post_with_categories_that_cannot_be_assigned_by_current_user() {
    1987         $cats = self::factory()->category->create_many( 2 );
     2281        $cats                = self::factory()->category->create_many( 2 );
    19882282        $this->forbidden_cat = $cats[1];
    19892283
    19902284        wp_set_current_user( self::$editor_id );
    19912285        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1992         $params = $this->set_post_data( array(
    1993             'password'   => 'testing',
    1994             'categories' => $cats,
    1995         ) );
     2286        $params  = $this->set_post_data(
     2287            array(
     2288                'password'   => 'testing',
     2289                'categories' => $cats,
     2290            )
     2291        );
    19962292        $request->set_body_params( $params );
    19972293
     
    20932389
    20942390        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2095         $params = $this->set_post_data();
     2391        $params  = $this->set_post_data();
    20962392        unset( $params['type'] );
    20972393        unset( $params['name'] );
     
    21132409
    21142410        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2115         $params = $this->set_post_data();
     2411        $params  = $this->set_post_data();
    21162412        $request->set_body_params( $params );
    21172413        $response = $this->server->dispatch( $request );
     
    21242420
    21252421        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2126         $params = $this->set_post_data( array(
    2127             'sticky' => true,
    2128             'status' => 'pending',
    2129         ) );
     2422        $params  = $this->set_post_data(
     2423            array(
     2424                'sticky' => true,
     2425                'status' => 'pending',
     2426            )
     2427        );
    21302428        $request->set_body_params( $params );
    21312429        $response = $this->server->dispatch( $request );
     
    21372435        wp_set_current_user( self::$editor_id );
    21382436
    2139         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );
     2437        $request  = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );
    21402438        $response = $this->server->dispatch( $request );
    21412439
     
    21462444        wp_set_current_user( self::$editor_id );
    21472445
    2148         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', self::$post_id ) );
     2446        $request  = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', self::$post_id ) );
    21492447        $response = $this->server->dispatch( $request );
    21502448
     
    21562454
    21572455        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2158         $params = $this->set_post_data( array(
    2159             'format' => 'gallery',
    2160         ) );
    2161         $request->set_body_params( $params );
    2162         $response = $this->server->dispatch( $request );
    2163 
    2164         $data = $response->get_data();
     2456        $params  = $this->set_post_data(
     2457            array(
     2458                'format' => 'gallery',
     2459            )
     2460        );
     2461        $request->set_body_params( $params );
     2462        $response = $this->server->dispatch( $request );
     2463
     2464        $data     = $response->get_data();
    21652465        $new_post = get_post( $data['id'] );
    21662466        $this->assertEquals( 'gallery', $data['format'] );
     
    21722472
    21732473        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2174         $params = $this->set_post_data( array(
    2175             'format' => 'standard',
    2176         ) );
    2177         $request->set_body_params( $params );
    2178         $response = $this->server->dispatch( $request );
    2179 
    2180         $data = $response->get_data();
     2474        $params  = $this->set_post_data(
     2475            array(
     2476                'format' => 'standard',
     2477            )
     2478        );
     2479        $request->set_body_params( $params );
     2480        $response = $this->server->dispatch( $request );
     2481
     2482        $data     = $response->get_data();
    21812483        $new_post = get_post( $data['id'] );
    21822484        $this->assertEquals( 'standard', $data['format'] );
     
    21882490
    21892491        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2190         $params = $this->set_post_data( array(
    2191             'format' => 'testformat',
    2192         ) );
     2492        $params  = $this->set_post_data(
     2493            array(
     2494                'format' => 'testformat',
     2495            )
     2496        );
    21932497        $request->set_body_params( $params );
    21942498        $response = $this->server->dispatch( $request );
     
    22062510
    22072511        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2208         $params = $this->set_post_data( array(
    2209             'format' => 'link',
    2210         ) );
     2512        $params  = $this->set_post_data(
     2513            array(
     2514                'format' => 'link',
     2515            )
     2516        );
    22112517        $request->set_body_params( $params );
    22122518        $response = $this->server->dispatch( $request );
     
    22202526        wp_set_current_user( self::$editor_id );
    22212527
    2222         $new_content = rand_str();
     2528        $new_content       = rand_str();
    22232529        $expected_modified = current_time( 'mysql' );
    22242530
    22252531        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2226         $params = $this->set_post_data( array(
    2227             'modified' => '2010-06-01T02:00:00Z',
    2228             'content'  => $new_content,
    2229         ) );
     2532        $params  = $this->set_post_data(
     2533            array(
     2534                'modified' => '2010-06-01T02:00:00Z',
     2535                'content'  => $new_content,
     2536            )
     2537        );
    22302538        $request->set_body_params( $params );
    22312539        $response = $this->server->dispatch( $request );
    22322540
    22332541        // The readonly modified param should be ignored, request should be a success.
    2234         $data = $response->get_data();
     2542        $data     = $response->get_data();
    22352543        $new_post = get_post( $data['id'] );
    22362544
     
    22802588
    22812589        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2282         $params = $this->set_post_data( array(
    2283             'date' => rand_str(),
    2284         ) );
     2590        $params  = $this->set_post_data(
     2591            array(
     2592                'date' => rand_str(),
     2593            )
     2594        );
    22852595        $request->set_body_params( $params );
    22862596        $response = $this->server->dispatch( $request );
     
    22932603
    22942604        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2295         $params = $this->set_post_data( array(
    2296             'date_gmt' => rand_str(),
    2297         ) );
     2605        $params  = $this->set_post_data(
     2606            array(
     2607                'date_gmt' => rand_str(),
     2608            )
     2609        );
    22982610        $request->set_body_params( $params );
    22992611        $response = $this->server->dispatch( $request );
     
    23262638
    23272639        $post = get_post( $post_id );
    2328         $this->assertEquals( $post->post_date,     '2016-02-23 12:00:00' );
     2640        $this->assertEquals( $post->post_date, '2016-02-23 12:00:00' );
    23292641        $this->assertEquals( $post->post_date_gmt, '0000-00-00 00:00:00' );
    23302642
    2331         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
     2643        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    23322644        $response = $this->server->dispatch( $request );
    23332645        $this->assertEquals( 200, $response->get_status() );
     
    23472659
    23482660        $post = get_post( $post_id );
    2349         $this->assertEquals( $post->post_date,     '2016-02-23 13:00:00' );
     2661        $this->assertEquals( $post->post_date, '2016-02-23 13:00:00' );
    23502662        $this->assertEquals( $post->post_date_gmt, '2016-02-23 19:00:00' );
    23512663
     
    23572669
    23582670        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2359         $params = $this->set_post_data( array(
    2360             'slug' => 'sample-slug',
    2361         ) );
     2671        $params  = $this->set_post_data(
     2672            array(
     2673                'slug' => 'sample-slug',
     2674            )
     2675        );
    23622676        $request->set_body_params( $params );
    23632677        $response = $this->server->dispatch( $request );
     
    23732687
    23742688        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2375         $params = $this->set_post_data( array(
    2376             'slug' => 'tęst-acceńted-chäræcters',
    2377         ) );
     2689        $params  = $this->set_post_data(
     2690            array(
     2691                'slug' => 'tęst-acceńted-chäræcters',
     2692            )
     2693        );
    23782694        $request->set_body_params( $params );
    23792695        $response = $this->server->dispatch( $request );
     
    23892705
    23902706        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2391         $params = $this->set_post_data( array(
    2392             'sticky' => true,
    2393         ) );
     2707        $params  = $this->set_post_data(
     2708            array(
     2709                'sticky' => true,
     2710            )
     2711        );
    23942712        $request->set_body_params( $params );
    23952713        $response = $this->server->dispatch( $request );
     
    24022720        // Updating another field shouldn't change sticky status
    24032721        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2404         $params = $this->set_post_data( array(
    2405             'title'       => 'This should not reset sticky',
    2406         ) );
     2722        $params  = $this->set_post_data(
     2723            array(
     2724                'title' => 'This should not reset sticky',
     2725            )
     2726        );
    24072727        $request->set_body_params( $params );
    24082728        $response = $this->server->dispatch( $request );
     
    24182738
    24192739        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2420         $request->set_body_params( array(
    2421             'excerpt' => 'An Excerpt',
    2422         ) );
     2740        $request->set_body_params(
     2741            array(
     2742                'excerpt' => 'An Excerpt',
     2743            )
     2744        );
    24232745
    24242746        $response = $this->server->dispatch( $request );
     
    24312753
    24322754        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2433         $request->set_body_params( array(
    2434             'excerpt' => '',
    2435         ) );
     2755        $request->set_body_params(
     2756            array(
     2757                'excerpt' => '',
     2758            )
     2759        );
    24362760
    24372761        $response = $this->server->dispatch( $request );
     
    24442768
    24452769        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2446         $request->set_body_params( array(
    2447             'content' => 'Some Content',
    2448         ) );
     2770        $request->set_body_params(
     2771            array(
     2772                'content' => 'Some Content',
     2773            )
     2774        );
    24492775
    24502776        $response = $this->server->dispatch( $request );
     
    24572783
    24582784        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2459         $request->set_body_params( array(
    2460             'content' => '',
    2461         ) );
     2785        $request->set_body_params(
     2786            array(
     2787                'content' => '',
     2788            )
     2789        );
    24622790
    24632791        $response = $this->server->dispatch( $request );
     
    24682796    public function test_update_post_with_empty_password() {
    24692797        wp_set_current_user( self::$editor_id );
    2470         wp_update_post( array(
    2471             'ID'            => self::$post_id,
    2472             'post_password' => 'foo',
    2473         ) );
     2798        wp_update_post(
     2799            array(
     2800                'ID'            => self::$post_id,
     2801                'post_password' => 'foo',
     2802            )
     2803        );
    24742804
    24752805        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2476         $params = $this->set_post_data( array(
    2477             'password' => '',
    2478         ) );
    2479         $request->set_body_params( $params );
    2480         $response = $this->server->dispatch( $request );
    2481         $data = $response->get_data();
     2806        $params  = $this->set_post_data(
     2807            array(
     2808                'password' => '',
     2809            )
     2810        );
     2811        $request->set_body_params( $params );
     2812        $response = $this->server->dispatch( $request );
     2813        $data     = $response->get_data();
    24822814        $this->assertEquals( '', $data['password'] );
    24832815    }
     
    24872819
    24882820        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2489         $params = $this->set_post_data( array(
    2490             'password' => '123',
    2491             'sticky'   => true,
    2492         ) );
     2821        $params  = $this->set_post_data(
     2822            array(
     2823                'password' => '123',
     2824                'sticky'   => true,
     2825            )
     2826        );
    24932827        $request->set_body_params( $params );
    24942828        $response = $this->server->dispatch( $request );
     
    25032837
    25042838        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2505         $params = $this->set_post_data( array(
    2506             'password' => '123',
    2507         ) );
     2839        $params  = $this->set_post_data(
     2840            array(
     2841                'password' => '123',
     2842            )
     2843        );
    25082844        $request->set_body_params( $params );
    25092845        $response = $this->server->dispatch( $request );
     
    25152851        wp_set_current_user( self::$editor_id );
    25162852
    2517         wp_update_post( array( 'ID' => self::$post_id, 'post_password' => '123' ) );
     2853        wp_update_post(
     2854            array(
     2855                'ID'            => self::$post_id,
     2856                'post_password' => '123',
     2857            )
     2858        );
    25182859
    25192860        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2520         $params = $this->set_post_data( array(
    2521             'sticky' => true,
    2522         ) );
     2861        $params  = $this->set_post_data(
     2862            array(
     2863                'sticky' => true,
     2864            )
     2865        );
    25232866        $request->set_body_params( $params );
    25242867        $response = $this->server->dispatch( $request );
     
    25312874
    25322875        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2533         $params = $this->set_post_data( array(
    2534             'title' => "Rob O'Rourke's Diary",
    2535         ) );
     2876        $params  = $this->set_post_data(
     2877            array(
     2878                'title' => "Rob O'Rourke's Diary",
     2879            )
     2880        );
    25362881        $request->set_body_params( $params );
    25372882        $response = $this->server->dispatch( $request );
     
    25462891
    25472892        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2548         $params = $this->set_post_data( array(
    2549             'title' => 'Tester',
    2550             'categories' => array(
    2551                 $category['term_id'],
    2552             ),
    2553         ) );
     2893        $params  = $this->set_post_data(
     2894            array(
     2895                'title'      => 'Tester',
     2896                'categories' => array(
     2897                    $category['term_id'],
     2898                ),
     2899            )
     2900        );
    25542901        $request->set_body_params( $params );
    25552902        $response = $this->server->dispatch( $request );
     
    25572904        $this->assertEquals( array( $category['term_id'] ), $new_data['categories'] );
    25582905        $categories_path = '';
    2559         $links = $response->get_links();
     2906        $links           = $response->get_links();
    25602907        foreach ( $links['https://api.w.org/term'] as $link ) {
    25612908            if ( 'category' === $link['attributes']['taxonomy'] ) {
     
    25692916        $request->set_query_params( $args );
    25702917        $response = $this->server->dispatch( $request );
    2571         $data = $response->get_data();
     2918        $data     = $response->get_data();
    25722919        $this->assertCount( 1, $data );
    25732920        $this->assertEquals( 'Test Category', $data[0]['name'] );
     
    25812928
    25822929        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2583         $params = $this->set_post_data( array(
    2584             'title' => 'Tester',
    2585             'categories' => array(),
    2586         ) );
     2930        $params  = $this->set_post_data(
     2931            array(
     2932                'title'      => 'Tester',
     2933                'categories' => array(),
     2934            )
     2935        );
    25872936        $request->set_body_params( $params );
    25882937        $response = $this->server->dispatch( $request );
     
    25952944     */
    25962945    public function test_update_post_with_categories_that_cannot_be_assigned_by_current_user() {
    2597         $cats = self::factory()->category->create_many( 2 );
     2946        $cats                = self::factory()->category->create_many( 2 );
    25982947        $this->forbidden_cat = $cats[1];
    25992948
    26002949        wp_set_current_user( self::$editor_id );
    26012950        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2602         $params = $this->set_post_data( array(
    2603             'password'   => 'testing',
    2604             'categories' => $cats,
    2605         ) );
     2951        $params  = $this->set_post_data(
     2952            array(
     2953                'password'   => 'testing',
     2954                'categories' => $cats,
     2955            )
     2956        );
    26062957        $request->set_body_params( $params );
    26072958
     
    26222973        // reregister the route as we now have a template available.
    26232974        $GLOBALS['wp_rest_server']->override_by_default = true;
    2624         $controller = new WP_REST_Posts_Controller( 'post' );
     2975        $controller                                     = new WP_REST_Posts_Controller( 'post' );
    26252976        $controller->register_routes();
    26262977        $GLOBALS['wp_rest_server']->override_by_default = false;
    26272978
    26282979        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2629         $params = $this->set_post_data( array(
    2630             'template' => 'post-my-test-template.php',
    2631         ) );
    2632         $request->set_body_params( $params );
    2633         $response = $this->server->dispatch( $request );
    2634 
    2635         $data = $response->get_data();
     2980        $params  = $this->set_post_data(
     2981            array(
     2982                'template' => 'post-my-test-template.php',
     2983            )
     2984        );
     2985        $request->set_body_params( $params );
     2986        $response = $this->server->dispatch( $request );
     2987
     2988        $data          = $response->get_data();
    26362989        $post_template = get_page_template_slug( get_post( $data['id'] ) );
    26372990
     
    26503003        // reregister the route as we now have a template available.
    26513004        $GLOBALS['wp_rest_server']->override_by_default = true;
    2652         $controller = new WP_REST_Posts_Controller( 'post' );
     3005        $controller                                     = new WP_REST_Posts_Controller( 'post' );
    26533006        $controller->register_routes();
    26543007        $GLOBALS['wp_rest_server']->override_by_default = false;
    26553008
    26563009        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2657         $params = $this->set_post_data( array(
    2658             'template' => '',
    2659         ) );
    2660         $request->set_body_params( $params );
    2661         $response = $this->server->dispatch( $request );
    2662 
    2663         $data = $response->get_data();
     3010        $params  = $this->set_post_data(
     3011            array(
     3012                'template' => '',
     3013            )
     3014        );
     3015        $request->set_body_params( $params );
     3016        $response = $this->server->dispatch( $request );
     3017
     3018        $data          = $response->get_data();
    26643019        $post_template = get_page_template_slug( get_post( $data['id'] ) );
    26653020
     
    26813036
    26823037        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    2683         $params = $this->set_post_data( array(
    2684             'template' => 'post-my-invalid-template.php',
    2685         ) );
     3038        $params  = $this->set_post_data(
     3039            array(
     3040                'template' => 'post-my-invalid-template.php',
     3041            )
     3042        );
    26863043        $request->set_body_params( $params );
    26873044        $response = $this->server->dispatch( $request );
     
    26893046        $this->assertEquals( 200, $response->get_status() );
    26903047
    2691         $data = $response->get_data();
     3048        $data          = $response->get_data();
    26923049        $post_template = get_page_template_slug( get_post( $data['id'] ) );
    26933050
     
    27073064
    27083065        // Compare expected API output to actual API output
    2709         $this->assertEquals( $expected_output['title']['raw']       , $actual_output['title']['raw'] );
    2710         $this->assertEquals( $expected_output['title']['rendered']  , trim( $actual_output['title']['rendered'] ) );
    2711         $this->assertEquals( $expected_output['content']['raw']     , $actual_output['content']['raw'] );
     3066        $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] );
     3067        $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );
     3068        $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] );
    27123069        $this->assertEquals( $expected_output['content']['rendered'], trim( $actual_output['content']['rendered'] ) );
    2713         $this->assertEquals( $expected_output['excerpt']['raw']     , $actual_output['excerpt']['raw'] );
     3070        $this->assertEquals( $expected_output['excerpt']['raw'], $actual_output['excerpt']['raw'] );
    27143071        $this->assertEquals( $expected_output['excerpt']['rendered'], trim( $actual_output['excerpt']['rendered'] ) );
    27153072
    27163073        // Compare expected API output to WP internal values
    27173074        $post = get_post( $actual_output['id'] );
    2718         $this->assertEquals( $expected_output['title']['raw']  , $post->post_title );
     3075        $this->assertEquals( $expected_output['title']['raw'], $post->post_title );
    27193076        $this->assertEquals( $expected_output['content']['raw'], $post->post_content );
    27203077        $this->assertEquals( $expected_output['excerpt']['raw'], $post->post_excerpt );
     
    27303087
    27313088        // Compare expected API output to actual API output
    2732         $this->assertEquals( $expected_output['title']['raw']       , $actual_output['title']['raw'] );
    2733         $this->assertEquals( $expected_output['title']['rendered']  , trim( $actual_output['title']['rendered'] ) );
    2734         $this->assertEquals( $expected_output['content']['raw']     , $actual_output['content']['raw'] );
     3089        $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] );
     3090        $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) );
     3091        $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] );
    27353092        $this->assertEquals( $expected_output['content']['rendered'], trim( $actual_output['content']['rendered'] ) );
    2736         $this->assertEquals( $expected_output['excerpt']['raw']     , $actual_output['excerpt']['raw'] );
     3093        $this->assertEquals( $expected_output['excerpt']['raw'], $actual_output['excerpt']['raw'] );
    27373094        $this->assertEquals( $expected_output['excerpt']['rendered'], trim( $actual_output['excerpt']['rendered'] ) );
    27383095
    27393096        // Compare expected API output to WP internal values
    27403097        $post = get_post( $actual_output['id'] );
    2741         $this->assertEquals( $expected_output['title']['raw']  , $post->post_title );
     3098        $this->assertEquals( $expected_output['title']['raw'], $post->post_title );
    27423099        $this->assertEquals( $expected_output['content']['raw'], $post->post_content );
    27433100        $this->assertEquals( $expected_output['excerpt']['raw'], $post->post_excerpt );
     
    27553112                // Expected returned values.
    27563113                array(
    2757                     'title' => array(
     3114                    'title'   => array(
    27583115                        'raw'      => '\o/ ¯\_(ツ)_/¯',
    27593116                        'rendered' => '\o/ ¯\_(ツ)_/¯',
     
    27673124                        'rendered' => '<p>\o/ ¯\_(ツ)_/¯</p>',
    27683125                    ),
    2769                 )
     3126                ),
    27703127            ),
    27713128            array(
     
    27783135                // Expected returned values.
    27793136                array(
    2780                     'title' => array(
     3137                    'title'   => array(
    27813138                        'raw'      => '\\\&amp;\\\ &amp; &amp;invalid; &lt; &lt; &amp;lt;',
    27823139                        'rendered' => '\\\&amp;\\\ &amp; &amp;invalid; &lt; &lt; &amp;lt;',
     
    28013158                // Expected returned values.
    28023159                array(
    2803                     'title' => array(
     3160                    'title'   => array(
     3161                        'raw'      => 'div <strong>strong</strong> oh noes',
     3162                        'rendered' => 'div <strong>strong</strong> oh noes',
     3163                    ),
     3164                    'content' => array(
     3165                        'raw'      => '<div>div</div> <strong>strong</strong> oh noes',
     3166                        'rendered' => "<div>div</div>\n<p> <strong>strong</strong> oh noes</p>",
     3167                    ),
     3168                    'excerpt' => array(
     3169                        'raw'      => '<div>div</div> <strong>strong</strong> oh noes',
     3170                        'rendered' => "<div>div</div>\n<p> <strong>strong</strong> oh noes</p>",
     3171                    ),
     3172                ),
     3173            ),
     3174            array(
     3175                // Raw values.
     3176                array(
     3177                    'title'   => '<a href="#" target="_blank" data-unfiltered=true>link</a>',
     3178                    'content' => '<a href="#" target="_blank" data-unfiltered=true>link</a>',
     3179                    'excerpt' => '<a href="#" target="_blank" data-unfiltered=true>link</a>',
     3180                ),
     3181                // Expected returned values.
     3182                array(
     3183                    'title'   => array(
     3184                        'raw'      => '<a href="#">link</a>',
     3185                        'rendered' => '<a href="#">link</a>',
     3186                    ),
     3187                    'content' => array(
     3188                        'raw'      => '<a href="#" target="_blank">link</a>',
     3189                        'rendered' => '<p><a href="#" target="_blank">link</a></p>',
     3190                    ),
     3191                    'excerpt' => array(
     3192                        'raw'      => '<a href="#" target="_blank">link</a>',
     3193                        'rendered' => '<p><a href="#" target="_blank">link</a></p>',
     3194                    ),
     3195                ),
     3196            ),
     3197        );
     3198    }
     3199
     3200    /**
     3201     * @dataProvider post_roundtrip_provider
     3202     */
     3203    public function test_post_roundtrip_as_author( $raw, $expected ) {
     3204        wp_set_current_user( self::$author_id );
     3205        $this->assertFalse( current_user_can( 'unfiltered_html' ) );
     3206        $this->verify_post_roundtrip( $raw, $expected );
     3207    }
     3208
     3209    public function test_post_roundtrip_as_editor_unfiltered_html() {
     3210        wp_set_current_user( self::$editor_id );
     3211        if ( is_multisite() ) {
     3212            $this->assertFalse( current_user_can( 'unfiltered_html' ) );
     3213            $this->verify_post_roundtrip(
     3214                array(
     3215                    'title'   => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     3216                    'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     3217                    'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     3218                ), array(
     3219                    'title'   => array(
    28043220                        'raw'      => 'div <strong>strong</strong> oh noes',
    28053221                        'rendered' => 'div <strong>strong</strong> oh noes',
     
    28143230                    ),
    28153231                )
    2816             ),
    2817             array(
    2818                 // Raw values.
     3232            );
     3233        } else {
     3234            $this->assertTrue( current_user_can( 'unfiltered_html' ) );
     3235            $this->verify_post_roundtrip(
    28193236                array(
    2820                     'title'   => '<a href="#" target="_blank" data-unfiltered=true>link</a>',
    2821                     'content' => '<a href="#" target="_blank" data-unfiltered=true>link</a>',
    2822                     'excerpt' => '<a href="#" target="_blank" data-unfiltered=true>link</a>',
    2823                 ),
    2824                 // Expected returned values.
    2825                 array(
    2826                     'title' => array(
    2827                         'raw'      => '<a href="#">link</a>',
    2828                         'rendered' => '<a href="#">link</a>',
     3237                    'title'   => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     3238                    'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     3239                    'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     3240                ), array(
     3241                    'title'   => array(
     3242                        'raw'      => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     3243                        'rendered' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    28293244                    ),
    28303245                    'content' => array(
    2831                         'raw'      => '<a href="#" target="_blank">link</a>',
    2832                         'rendered' => '<p><a href="#" target="_blank">link</a></p>',
     3246                        'raw'      => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     3247                        'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>",
    28333248                    ),
    28343249                    'excerpt' => array(
    2835                         'raw'      => '<a href="#" target="_blank">link</a>',
    2836                         'rendered' => '<p><a href="#" target="_blank">link</a></p>',
     3250                        'raw'      => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     3251                        'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>",
    28373252                    ),
    28383253                )
    2839             ),
    2840         );
    2841     }
    2842 
    2843     /**
    2844      * @dataProvider post_roundtrip_provider
    2845      */
    2846     public function test_post_roundtrip_as_author( $raw, $expected ) {
    2847         wp_set_current_user( self::$author_id );
    2848         $this->assertFalse( current_user_can( 'unfiltered_html' ) );
    2849         $this->verify_post_roundtrip( $raw, $expected );
    2850     }
    2851 
    2852     public function test_post_roundtrip_as_editor_unfiltered_html() {
    2853         wp_set_current_user( self::$editor_id );
    2854         if ( is_multisite() ) {
    2855             $this->assertFalse( current_user_can( 'unfiltered_html' ) );
    2856             $this->verify_post_roundtrip( array(
     3254            );
     3255        }
     3256    }
     3257
     3258    public function test_post_roundtrip_as_superadmin_unfiltered_html() {
     3259        wp_set_current_user( self::$superadmin_id );
     3260        $this->assertTrue( current_user_can( 'unfiltered_html' ) );
     3261        $this->verify_post_roundtrip(
     3262            array(
    28573263                'title'   => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    28583264                'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    28593265                'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    28603266            ), array(
    2861                 'title' => array(
    2862                     'raw'      => 'div <strong>strong</strong> oh noes',
    2863                     'rendered' => 'div <strong>strong</strong> oh noes',
    2864                 ),
    2865                 'content' => array(
    2866                     'raw'      => '<div>div</div> <strong>strong</strong> oh noes',
    2867                     'rendered' => "<div>div</div>\n<p> <strong>strong</strong> oh noes</p>",
    2868                 ),
    2869                 'excerpt' => array(
    2870                     'raw'      => '<div>div</div> <strong>strong</strong> oh noes',
    2871                     'rendered' => "<div>div</div>\n<p> <strong>strong</strong> oh noes</p>",
    2872                 ),
    2873             ) );
    2874         } else {
    2875             $this->assertTrue( current_user_can( 'unfiltered_html' ) );
    2876             $this->verify_post_roundtrip( array(
    2877                 'title'   => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2878                 'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2879                 'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2880             ), array(
    2881                 'title' => array(
     3267                'title'   => array(
    28823268                    'raw'      => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    28833269                    'rendered' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
     
    28913277                    'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>",
    28923278                ),
    2893             ) );
    2894         }
    2895     }
    2896 
    2897     public function test_post_roundtrip_as_superadmin_unfiltered_html() {
    2898         wp_set_current_user( self::$superadmin_id );
    2899         $this->assertTrue( current_user_can( 'unfiltered_html' ) );
    2900         $this->verify_post_roundtrip( array(
    2901             'title'   => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2902             'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2903             'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2904         ), array(
    2905             'title' => array(
    2906                 'raw'      => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2907                 'rendered' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2908             ),
    2909             'content' => array(
    2910                 'raw'      => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2911                 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>",
    2912             ),
    2913             'excerpt' => array(
    2914                 'raw'      => '<div>div</div> <strong>strong</strong> <script>oh noes</script>',
    2915                 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>",
    2916             ),
    2917         ) );
     3279            )
     3280        );
    29183281    }
    29193282
     
    29363299        wp_set_current_user( self::$editor_id );
    29373300
    2938         $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
     3301        $request          = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    29393302        $request['force'] = true;
    2940         $response = $this->server->dispatch( $request );
     3303        $response         = $this->server->dispatch( $request );
    29413304
    29423305        $this->assertEquals( 200, $response->get_status() );
     
    29493312        $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) );
    29503313        wp_set_current_user( self::$editor_id );
    2951         $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
     3314        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    29523315        $response = $this->server->dispatch( $request );
    29533316        $this->assertEquals( 200, $response->get_status() );
     
    29593322        wp_set_current_user( self::$editor_id );
    29603323
    2961         $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
     3324        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    29623325        $response = $this->server->dispatch( $request );
    29633326
     
    29693332        wp_set_current_user( self::$editor_id );
    29703333
    2971         $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $page_id );
     3334        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $page_id );
    29723335        $response = $this->server->dispatch( $request );
    29733336
     
    29783341        wp_set_current_user( self::$author_id );
    29793342
    2980         $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     3343        $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    29813344        $response = $this->server->dispatch( $request );
    29823345
     
    29863349    public function test_register_post_type_invalid_controller() {
    29873350
    2988         register_post_type( 'invalid-controller', array( 'show_in_rest' => true, 'rest_controller_class' => 'Fake_Class_Baba' ) );
     3351        register_post_type(
     3352            'invalid-controller', array(
     3353                'show_in_rest'          => true,
     3354                'rest_controller_class' => 'Fake_Class_Baba',
     3355            )
     3356        );
    29893357        create_initial_rest_routes();
    29903358        $routes = $this->server->get_routes();
     
    29953363
    29963364    public function test_get_item_schema() {
    2997         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    2998         $response = $this->server->dispatch( $request );
    2999         $data = $response->get_data();
     3365        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
     3366        $response   = $this->server->dispatch( $request );
     3367        $data       = $response->get_data();
    30003368        $properties = $data['schema']['properties'];
    30013369        $this->assertEquals( 24, count( $properties ) );
     
    30333401        $request->set_param( 'context', 'view' );
    30343402        $response = $this->server->dispatch( $request );
    3035         $keys = array_keys( $response->get_data() );
     3403        $keys     = array_keys( $response->get_data() );
    30363404        sort( $keys );
    30373405
     
    30713439        $request->set_param( 'context', 'edit' );
    30723440        $response = $this->server->dispatch( $request );
    3073         $keys = array_keys( $response->get_data() );
     3441        $keys     = array_keys( $response->get_data() );
    30743442        sort( $keys );
    30753443
     
    31083476        $request->set_param( 'context', 'embed' );
    31093477        $response = $this->server->dispatch( $request );
    3110         $keys = array_keys( $response->get_data() );
     3478        $keys     = array_keys( $response->get_data() );
    31113479        sort( $keys );
    31123480
     
    31273495
    31283496    public function test_status_array_enum_args() {
    3129         $request = new WP_REST_Request( 'GET', '/wp/v2' );
    3130         $response = $this->server->dispatch( $request );
    3131         $data = $response->get_data();
     3497        $request         = new WP_REST_Request( 'GET', '/wp/v2' );
     3498        $response        = $this->server->dispatch( $request );
     3499        $data            = $response->get_data();
    31323500        $list_posts_args = $data['routes']['/wp/v2/posts']['endpoints'][0]['args'];
    3133         $status_arg = $list_posts_args['status'];
     3501        $status_arg      = $list_posts_args['status'];
    31343502        $this->assertEquals( 'array', $status_arg['type'] );
    3135         $this->assertEquals( array(
    3136             'type' => 'string',
    3137             'enum' => array( 'publish', 'future', 'draft', 'pending', 'private', 'trash', 'auto-draft', 'inherit', 'any' ),
    3138         ), $status_arg['items'] );
     3503        $this->assertEquals(
     3504            array(
     3505                'type' => 'string',
     3506                'enum' => array( 'publish', 'future', 'draft', 'pending', 'private', 'trash', 'auto-draft', 'inherit', 'any' ),
     3507            ), $status_arg['items']
     3508        );
    31393509    }
    31403510
     
    31483518        );
    31493519
    3150         register_rest_field( 'post', 'my_custom_int', array(
    3151             'schema'          => $schema,
    3152             'get_callback'    => array( $this, 'additional_field_get_callback' ),
    3153             'update_callback' => array( $this, 'additional_field_update_callback' ),
    3154         ) );
     3520        register_rest_field(
     3521            'post', 'my_custom_int', array(
     3522                'schema'          => $schema,
     3523                'get_callback'    => array( $this, 'additional_field_get_callback' ),
     3524                'update_callback' => array( $this, 'additional_field_update_callback' ),
     3525            )
     3526        );
    31553527
    31563528        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    31573529
    31583530        $response = $this->server->dispatch( $request );
    3159         $data = $response->get_data();
     3531        $data     = $response->get_data();
    31603532
    31613533        $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] );
     
    31723544
    31733545        $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . $post_id );
    3174         $request->set_body_params(array(
    3175             'my_custom_int' => 123,
    3176         ));
     3546        $request->set_body_params(
     3547            array(
     3548                'my_custom_int' => 123,
     3549            )
     3550        );
    31773551
    31783552        $response = $this->server->dispatch( $request );
     
    31803554
    31813555        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    3182         $request->set_body_params(array(
    3183             'my_custom_int' => 123,
    3184             'title' => 'hello',
    3185         ));
     3556        $request->set_body_params(
     3557            array(
     3558                'my_custom_int' => 123,
     3559                'title'         => 'hello',
     3560            )
     3561        );
    31863562
    31873563        $response = $this->server->dispatch( $request );
     
    32013577        );
    32023578
    3203         register_rest_field( 'post', 'my_custom_int', array(
    3204             'schema'          => $schema,
    3205             'get_callback'    => array( $this, 'additional_field_get_callback' ),
    3206             'update_callback' => array( $this, 'additional_field_update_callback' ),
    3207         ) );
     3579        register_rest_field(
     3580            'post', 'my_custom_int', array(
     3581                'schema'          => $schema,
     3582                'get_callback'    => array( $this, 'additional_field_get_callback' ),
     3583                'update_callback' => array( $this, 'additional_field_update_callback' ),
     3584            )
     3585        );
    32083586
    32093587        wp_set_current_user( self::$editor_id );
    32103588        // Check for error on update.
    32113589        $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    3212         $request->set_body_params( array(
    3213             'my_custom_int' => 'returnError',
    3214         ) );
     3590        $request->set_body_params(
     3591            array(
     3592                'my_custom_int' => 'returnError',
     3593            )
     3594        );
    32153595
    32163596        $response = $this->server->dispatch( $request );
Note: See TracChangeset for help on using the changeset viewer.