- 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-categories-controller.php
r42354 r42724 34 34 35 35 public function test_register_routes() { 36 $routes = $this->server->get_routes();36 $routes = rest_get_server()->get_routes(); 37 37 $this->assertArrayHasKey( '/wp/v2/categories', $routes ); 38 38 $this->assertArrayHasKey( '/wp/v2/categories/(?P<id>[\d]+)', $routes ); … … 42 42 // Collection 43 43 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); 44 $response = $this->server->dispatch( $request );44 $response = rest_get_server()->dispatch( $request ); 45 45 $data = $response->get_data(); 46 46 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 49 49 $category1 = $this->factory->category->create( array( 'name' => 'Season 5' ) ); 50 50 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories/' . $category1 ); 51 $response = $this->server->dispatch( $request );51 $response = rest_get_server()->dispatch( $request ); 52 52 $data = $response->get_data(); 53 53 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); … … 57 57 public function test_registered_query_params() { 58 58 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); 59 $response = $this->server->dispatch( $request );59 $response = rest_get_server()->dispatch( $request ); 60 60 $data = $response->get_data(); 61 61 $keys = array_keys( $data['endpoints'][0]['args'] ); … … 81 81 public function test_get_items() { 82 82 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 83 $response = $this->server->dispatch( $request );83 $response = rest_get_server()->dispatch( $request ); 84 84 $this->check_get_taxonomy_terms_response( $response ); 85 85 } … … 89 89 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 90 90 $request->set_param( 'context', 'edit' ); 91 $response = $this->server->dispatch( $request );91 $response = rest_get_server()->dispatch( $request ); 92 92 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 93 93 } … … 100 100 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 101 101 $request->set_param( 'hide_empty', true ); 102 $response = $this->server->dispatch( $request );102 $response = rest_get_server()->dispatch( $request ); 103 103 $data = $response->get_data(); 104 104 $this->assertEquals( 2, count( $data ) ); … … 108 108 // Confirm the empty category "Uncategorized" category appears. 109 109 $request->set_param( 'hide_empty', 'false' ); 110 $response = $this->server->dispatch( $request );110 $response = rest_get_server()->dispatch( $request ); 111 111 $data = $response->get_data(); 112 112 $this->assertEquals( 3, count( $data ) ); … … 130 130 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 131 131 $request->set_param( 'parent', 0 ); 132 $response = $this->server->dispatch( $request );132 $response = rest_get_server()->dispatch( $request ); 133 133 134 134 $this->assertEquals( 200, $response->get_status() ); … … 160 160 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 161 161 $request->set_param( 'parent', '0' ); 162 $response = $this->server->dispatch( $request );162 $response = rest_get_server()->dispatch( $request ); 163 163 164 164 $this->assertEquals( 200, $response->get_status() ); … … 178 178 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 179 179 $request->set_param( 'parent', $parent1 ); 180 $response = $this->server->dispatch( $request );180 $response = rest_get_server()->dispatch( $request ); 181 181 182 182 $this->assertEquals( 200, $response->get_status() ); … … 189 189 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 190 190 $request->set_param( 'page', 0 ); 191 $response = $this->server->dispatch( $request );191 $response = rest_get_server()->dispatch( $request ); 192 192 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 193 193 $data = $response->get_data(); … … 203 203 // Orderby=>asc 204 204 $request->set_param( 'include', array( $id3, $id1 ) ); 205 $response = $this->server->dispatch( $request );205 $response = rest_get_server()->dispatch( $request ); 206 206 $data = $response->get_data(); 207 207 $this->assertEquals( 2, count( $data ) ); … … 209 209 // Orderby=>include 210 210 $request->set_param( 'orderby', 'include' ); 211 $response = $this->server->dispatch( $request );211 $response = rest_get_server()->dispatch( $request ); 212 212 $data = $response->get_data(); 213 213 $this->assertEquals( 2, count( $data ) ); … … 219 219 $id2 = $this->factory->category->create(); 220 220 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 221 $response = $this->server->dispatch( $request );221 $response = rest_get_server()->dispatch( $request ); 222 222 $data = $response->get_data(); 223 223 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 224 224 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 225 225 $request->set_param( 'exclude', array( $id2 ) ); 226 $response = $this->server->dispatch( $request );226 $response = rest_get_server()->dispatch( $request ); 227 227 $data = $response->get_data(); 228 228 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); … … 243 243 $request->set_param( 'order', 'desc' ); 244 244 $request->set_param( 'per_page', 1 ); 245 $response = $this->server->dispatch( $request );245 $response = rest_get_server()->dispatch( $request ); 246 246 $this->assertEquals( 200, $response->get_status() ); 247 247 $data = $response->get_data(); … … 252 252 $request->set_param( 'order', 'asc' ); 253 253 $request->set_param( 'per_page', 2 ); 254 $response = $this->server->dispatch( $request );254 $response = rest_get_server()->dispatch( $request ); 255 255 $this->assertEquals( 200, $response->get_status() ); 256 256 $data = $response->get_data(); … … 265 265 // defaults to orderby=name, order=asc 266 266 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 267 $response = $this->server->dispatch( $request );267 $response = rest_get_server()->dispatch( $request ); 268 268 $this->assertEquals( 200, $response->get_status() ); 269 269 $data = $response->get_data(); … … 275 275 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 276 276 $request->set_param( 'orderby', 'id' ); 277 $response = $this->server->dispatch( $request );277 $response = rest_get_server()->dispatch( $request ); 278 278 $this->assertEquals( 200, $response->get_status() ); 279 279 $data = $response->get_data(); … … 286 286 $request->set_param( 'orderby', 'id' ); 287 287 $request->set_param( 'order', 'desc' ); 288 $response = $this->server->dispatch( $request );288 $response = rest_get_server()->dispatch( $request ); 289 289 $data = $response->get_data(); 290 290 $this->assertEquals( 200, $response->get_status() ); … … 302 302 $request->set_param( 'orderby', 'include_slugs' ); 303 303 $request->set_param( 'slug', array( 'taco', 'burrito', 'chalupa' ) ); 304 $response = $this->server->dispatch( $request );304 $response = rest_get_server()->dispatch( $request ); 305 305 $data = $response->get_data(); 306 306 $this->assertEquals( 200, $response->get_status() ); … … 340 340 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 341 341 $request->set_param( 'post', $post_id ); 342 $response = $this->server->dispatch( $request );342 $response = rest_get_server()->dispatch( $request ); 343 343 $this->assertEquals( 200, $response->get_status() ); 344 344 … … 358 358 $request->set_param( 'post', $post_id ); 359 359 $request->set_param( 'orderby', 'description' ); 360 $response = $this->server->dispatch( $request );360 $response = rest_get_server()->dispatch( $request ); 361 361 $this->assertEquals( 200, $response->get_status() ); 362 362 … … 368 368 // Flip the order 369 369 $request->set_param( 'order', 'desc' ); 370 $response = $this->server->dispatch( $request );370 $response = rest_get_server()->dispatch( $request ); 371 371 $this->assertEquals( 200, $response->get_status() ); 372 372 … … 383 383 $request->set_param( 'post', $post_id ); 384 384 $request->set_param( 'orderby', 'id' ); 385 $response = $this->server->dispatch( $request );385 $response = rest_get_server()->dispatch( $request ); 386 386 $this->assertEquals( 200, $response->get_status() ); 387 387 … … 419 419 $request = new WP_REST_Request( 'GET', '/wp/v2/batman' ); 420 420 $request->set_param( 'post', $post_id ); 421 $response = $this->server->dispatch( $request );421 $response = rest_get_server()->dispatch( $request ); 422 422 $this->assertEquals( 200, $response->get_status() ); 423 423 … … 436 436 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 437 437 $request->set_param( 'search', 'App' ); 438 $response = $this->server->dispatch( $request );438 $response = rest_get_server()->dispatch( $request ); 439 439 $this->assertEquals( 200, $response->get_status() ); 440 440 $data = $response->get_data(); … … 443 443 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 444 444 $request->set_param( 'search', 'Garbage' ); 445 $response = $this->server->dispatch( $request );445 $response = rest_get_server()->dispatch( $request ); 446 446 $this->assertEquals( 200, $response->get_status() ); 447 447 $data = $response->get_data(); … … 454 454 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 455 455 $request->set_param( 'slug', 'apple' ); 456 $response = $this->server->dispatch( $request );456 $response = rest_get_server()->dispatch( $request ); 457 457 $this->assertEquals( 200, $response->get_status() ); 458 458 $data = $response->get_data(); … … 471 471 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 472 472 $request->set_param( 'parent', $category1 ); 473 $response = $this->server->dispatch( $request );473 $response = rest_get_server()->dispatch( $request ); 474 474 $data = $response->get_data(); 475 475 $this->assertEquals( 1, count( $data ) ); … … 487 487 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 488 488 $request->set_param( 'parent', 'invalid-parent' ); 489 $response = $this->server->dispatch( $request );489 $response = rest_get_server()->dispatch( $request ); 490 490 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 491 491 } … … 507 507 508 508 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin' ); 509 $response = $this->server->dispatch( $request );509 $response = rest_get_server()->dispatch( $request ); 510 510 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 511 511 } … … 513 513 public function test_get_terms_invalid_taxonomy() { 514 514 $request = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy' ); 515 $response = $this->server->dispatch( $request );515 $response = rest_get_server()->dispatch( $request ); 516 516 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 517 517 } … … 527 527 } 528 528 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 529 $response = $this->server->dispatch( $request );529 $response = rest_get_server()->dispatch( $request ); 530 530 $headers = $response->get_headers(); 531 531 $this->assertEquals( 50, $headers['X-WP-Total'] ); … … 547 547 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 548 548 $request->set_param( 'page', 3 ); 549 $response = $this->server->dispatch( $request );549 $response = rest_get_server()->dispatch( $request ); 550 550 $headers = $response->get_headers(); 551 551 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 567 567 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 568 568 $request->set_param( 'page', 6 ); 569 $response = $this->server->dispatch( $request );569 $response = rest_get_server()->dispatch( $request ); 570 570 $headers = $response->get_headers(); 571 571 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 582 582 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 583 583 $request->set_param( 'page', 8 ); 584 $response = $this->server->dispatch( $request );584 $response = rest_get_server()->dispatch( $request ); 585 585 $headers = $response->get_headers(); 586 586 $this->assertEquals( 51, $headers['X-WP-Total'] ); … … 608 608 $request->set_param( 'page', 1 ); 609 609 $request->set_param( 'per_page', 100 ); 610 $response = $this->server->dispatch( $request );610 $response = rest_get_server()->dispatch( $request ); 611 611 $headers = $response->get_headers(); 612 612 $this->assertEquals( 18, $headers['X-WP-Total'] ); … … 616 616 $request->set_param( 'page', 2 ); 617 617 $request->set_param( 'per_page', 100 ); 618 $response = $this->server->dispatch( $request );618 $response = rest_get_server()->dispatch( $request ); 619 619 $headers = $response->get_headers(); 620 620 $this->assertEquals( 18, $headers['X-WP-Total'] ); … … 625 625 public function test_get_item() { 626 626 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 627 $response = $this->server->dispatch( $request );627 $response = rest_get_server()->dispatch( $request ); 628 628 $this->check_get_taxonomy_term_response( $response ); 629 629 } … … 631 631 public function test_get_term_invalid_taxonomy() { 632 632 $request = new WP_REST_Request( 'GET', '/wp/v2/invalid-taxonomy/1' ); 633 $response = $this->server->dispatch( $request );633 $response = rest_get_server()->dispatch( $request ); 634 634 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 635 635 } … … 637 637 public function test_get_term_invalid_term() { 638 638 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 639 $response = $this->server->dispatch( $request );639 $response = rest_get_server()->dispatch( $request ); 640 640 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 641 641 } … … 645 645 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 646 646 $request->set_param( 'context', 'edit' ); 647 $response = $this->server->dispatch( $request );647 $response = rest_get_server()->dispatch( $request ); 648 648 $this->assertErrorResponse( 'rest_forbidden_context', $response, 401 ); 649 649 } … … 659 659 660 660 $request = new WP_REST_Request( 'GET', '/wp/v2/terms/robin/' . $term1 ); 661 $response = $this->server->dispatch( $request );661 $response = rest_get_server()->dispatch( $request ); 662 662 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 663 663 } … … 672 672 ); 673 673 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $term1 ); 674 $response = $this->server->dispatch( $request );674 $response = rest_get_server()->dispatch( $request ); 675 675 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 676 676 } … … 682 682 $request->set_param( 'description', 'This term is so awesome.' ); 683 683 $request->set_param( 'slug', 'so-awesome' ); 684 $response = $this->server->dispatch( $request );684 $response = rest_get_server()->dispatch( $request ); 685 685 $this->assertEquals( 201, $response->get_status() ); 686 686 $headers = $response->get_headers(); … … 702 702 $request->set_param( 'name', 'Existing' ); 703 703 704 $response = $this->server->dispatch( $request );704 $response = rest_get_server()->dispatch( $request ); 705 705 $this->assertEquals( 400, $response->get_status() ); 706 706 $data = $response->get_data(); … … 715 715 $request = new WP_REST_Request( 'POST', '/wp/v2/invalid-taxonomy' ); 716 716 $request->set_param( 'name', 'Invalid Taxonomy' ); 717 $response = $this->server->dispatch( $request );717 $response = rest_get_server()->dispatch( $request ); 718 718 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 719 719 } … … 723 723 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 724 724 $request->set_param( 'name', 'Incorrect permissions' ); 725 $response = $this->server->dispatch( $request );725 $response = rest_get_server()->dispatch( $request ); 726 726 $this->assertErrorResponse( 'rest_cannot_create', $response, 403 ); 727 727 } … … 730 730 wp_set_current_user( self::$administrator ); 731 731 $request = new WP_REST_Request( 'POST', '/wp/v2/categories' ); 732 $response = $this->server->dispatch( $request );732 $response = rest_get_server()->dispatch( $request ); 733 733 $this->assertErrorResponse( 'rest_missing_callback_param', $response, 400 ); 734 734 } … … 740 740 $request->set_param( 'name', 'My Awesome Term' ); 741 741 $request->set_param( 'parent', $parent['term_id'] ); 742 $response = $this->server->dispatch( $request );742 $response = rest_get_server()->dispatch( $request ); 743 743 $this->assertEquals( 201, $response->get_status() ); 744 744 $data = $response->get_data(); … … 753 753 $request->set_param( 'name', 'My Awesome Term' ); 754 754 $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 755 $response = $this->server->dispatch( $request );755 $response = rest_get_server()->dispatch( $request ); 756 756 $this->assertErrorResponse( 'rest_term_invalid', $response, 400 ); 757 757 } … … 769 769 $request->set_param( 'description', 'New Description' ); 770 770 $request->set_param( 'slug', 'new-slug' ); 771 $response = $this->server->dispatch( $request );771 $response = rest_get_server()->dispatch( $request ); 772 772 $this->assertEquals( 200, $response->get_status() ); 773 773 $data = $response->get_data(); … … 781 781 $request = new WP_REST_Request( 'POST', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 782 782 $request->set_param( 'name', 'Invalid Taxonomy' ); 783 $response = $this->server->dispatch( $request );783 $response = rest_get_server()->dispatch( $request ); 784 784 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 785 785 } … … 789 789 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 790 790 $request->set_param( 'name', 'Invalid Term' ); 791 $response = $this->server->dispatch( $request );791 $response = rest_get_server()->dispatch( $request ); 792 792 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 793 793 } … … 798 798 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); 799 799 $request->set_param( 'name', 'Incorrect permissions' ); 800 $response = $this->server->dispatch( $request );800 $response = rest_get_server()->dispatch( $request ); 801 801 $this->assertErrorResponse( 'rest_cannot_update', $response, 403 ); 802 802 } … … 809 809 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); 810 810 $request->set_param( 'parent', $parent->term_id ); 811 $response = $this->server->dispatch( $request );811 $response = rest_get_server()->dispatch( $request ); 812 812 $this->assertEquals( 200, $response->get_status() ); 813 813 … … 822 822 $request = new WP_REST_Request( 'POST', '/wp/v2/categories/' . $term->term_id ); 823 823 $request->set_param( 'parent', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 824 $response = $this->server->dispatch( $request );824 $response = rest_get_server()->dispatch( $request ); 825 825 $this->assertErrorResponse( 'rest_term_invalid', $response, 400 ); 826 826 } … … 831 831 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); 832 832 $request->set_param( 'force', true ); 833 $response = $this->server->dispatch( $request );833 $response = rest_get_server()->dispatch( $request ); 834 834 $this->assertEquals( 200, $response->get_status() ); 835 835 $data = $response->get_data(); … … 843 843 844 844 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); 845 $response = $this->server->dispatch( $request );845 $response = rest_get_server()->dispatch( $request ); 846 846 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 847 847 848 848 $request->set_param( 'force', 'false' ); 849 $response = $this->server->dispatch( $request );849 $response = rest_get_server()->dispatch( $request ); 850 850 $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 ); 851 851 } … … 854 854 wp_set_current_user( self::$administrator ); 855 855 $request = new WP_REST_Request( 'DELETE', '/wp/v2/invalid-taxonomy/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 856 $response = $this->server->dispatch( $request );856 $response = rest_get_server()->dispatch( $request ); 857 857 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 858 858 } … … 861 861 wp_set_current_user( self::$administrator ); 862 862 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 863 $response = $this->server->dispatch( $request );863 $response = rest_get_server()->dispatch( $request ); 864 864 $this->assertErrorResponse( 'rest_term_invalid', $response, 404 ); 865 865 } … … 869 869 $term = get_term_by( 'id', $this->factory->category->create(), 'category' ); 870 870 $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id ); 871 $response = $this->server->dispatch( $request );871 $response = rest_get_server()->dispatch( $request ); 872 872 $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 ); 873 873 } … … 877 877 878 878 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/1' ); 879 $response = $this->server->dispatch( $request );879 $response = rest_get_server()->dispatch( $request ); 880 880 $data = $response->get_data(); 881 881 … … 892 892 893 893 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $child ); 894 $response = $this->server->dispatch( $request );894 $response = rest_get_server()->dispatch( $request ); 895 895 $data = $response->get_data(); 896 896 … … 905 905 public function test_get_item_schema() { 906 906 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); 907 $response = $this->server->dispatch( $request );907 $response = rest_get_server()->dispatch( $request ); 908 908 $data = $response->get_data(); 909 909 $properties = $data['schema']['properties']; … … 939 939 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/categories' ); 940 940 941 $response = $this->server->dispatch( $request );941 $response = rest_get_server()->dispatch( $request ); 942 942 $data = $response->get_data(); 943 943 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); … … 947 947 $request = new WP_REST_Request( 'GET', '/wp/v2/categories/' . $category_id ); 948 948 949 $response = $this->server->dispatch( $request );949 $response = rest_get_server()->dispatch( $request ); 950 950 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 951 951
Note: See TracChangeset
for help on using the changeset viewer.