- Timestamp:
- 09/12/2019 09:28:14 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r44510 r46098 1270 1270 } 1271 1271 1272 /** 1273 * @ticket 41411 1274 */ 1275 public function test_editable_response_uses_edit_context() { 1276 wp_set_current_user( self::$administrator ); 1277 1278 $view_field = 'view_only_field'; 1279 $edit_field = 'edit_only_field'; 1280 1281 register_rest_field( 1282 'tag', 1283 $view_field, 1284 array( 1285 'context' => array( 'view' ), 1286 'get_callback' => '__return_empty_string', 1287 ) 1288 ); 1289 1290 register_rest_field( 1291 'tag', 1292 $edit_field, 1293 array( 1294 'context' => array( 'edit' ), 1295 'get_callback' => '__return_empty_string', 1296 ) 1297 ); 1298 1299 $create = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 1300 $create->set_param( 'name', 'My New Term' ); 1301 $response = rest_get_server()->dispatch( $create ); 1302 $this->assertEquals( 201, $response->get_status() ); 1303 $data = $response->get_data(); 1304 $this->assertArrayHasKey( $edit_field, $data ); 1305 $this->assertArrayNotHasKey( $view_field, $data ); 1306 1307 $update = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $data['id'] ); 1308 $update->set_param( 'name', 'My Awesome New Term' ); 1309 $response = rest_get_server()->dispatch( $update ); 1310 $this->assertEquals( 200, $response->get_status() ); 1311 $data = $response->get_data(); 1312 $this->assertArrayHasKey( $edit_field, $data ); 1313 $this->assertArrayNotHasKey( $view_field, $data ); 1314 } 1315 1272 1316 public function additional_field_get_callback( $object, $request ) { 1273 1317 return 123;
Note: See TracChangeset
for help on using the changeset viewer.