- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-post-statuses-controller.php
r42228 r42343 20 20 public function test_context_param() { 21 21 // Collection 22 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );23 $response = $this->server->dispatch( $request ); 24 $data = $response->get_data();22 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' ); 23 $response = $this->server->dispatch( $request ); 24 $data = $response->get_data(); 25 25 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 26 26 $this->assertEqualSets( array( 'embed', 'view', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 27 27 // Single 28 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses/publish' );29 $response = $this->server->dispatch( $request ); 30 $data = $response->get_data();28 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses/publish' ); 29 $response = $this->server->dispatch( $request ); 30 $data = $response->get_data(); 31 31 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 32 32 $this->assertEqualSets( array( 'embed', 'view', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); … … 34 34 35 35 public function test_get_items() { 36 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' );37 $response = $this->server->dispatch( $request ); 38 39 $data = $response->get_data();36 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' ); 37 $response = $this->server->dispatch( $request ); 38 39 $data = $response->get_data(); 40 40 $statuses = get_post_stati( array( 'public' => true ), 'objects' ); 41 41 $this->assertEquals( 1, count( $data ) ); … … 47 47 wp_set_current_user( $user_id ); 48 48 49 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' );49 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses' ); 50 50 $response = $this->server->dispatch( $request ); 51 51 52 52 $data = $response->get_data(); 53 53 $this->assertEquals( 6, count( $data ) ); 54 $this->assertEqualSets( array( 55 'publish', 56 'private', 57 'pending', 58 'draft', 59 'trash', 60 'future', 61 ), array_keys( $data ) ); 54 $this->assertEqualSets( 55 array( 56 'publish', 57 'private', 58 'pending', 59 'draft', 60 'trash', 61 'future', 62 ), array_keys( $data ) 63 ); 62 64 } 63 65 … … 79 81 80 82 public function test_get_item_invalid_status() { 81 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/invalid' );83 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/invalid' ); 82 84 $response = $this->server->dispatch( $request ); 83 85 $this->assertErrorResponse( 'rest_status_invalid', $response, 404 ); … … 86 88 public function test_get_item_invalid_access() { 87 89 wp_set_current_user( 0 ); 88 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/draft' );90 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/draft' ); 89 91 $response = $this->server->dispatch( $request ); 90 92 $this->assertErrorResponse( 'rest_cannot_read_status', $response, 401 ); … … 95 97 wp_set_current_user( $user_id ); 96 98 97 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/inherit' );99 $request = new WP_REST_Request( 'GET', '/wp/v2/statuses/inherit' ); 98 100 $response = $this->server->dispatch( $request ); 99 101 $this->assertErrorResponse( 'rest_cannot_read_status', $response, 403 ); … … 101 103 102 104 public function test_create_item() { 103 /** Post statuses can't be created * */104 $request = new WP_REST_Request( 'POST', '/wp/v2/statuses' );105 /** Post statuses can't be created */ 106 $request = new WP_REST_Request( 'POST', '/wp/v2/statuses' ); 105 107 $response = $this->server->dispatch( $request ); 106 108 $this->assertEquals( 404, $response->get_status() ); … … 108 110 109 111 public function test_update_item() { 110 /** Post statuses can't be updated * */111 $request = new WP_REST_Request( 'POST', '/wp/v2/statuses/draft' );112 /** Post statuses can't be updated */ 113 $request = new WP_REST_Request( 'POST', '/wp/v2/statuses/draft' ); 112 114 $response = $this->server->dispatch( $request ); 113 115 $this->assertEquals( 404, $response->get_status() ); … … 115 117 116 118 public function test_delete_item() { 117 /** Post statuses can't be deleted * */118 $request = new WP_REST_Request( 'DELETE', '/wp/v2/statuses/draft' );119 /** Post statuses can't be deleted */ 120 $request = new WP_REST_Request( 'DELETE', '/wp/v2/statuses/draft' ); 119 121 $response = $this->server->dispatch( $request ); 120 122 $this->assertEquals( 404, $response->get_status() ); … … 122 124 123 125 public function test_prepare_item() { 124 $obj = get_post_status_object( 'publish' );126 $obj = get_post_status_object( 'publish' ); 125 127 $endpoint = new WP_REST_Post_Statuses_Controller; 126 $request = new WP_REST_Request;128 $request = new WP_REST_Request; 127 129 $request->set_param( 'context', 'edit' ); 128 130 $data = $endpoint->prepare_item_for_response( $obj, $request ); … … 131 133 132 134 public function test_get_item_schema() { 133 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' );134 $response = $this->server->dispatch( $request );135 $data = $response->get_data();135 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' ); 136 $response = $this->server->dispatch( $request ); 137 $data = $response->get_data(); 136 138 $properties = $data['schema']['properties']; 137 139 $this->assertEquals( 7, count( $properties ) ); … … 154 156 ); 155 157 156 register_rest_field( 'status', 'my_custom_int', array( 157 'schema' => $schema, 158 'get_callback' => array( $this, 'additional_field_get_callback' ), 159 'update_callback' => array( $this, 'additional_field_update_callback' ), 160 ) ); 158 register_rest_field( 159 'status', 'my_custom_int', array( 160 'schema' => $schema, 161 'get_callback' => array( $this, 'additional_field_get_callback' ), 162 'update_callback' => array( $this, 'additional_field_update_callback' ), 163 ) 164 ); 161 165 162 166 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/statuses' ); 163 167 164 168 $response = $this->server->dispatch( $request ); 165 $data = $response->get_data();169 $data = $response->get_data(); 166 170 167 171 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); … … 189 193 $this->assertEquals( $status_obj->show_in_admin_all_list, $data['show_in_list'] ); 190 194 $this->assertEquals( $status_obj->name, $data['slug'] ); 191 $this->assertEqualSets( array( 192 'archives', 193 ), array_keys( $links ) ); 195 $this->assertEqualSets( 196 array( 197 'archives', 198 ), array_keys( $links ) 199 ); 194 200 } 195 201 … … 197 203 $this->assertEquals( 200, $response->get_status() ); 198 204 $data = $response->get_data(); 199 $obj = get_post_status_object( 'publish' );205 $obj = get_post_status_object( 'publish' ); 200 206 $this->check_post_status_obj( $obj, $data, $response->get_links() ); 201 207 }
Note: See TracChangeset
for help on using the changeset viewer.