- Timestamp:
- 02/21/2018 04:24:30 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
r42343 r42724 38 38 39 39 public function test_register_routes() { 40 $routes = $this->server->get_routes();40 $routes = rest_get_server()->get_routes(); 41 41 $this->assertArrayHasKey( '/wp/v2/pages', $routes ); 42 42 $this->assertCount( 2, $routes['/wp/v2/pages'] ); … … 48 48 // Collection 49 49 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ); 50 $response = $this->server->dispatch( $request );50 $response = rest_get_server()->dispatch( $request ); 51 51 $data = $response->get_data(); 52 52 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 55 55 $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 56 56 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages/' . $page_id ); 57 $response = $this->server->dispatch( $request );57 $response = rest_get_server()->dispatch( $request ); 58 58 $data = $response->get_data(); 59 59 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 63 63 public function test_registered_query_params() { 64 64 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ); 65 $response = $this->server->dispatch( $request );65 $response = rest_get_server()->dispatch( $request ); 66 66 $data = $response->get_data(); 67 67 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 105 105 ); 106 106 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 107 $response = $this->server->dispatch( $request );107 $response = rest_get_server()->dispatch( $request ); 108 108 $data = $response->get_data(); 109 109 $this->assertEquals( 1, count( $data ) ); … … 127 127 // No parent 128 128 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 129 $response = $this->server->dispatch( $request );129 $response = rest_get_server()->dispatch( $request ); 130 130 $data = $response->get_data(); 131 131 $this->assertEquals( 2, count( $data ) ); 132 132 // Filter to parent 133 133 $request->set_param( 'parent', $id1 ); 134 $response = $this->server->dispatch( $request );134 $response = rest_get_server()->dispatch( $request ); 135 135 $data = $response->get_data(); 136 136 $this->assertEquals( 1, count( $data ) ); … … 138 138 // Invalid parent should fail 139 139 $request->set_param( 'parent', 'some-slug' ); 140 $response = $this->server->dispatch( $request );140 $response = rest_get_server()->dispatch( $request ); 141 141 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 142 142 } … … 171 171 // No parent 172 172 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 173 $response = $this->server->dispatch( $request );173 $response = rest_get_server()->dispatch( $request ); 174 174 $data = $response->get_data(); 175 175 $this->assertEquals( 4, count( $data ) ); 176 176 // Filter to parents 177 177 $request->set_param( 'parent', array( $id1, $id3 ) ); 178 $response = $this->server->dispatch( $request );178 $response = rest_get_server()->dispatch( $request ); 179 179 $data = $response->get_data(); 180 180 $this->assertEquals( 2, count( $data ) ); … … 198 198 // No parent 199 199 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 200 $response = $this->server->dispatch( $request );200 $response = rest_get_server()->dispatch( $request ); 201 201 $data = $response->get_data(); 202 202 $this->assertEquals( 2, count( $data ) ); 203 203 // Filter to parent 204 204 $request->set_param( 'parent_exclude', $id1 ); 205 $response = $this->server->dispatch( $request );205 $response = rest_get_server()->dispatch( $request ); 206 206 $data = $response->get_data(); 207 207 $this->assertEquals( 1, count( $data ) ); … … 209 209 // Invalid parent_exclude should error 210 210 $request->set_param( 'parent_exclude', 'some-slug' ); 211 $response = $this->server->dispatch( $request );211 $response = rest_get_server()->dispatch( $request ); 212 212 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 213 213 } … … 243 243 // No parent 244 244 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 245 $response = $this->server->dispatch( $request );245 $response = rest_get_server()->dispatch( $request ); 246 246 $data = $response->get_data(); 247 247 $this->assertEqualSets( array( $id1, $id2, $id3, $id4 ), wp_list_pluck( $data, 'id' ) ); 248 248 // Filter to menu_order 249 249 $request->set_param( 'menu_order', 1 ); 250 $response = $this->server->dispatch( $request );250 $response = rest_get_server()->dispatch( $request ); 251 251 $data = $response->get_data(); 252 252 $this->assertEqualSets( array( $id4 ), wp_list_pluck( $data, 'id' ) ); … … 255 255 $request->set_param( 'order', 'asc' ); 256 256 $request->set_param( 'orderby', 'menu_order' ); 257 $response = $this->server->dispatch( $request );257 $response = rest_get_server()->dispatch( $request ); 258 258 $data = $response->get_data(); 259 259 $this->assertEquals( $id1, $data[0]['id'] ); … … 264 264 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 265 265 $request->set_param( 'menu_order', 'top-first' ); 266 $response = $this->server->dispatch( $request );266 $response = rest_get_server()->dispatch( $request ); 267 267 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 268 268 } … … 271 271 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 272 272 $request->set_param( 'per_page', 0 ); 273 $response = $this->server->dispatch( $request );273 $response = rest_get_server()->dispatch( $request ); 274 274 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 275 275 $data = $response->get_data(); … … 278 278 $this->assertContains( 'per_page must be between 1 (inclusive) and 100 (inclusive)', $first_error ); 279 279 $request->set_param( 'per_page', 101 ); 280 $response = $this->server->dispatch( $request );280 $response = rest_get_server()->dispatch( $request ); 281 281 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 282 282 $data = $response->get_data(); … … 302 302 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 303 303 $request->set_param( 'status', 'draft' ); 304 $response = $this->server->dispatch( $request );304 $response = rest_get_server()->dispatch( $request ); 305 305 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 306 306 307 307 // But they are accessible to authorized users 308 308 wp_set_current_user( self::$editor_id ); 309 $response = $this->server->dispatch( $request );309 $response = rest_get_server()->dispatch( $request ); 310 310 $data = $response->get_data(); 311 311 $this->assertCount( 1, $data ); … … 317 317 $request->set_param( 'after', rand_str() ); 318 318 $request->set_param( 'before', rand_str() ); 319 $response = $this->server->dispatch( $request );319 $response = rest_get_server()->dispatch( $request ); 320 320 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 321 321 } … … 343 343 $request->set_param( 'after', '2016-01-15T00:00:00Z' ); 344 344 $request->set_param( 'before', '2016-01-17T00:00:00Z' ); 345 $response = $this->server->dispatch( $request );345 $response = rest_get_server()->dispatch( $request ); 346 346 $data = $response->get_data(); 347 347 $this->assertCount( 1, $data ); … … 356 356 $post_id = $this->factory->post->create(); 357 357 $request = new WP_REST_Request( 'GET', '/wp/v2/pages/' . $post_id ); 358 $response = $this->server->dispatch( $request );358 $response = rest_get_server()->dispatch( $request ); 359 359 $this->assertEquals( 404, $response->get_status() ); 360 360 } … … 374 374 ); 375 375 $request->set_body_params( $params ); 376 $response = $this->server->dispatch( $request );376 $response = rest_get_server()->dispatch( $request ); 377 377 378 378 $data = $response->get_data(); … … 397 397 ); 398 398 $request->set_body_params( $params ); 399 $response = $this->server->dispatch( $request );399 $response = rest_get_server()->dispatch( $request ); 400 400 401 401 $this->assertEquals( 201, $response->get_status() ); … … 420 420 ); 421 421 $request->set_body_params( $params ); 422 $response = $this->server->dispatch( $request );422 $response = rest_get_server()->dispatch( $request ); 423 423 424 424 $this->assertErrorResponse( 'rest_post_invalid_id', $response, 400 ); … … 440 440 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/pages/%d', $page_id ) ); 441 441 $request->set_param( 'force', 'false' ); 442 $response = $this->server->dispatch( $request );442 $response = rest_get_server()->dispatch( $request ); 443 443 444 444 $this->assertEquals( 200, $response->get_status() ); … … 466 466 ) 467 467 ); 468 $response = $this->server->dispatch( $request );468 $response = rest_get_server()->dispatch( $request ); 469 469 470 470 $this->assertEquals( 200, $response->get_status() ); … … 498 498 ) 499 499 ); 500 $response = $this->server->dispatch( $request );500 $response = rest_get_server()->dispatch( $request ); 501 501 502 502 $new_data = $response->get_data(); … … 522 522 ) 523 523 ); 524 $response = $this->server->dispatch( $request );524 $response = rest_get_server()->dispatch( $request ); 525 525 526 526 $new_data = $response->get_data(); … … 546 546 ) 547 547 ); 548 $response = $this->server->dispatch( $request );548 $response = rest_get_server()->dispatch( $request ); 549 549 $new_data = $response->get_data(); 550 550 $this->assertEquals( $page_id1, $new_data['parent'] ); … … 570 570 ) 571 571 ); 572 $response = $this->server->dispatch( $request );572 $response = rest_get_server()->dispatch( $request ); 573 573 $new_data = $response->get_data(); 574 574 $this->assertEquals( 0, $new_data['parent'] ); … … 584 584 585 585 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) ); 586 $response = $this->server->dispatch( $request );586 $response = rest_get_server()->dispatch( $request ); 587 587 588 588 $data = $response->get_data(); … … 606 606 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) ); 607 607 $request->set_param( 'password', '$inthebananastand' ); 608 $response = $this->server->dispatch( $request );608 $response = rest_get_server()->dispatch( $request ); 609 609 610 610 $data = $response->get_data(); … … 626 626 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) ); 627 627 $request->set_param( 'password', 'wrongpassword' ); 628 $response = $this->server->dispatch( $request );628 $response = rest_get_server()->dispatch( $request ); 629 629 630 630 $this->assertErrorResponse( 'rest_post_incorrect_password', $response, 403 ); … … 641 641 ); 642 642 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) ); 643 $response = $this->server->dispatch( $request );643 $response = rest_get_server()->dispatch( $request ); 644 644 $data = $response->get_data(); 645 645 $this->assertEquals( '', $data['content']['rendered'] ); … … 651 651 public function test_get_item_schema() { 652 652 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ); 653 $response = $this->server->dispatch( $request );653 $response = rest_get_server()->dispatch( $request ); 654 654 $data = $response->get_data(); 655 655 $properties = $data['schema']['properties'];
Note: See TracChangeset
for help on using the changeset viewer.