- Timestamp:
- 11/05/2019 08:41:12 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r46648 r46657 20 20 21 21 protected static $supported_formats; 22 protected static $post_ids = array(); 23 protected static $total_posts = 30; 24 protected static $per_page = 50; 22 25 23 26 protected $forbidden_cat; … … 62 65 self::$supported_formats = get_theme_support( 'post-formats' ); 63 66 add_theme_support( 'post-formats', array( 'post', 'gallery' ) ); 67 68 // Set up posts for pagination tests. 69 for ( $i = 0; $i < self::$total_posts - 1; $i++ ) { 70 self::$post_ids[] = $factory->post->create( 71 array( 72 'post_title' => "Post {$i}", 73 ) 74 ); 75 } 64 76 } 65 77 … … 70 82 } else { 71 83 remove_theme_support( 'post-formats' ); 84 } 85 86 // Remove posts for pagination tests. 87 foreach ( self::$post_ids as $post_id ) { 88 wp_delete_post( $post_id, true ); 72 89 } 73 90 … … 204 221 205 222 wp_set_current_user( self::$editor_id ); 223 206 224 $request = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 207 225 $response = rest_get_server()->dispatch( $request ); … … 241 259 $this->factory->post->create( array( 'post_author' => self::$editor_id ) ); 242 260 $this->factory->post->create( array( 'post_author' => self::$author_id ) ); 243 // All 3 posts 244 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 261 262 $total_posts = self::$total_posts + 2; 263 264 // All posts in the database. 265 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 266 $request->set_param( 'per_page', self::$per_page ); 245 267 $response = rest_get_server()->dispatch( $request ); 246 268 $this->assertEquals( 200, $response->get_status() ); 247 $this->assertEquals( 3, count( $response->get_data() ) ); 248 // 2 of 3 posts 269 $this->assertEquals( $total_posts, count( $response->get_data() ) ); 270 271 // Limit to editor and author. 249 272 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 250 273 $request->set_param( 'author', array( self::$editor_id, self::$author_id ) ); … … 254 277 $this->assertEquals( 2, count( $data ) ); 255 278 $this->assertEqualSets( array( self::$editor_id, self::$author_id ), wp_list_pluck( $data, 'author' ) ); 256 // 1 of 3 posts 279 280 // Limit to editor. 257 281 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 258 282 $request->set_param( 'author', self::$editor_id ); … … 267 291 $this->factory->post->create( array( 'post_author' => self::$editor_id ) ); 268 292 $this->factory->post->create( array( 'post_author' => self::$author_id ) ); 269 // All 3 posts 270 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 293 294 $total_posts = self::$total_posts + 2; 295 296 // All posts in the database. 297 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 298 $request->set_param( 'per_page', self::$per_page ); 271 299 $response = rest_get_server()->dispatch( $request ); 272 300 $this->assertEquals( 200, $response->get_status() ); 273 $this->assertEquals( 3, count( $response->get_data() ) ); 274 // 1 of 3 posts 275 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 301 $this->assertEquals( $total_posts, count( $response->get_data() ) ); 302 303 // Exclude editor and author. 304 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 305 $request->set_param( 'per_page', self::$per_page ); 276 306 $request->set_param( 'author_exclude', array( self::$editor_id, self::$author_id ) ); 277 307 $response = rest_get_server()->dispatch( $request ); 278 308 $this->assertEquals( 200, $response->get_status() ); 279 309 $data = $response->get_data(); 280 $this->assertEquals( 1, count( $data ) );310 $this->assertEquals( $total_posts - 2, count( $data ) ); 281 311 $this->assertNotEquals( self::$editor_id, $data[0]['author'] ); 282 312 $this->assertNotEquals( self::$author_id, $data[0]['author'] ); 283 // 2 of 3 posts 284 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 313 314 // Exclude editor. 315 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 316 $request->set_param( 'per_page', self::$per_page ); 285 317 $request->set_param( 'author_exclude', self::$editor_id ); 286 318 $response = rest_get_server()->dispatch( $request ); 287 319 $this->assertEquals( 200, $response->get_status() ); 288 320 $data = $response->get_data(); 289 $this->assertEquals( 2, count( $data ) );321 $this->assertEquals( $total_posts - 1, count( $data ) ); 290 322 $this->assertNotEquals( self::$editor_id, $data[0]['author'] ); 291 323 $this->assertNotEquals( self::$editor_id, $data[1]['author'] ); 292 // invalid author_exclude errors 324 325 // Invalid 'author_exclude' should error. 293 326 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 294 327 $request->set_param( 'author_exclude', 'invalid' ); … … 299 332 public function test_get_items_include_query() { 300 333 $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 301 $this->factory->post->create( array( 'post_status' => 'publish' ) ); 302 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 303 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 304 // Orderby=>desc 305 $request->set_param( 'include', array( $id1, $id3 ) ); 334 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 335 336 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 337 338 // Order defaults to 'desc'. 339 $request->set_param( 'include', array( $id1, $id2 ) ); 306 340 $response = rest_get_server()->dispatch( $request ); 307 341 $data = $response->get_data(); 308 342 $this->assertEquals( 2, count( $data ) ); 309 $this->assertEquals( $id 3, $data[0]['id'] );343 $this->assertEquals( $id2, $data[0]['id'] ); 310 344 $this->assertPostsOrderedBy( '{posts}.post_date DESC' ); 311 // Orderby=>include 345 346 // 'orderby' => 'include' 312 347 $request->set_param( 'orderby', 'include' ); 313 348 $response = rest_get_server()->dispatch( $request ); … … 315 350 $this->assertEquals( 2, count( $data ) ); 316 351 $this->assertEquals( $id1, $data[0]['id'] ); 317 $this->assertPostsOrderedBy( "FIELD({posts}.ID,$id1,$id3)" ); 318 // Invalid include should error 352 $this->assertPostsOrderedBy( "FIELD({posts}.ID,$id1,$id2)" ); 353 354 // Invalid 'include' should error. 319 355 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 320 356 $request->set_param( 'include', 'invalid' ); … … 421 457 422 458 public function test_get_items_exclude_query() { 423 $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 424 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 459 $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 460 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 461 425 462 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 426 463 $response = rest_get_server()->dispatch( $request ); 427 464 $data = $response->get_data(); 428 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 429 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 465 $ids = wp_list_pluck( $data, 'id' ); 466 $this->assertTrue( in_array( $id1, $ids, true ) ); 467 $this->assertTrue( in_array( $id2, $ids, true ) ); 430 468 431 469 $request->set_param( 'exclude', array( $id2 ) ); 432 470 $response = rest_get_server()->dispatch( $request ); 433 471 $data = $response->get_data(); 434 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 435 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 472 $ids = wp_list_pluck( $data, 'id' ); 473 $this->assertTrue( in_array( $id1, $ids, true ) ); 474 $this->assertFalse( in_array( $id2, $ids, true ) ); 436 475 437 476 $request->set_param( 'exclude', "$id2" ); 438 477 $response = rest_get_server()->dispatch( $request ); 439 478 $data = $response->get_data(); 440 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 441 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 479 $ids = wp_list_pluck( $data, 'id' ); 480 $this->assertTrue( in_array( $id1, $ids, true ) ); 481 $this->assertFalse( in_array( $id2, $ids, true ) ); 442 482 443 483 $request->set_param( 'exclude', 'invalid' ); … … 447 487 448 488 public function test_get_items_search_query() { 449 for ( $i = 0; $i < 5; $i++ ) {450 $this->factory->post->create( array( 'post_status' => 'publish' ) );451 }452 489 $this->factory->post->create( 453 490 array( … … 456 493 ) 457 494 ); 458 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 459 $response = rest_get_server()->dispatch( $request ); 460 $this->assertEquals( 7, count( $response->get_data() ) ); 495 $total_posts = self::$total_posts + 1; 496 497 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 498 $request->set_param( 'per_page', self::$per_page ); 499 $response = rest_get_server()->dispatch( $request ); 500 $this->assertEquals( $total_posts, count( $response->get_data() ) ); 501 461 502 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 462 503 $request->set_param( 'search', 'Search Result' ); … … 480 521 ) 481 522 ); 523 482 524 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 483 525 $request->set_param( 'slug', 'apple' ); … … 508 550 ) 509 551 ); 552 510 553 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 511 554 $request->set_param( 'slug', array( 'banana', 'peach' ) ); … … 541 584 ) 542 585 ); 586 543 587 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 544 588 $request->set_param( 'slug', 'apple,banana' ); … … 557 601 public function test_get_items_status_query() { 558 602 wp_set_current_user( 0 ); 603 559 604 $this->factory->post->create( array( 'post_status' => 'draft' ) ); 560 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 605 606 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 607 $request->set_param( 'per_page', self::$per_page ); 561 608 $request->set_param( 'status', 'publish' ); 562 609 $response = rest_get_server()->dispatch( $request ); 563 610 $this->assertEquals( 200, $response->get_status() ); 564 $this->assertEquals( 1, count( $response->get_data() ) ); 611 $this->assertEquals( self::$total_posts, count( $response->get_data() ) ); 612 565 613 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 566 614 $request->set_param( 'status', 'draft' ); 567 615 $response = rest_get_server()->dispatch( $request ); 568 616 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 569 wp_set_current_user( self::$editor_id ); 617 618 wp_set_current_user( self::$editor_id ); 619 570 620 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 571 621 $request->set_param( 'status', 'draft' ); … … 636 686 637 687 wp_set_current_user( self::$private_reader_id ); 688 638 689 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 639 690 $request->set_param( 'status', array( 'private', 'future' ) ); … … 645 696 public function test_get_items_invalid_status_query() { 646 697 wp_set_current_user( 0 ); 698 647 699 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 648 700 $request->set_param( 'status', 'invalid' ); … … 657 709 ) 658 710 ); 711 659 712 wp_set_current_user( 0 ); 660 713 … … 695 748 ) 696 749 ); 750 697 751 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 698 752 $request->set_param( 'search', 'Apple' ); 699 // order defaults to 'desc' 753 754 // Order defaults to 'desc'. 700 755 $request->set_param( 'orderby', 'title' ); 701 756 $response = rest_get_server()->dispatch( $request ); … … 703 758 $this->assertEquals( 'Apple Sauce', $data[0]['title']['rendered'] ); 704 759 $this->assertPostsOrderedBy( '{posts}.post_title DESC' ); 705 // order=>asc 760 761 // 'order' => 'asc'. 706 762 $request->set_param( 'order', 'asc' ); 707 763 $response = rest_get_server()->dispatch( $request ); … … 709 765 $this->assertEquals( 'Apple Cobbler', $data[0]['title']['rendered'] ); 710 766 $this->assertPostsOrderedBy( '{posts}.post_title ASC' ); 711 // order=>asc,id should fail 767 768 // 'order' => 'asc,id' should error. 712 769 $request->set_param( 'order', 'asc,id' ); 713 770 $response = rest_get_server()->dispatch( $request ); 714 771 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 715 // orderby=>content should fail (invalid param test) 772 773 // 'orderby' => 'content' should error (invalid param test). 716 774 $request->set_param( 'order', 'asc' ); 717 775 $request->set_param( 'orderby', 'content' ); … … 722 780 public function test_get_items_with_orderby_include_without_include_param() { 723 781 $this->factory->post->create( array( 'post_status' => 'publish' ) ); 782 724 783 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 725 784 $request->set_param( 'orderby', 'include' ); … … 818 877 819 878 public function test_get_items_with_orderby_relevance() { 820 $id1 = $this->factory->post->create(879 $id1 = $this->factory->post->create( 821 880 array( 822 881 'post_title' => 'Title is more relevant', … … 825 884 ) 826 885 ); 827 $id2 = $this->factory->post->create(886 $id2 = $this->factory->post->create( 828 887 array( 829 888 'post_title' => 'Title is', … … 832 891 ) 833 892 ); 893 834 894 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 835 895 $request->set_param( 'orderby', 'relevance' ); … … 845 905 846 906 public function test_get_items_with_orderby_relevance_two_terms() { 847 $id1 = $this->factory->post->create(907 $id1 = $this->factory->post->create( 848 908 array( 849 909 'post_title' => 'Title is more relevant', … … 852 912 ) 853 913 ); 854 $id2 = $this->factory->post->create(914 $id2 = $this->factory->post->create( 855 915 array( 856 916 'post_title' => 'Title is', … … 859 919 ) 860 920 ); 921 861 922 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 862 923 $request->set_param( 'orderby', 'relevance' ); … … 879 940 880 941 public function test_get_items_offset_query() { 881 $id1 = self::$post_id; 882 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 883 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 884 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 885 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 942 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 943 $request->set_param( 'per_page', self::$per_page ); 886 944 $request->set_param( 'offset', 1 ); 887 945 $response = rest_get_server()->dispatch( $request ); 888 $this->assertCount( 3, $response->get_data() ); 889 // 'offset' works with 'per_page' 946 $this->assertCount( self::$total_posts - 1, $response->get_data() ); 947 948 // 'offset' works with 'per_page'. 890 949 $request->set_param( 'per_page', 2 ); 891 950 $response = rest_get_server()->dispatch( $request ); 892 951 $this->assertCount( 2, $response->get_data() ); 893 // 'offset' takes priority over 'page' 952 953 // 'offset' takes priority over 'page'. 894 954 $request->set_param( 'page', 2 ); 895 955 $response = rest_get_server()->dispatch( $request ); 896 956 $this->assertCount( 2, $response->get_data() ); 897 // Invalid 'offset' should error 957 958 // Invalid 'offset' should error. 898 959 $request->set_param( 'offset', 'moreplease' ); 899 960 $response = rest_get_server()->dispatch( $request ); … … 903 964 public function test_get_items_tags_query() { 904 965 $id1 = self::$post_id; 905 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );906 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );907 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );908 966 $tag = wp_insert_term( 'My Tag', 'post_tag' ); 909 967 910 968 wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' ); 969 911 970 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 912 971 $request->set_param( 'tags', array( $tag['term_id'] ) ); … … 925 984 $tag = wp_insert_term( 'My Tag', 'post_tag' ); 926 985 986 $total_posts = self::$total_posts + 3; 987 927 988 wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' ); 928 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 989 990 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 991 $request->set_param( 'per_page', self::$per_page ); 929 992 $request->set_param( 'tags_exclude', array( $tag['term_id'] ) ); 930 993 931 994 $response = rest_get_server()->dispatch( $request ); 932 995 $data = $response->get_data(); 933 $this->assertCount( 3, $data );996 $this->assertCount( $total_posts - 1, $data ); 934 997 $this->assertEquals( $id4, $data[0]['id'] ); 935 998 $this->assertEquals( $id3, $data[1]['id'] ); … … 940 1003 $id1 = self::$post_id; 941 1004 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 942 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );943 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );944 1005 $tag = wp_insert_term( 'My Tag', 'post_tag' ); 945 1006 $category = wp_insert_term( 'My Category', 'category' ); … … 967 1028 $id1 = self::$post_id; 968 1029 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 969 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );970 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );971 1030 $tag = wp_insert_term( 'My Tag', 'post_tag' ); 972 1031 $category = wp_insert_term( 'My Category', 'category' ); … … 990 1049 public function test_get_items_tags_and_categories_exclude_query() { 991 1050 $id1 = self::$post_id; 1051 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 1052 $tag = wp_insert_term( 'My Tag', 'post_tag' ); 1053 $category = wp_insert_term( 'My Category', 'category' ); 1054 1055 wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' ); 1056 wp_set_object_terms( $id2, array( $tag['term_id'] ), 'post_tag' ); 1057 wp_set_object_terms( $id1, array( $category['term_id'] ), 'category' ); 1058 1059 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1060 $request->set_param( 'tags', array( $tag['term_id'] ) ); 1061 $request->set_param( 'categories_exclude', array( $category['term_id'] ) ); 1062 1063 $response = rest_get_server()->dispatch( $request ); 1064 $data = $response->get_data(); 1065 $this->assertCount( 1, $data ); 1066 $this->assertEquals( $id2, $data[0]['id'] ); 1067 1068 $request->set_param( 'tags_exclude', array( 'my-tag' ) ); 1069 $response = rest_get_server()->dispatch( $request ); 1070 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1071 } 1072 1073 /** 1074 * @ticket 44326 1075 */ 1076 public function test_get_items_tags_or_categories_exclude_query() { 1077 $id1 = end( self::$post_ids ); 992 1078 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 993 1079 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); … … 996 1082 $category = wp_insert_term( 'My Category', 'category' ); 997 1083 998 wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' ); 999 wp_set_object_terms( $id2, array( $tag['term_id'] ), 'post_tag' ); 1000 wp_set_object_terms( $id1, array( $category['term_id'] ), 'category' ); 1001 1002 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1003 $request->set_param( 'tags', array( $tag['term_id'] ) ); 1004 $request->set_param( 'categories_exclude', array( $category['term_id'] ) ); 1005 1006 $response = rest_get_server()->dispatch( $request ); 1007 $data = $response->get_data(); 1008 $this->assertCount( 1, $data ); 1009 $this->assertEquals( $id2, $data[0]['id'] ); 1010 1011 $request->set_param( 'tags_exclude', array( 'my-tag' ) ); 1012 $response = rest_get_server()->dispatch( $request ); 1013 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1014 } 1015 1016 /** 1017 * @ticket 44326 1018 */ 1019 public function test_get_items_tags_or_categories_exclude_query() { 1020 $id1 = self::$post_id; 1021 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 1022 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 1023 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 1024 $tag = wp_insert_term( 'My Tag', 'post_tag' ); 1025 $category = wp_insert_term( 'My Category', 'category' ); 1084 $total_posts = self::$total_posts + 3; 1026 1085 1027 1086 wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' ); … … 1031 1090 1032 1091 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1092 $request->set_param( 'per_page', self::$per_page ); 1033 1093 $request->set_param( 'tags', array( $tag['term_id'] ) ); 1034 1094 $request->set_param( 'categories_exclude', array( $category['term_id'] ) ); … … 1038 1098 $response = rest_get_server()->dispatch( $request ); 1039 1099 $data = $response->get_data(); 1040 $this->assertCount( 3, $data );1100 $this->assertCount( $total_posts - 1, $data ); 1041 1101 $this->assertEquals( $id4, $data[0]['id'] ); 1042 1102 $this->assertEquals( $id2, $data[1]['id'] ); … … 1082 1142 $id1 = self::$post_id; 1083 1143 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 1084 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );1085 1144 1086 1145 update_option( 'sticky_posts', array( $id2 ) ); … … 1117 1176 1118 1177 public function test_get_items_sticky_no_sticky_posts() { 1119 $id1 = self::$post_id;1120 1121 1178 update_option( 'sticky_posts', array() ); 1122 1179 … … 1154 1211 1155 1212 public function test_get_items_not_sticky() { 1156 $id1 = self::$post_id;1213 $id1 = end( self::$post_ids ); 1157 1214 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 1158 1215 1216 $total_posts = self::$total_posts + 1; 1217 1159 1218 update_option( 'sticky_posts', array( $id2 ) ); 1160 1219 1161 1220 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1221 $request->set_param( 'per_page', self::$per_page ); 1162 1222 $request->set_param( 'sticky', false ); 1163 1223 1164 1224 $response = rest_get_server()->dispatch( $request ); 1165 $this->assertCount( 1, $response->get_data() );1225 $this->assertCount( $total_posts - 1, $response->get_data() ); 1166 1226 1167 1227 $posts = $response->get_data(); … … 1173 1233 1174 1234 public function test_get_items_not_sticky_with_exclude() { 1175 $id1 = self::$post_id;1235 $id1 = end( self::$post_ids ); 1176 1236 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 1177 1237 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 1178 1238 1239 $total_posts = self::$total_posts + 2; 1240 1179 1241 update_option( 'sticky_posts', array( $id2 ) ); 1180 1242 1181 1243 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1244 $request->set_param( 'per_page', self::$per_page ); 1182 1245 $request->set_param( 'sticky', false ); 1183 1246 $request->set_param( 'exclude', array( $id3 ) ); 1184 1247 1185 1248 $response = rest_get_server()->dispatch( $request ); 1186 $this->assertCount( 1, $response->get_data() );1249 $this->assertCount( $total_posts - 2, $response->get_data() ); 1187 1250 1188 1251 $posts = $response->get_data(); 1189 $post = $posts[0]; 1190 $this->assertEquals( $id1, $post['id'] ); 1252 $ids = wp_list_pluck( $posts, 'id' ); 1253 $this->assertTrue( in_array( $id1, $ids, true ) ); 1254 $this->assertFalse( in_array( $id2, $ids, true ) ); 1255 $this->assertFalse( in_array( $id3, $ids, true ) ); 1191 1256 1192 1257 $this->assertPostsWhere( " AND {posts}.ID NOT IN ($id3,$id2) AND {posts}.post_type = 'post' AND (({posts}.post_status = 'publish'))" ); … … 1198 1263 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 1199 1264 1265 $total_posts = self::$total_posts + 2; 1266 1200 1267 update_option( 'sticky_posts', array() ); 1201 1268 1202 1269 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1270 $request->set_param( 'per_page', self::$per_page ); 1203 1271 $request->set_param( 'sticky', false ); 1204 1272 $request->set_param( 'exclude', array( $id3 ) ); 1205 1273 1206 1274 $response = rest_get_server()->dispatch( $request ); 1207 $this->assertCount( 2, $response->get_data() );1275 $this->assertCount( $total_posts - 1, $response->get_data() ); 1208 1276 1209 1277 $posts = $response->get_data(); 1210 1278 $ids = wp_list_pluck( $posts, 'id' ); 1211 sort( $ids ); 1212 $this->assertEquals( array( $id1, $id2 ), $ids ); 1279 $this->assertTrue( in_array( $id1, $ids, true ) ); 1280 $this->assertTrue( in_array( $id2, $ids, true ) ); 1281 $this->assertFalse( in_array( $id3, $ids, true ) ); 1213 1282 1214 1283 $this->assertPostsWhere( " AND {posts}.ID NOT IN ($id3) AND {posts}.post_type = 'post' AND (({posts}.post_status = 'publish'))" ); … … 1216 1285 1217 1286 public function test_get_items_pagination_headers() { 1218 // Start of the index 1219 for ( $i = 0; $i < 49; $i++ ) { 1220 $this->factory->post->create( 1221 array( 1222 'post_title' => "Post {$i}", 1223 ) 1224 ); 1225 } 1287 $total_posts = self::$total_posts; 1288 $total_pages = (int) ceil( $total_posts / 10 ); 1289 1290 // Start of the index. 1226 1291 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1227 1292 $response = rest_get_server()->dispatch( $request ); 1228 1293 $headers = $response->get_headers(); 1229 $this->assertEquals( 50, $headers['X-WP-Total'] );1230 $this->assertEquals( 5, $headers['X-WP-TotalPages'] );1294 $this->assertEquals( $total_posts, $headers['X-WP-Total'] ); 1295 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 1231 1296 $next_link = add_query_arg( 1232 1297 array( … … 1237 1302 $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) ); 1238 1303 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 1239 // 3rd page 1240 $this->factory->post->create( 1241 array( 1242 'post_title' => 'Post 51', 1243 ) 1244 ); 1304 1305 // 3rd page. 1306 $this->factory->post->create(); 1307 $total_posts++; 1308 $total_pages++; 1245 1309 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1246 1310 $request->set_param( 'page', 3 ); 1247 1311 $response = rest_get_server()->dispatch( $request ); 1248 1312 $headers = $response->get_headers(); 1249 $this->assertEquals( 51, $headers['X-WP-Total'] );1250 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );1313 $this->assertEquals( $total_posts, $headers['X-WP-Total'] ); 1314 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 1251 1315 $prev_link = add_query_arg( 1252 1316 array( … … 1263 1327 ); 1264 1328 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 1265 // Last page 1266 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1267 $request->set_param( 'page', 6 ); 1329 1330 // Last page. 1331 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1332 $request->set_param( 'page', $total_pages ); 1268 1333 $response = rest_get_server()->dispatch( $request ); 1269 1334 $headers = $response->get_headers(); 1270 $this->assertEquals( 51, $headers['X-WP-Total'] );1271 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );1335 $this->assertEquals( $total_posts, $headers['X-WP-Total'] ); 1336 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 1272 1337 $prev_link = add_query_arg( 1273 1338 array( 1274 'page' => 5,1339 'page' => $total_pages - 1, 1275 1340 ), 1276 1341 rest_url( '/wp/v2/posts' ) … … 1279 1344 $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); 1280 1345 1281 // Out of bounds 1282 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1283 $request->set_param( 'page', 8);1346 // Out of bounds. 1347 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1348 $request->set_param( 'page', 100 ); 1284 1349 $response = rest_get_server()->dispatch( $request ); 1285 1350 $headers = $response->get_headers(); … … 1287 1352 1288 1353 // With query params. 1289 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1354 $total_pages = (int) ceil( $total_posts / 5 ); 1355 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1290 1356 $request->set_query_params( 1291 1357 array( … … 1296 1362 $response = rest_get_server()->dispatch( $request ); 1297 1363 $headers = $response->get_headers(); 1298 $this->assertEquals( 51, $headers['X-WP-Total'] );1299 $this->assertEquals( 11, $headers['X-WP-TotalPages'] );1364 $this->assertEquals( $total_posts, $headers['X-WP-Total'] ); 1365 $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] ); 1300 1366 $prev_link = add_query_arg( 1301 1367 array( … … 1321 1387 // Drafts status query var inaccessible to unauthorized users. 1322 1388 wp_set_current_user( 0 ); 1389 1323 1390 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1324 1391 $request->set_param( 'status', 'draft' ); … … 1328 1395 // Users with 'read_private_posts' cap shouldn't also be able to view drafts. 1329 1396 wp_set_current_user( self::$private_reader_id ); 1397 1330 1398 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1331 1399 $request->set_param( 'status', 'draft' ); … … 1335 1403 // But drafts are accessible to authorized users. 1336 1404 wp_set_current_user( self::$editor_id ); 1337 $response = rest_get_server()->dispatch( $request ); 1338 $ data = $response->get_data();1339 1405 1406 $response = rest_get_server()->dispatch( $request ); 1407 $data = $response->get_data(); 1340 1408 $this->assertEquals( $draft_id, $data[0]['id'] ); 1341 1409 } … … 1348 1416 1349 1417 wp_set_current_user( 0 ); 1418 1350 1419 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1351 1420 $request->set_param( 'status', 'private' ); … … 1354 1423 1355 1424 wp_set_current_user( self::$private_reader_id ); 1425 1356 1426 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1357 1427 $request->set_param( 'status', 'private' ); … … 1521 1591 ) 1522 1592 ); 1593 1523 1594 wp_set_current_user( 0 ); 1524 1595 … … 1553 1624 public function test_get_post_list_context_without_permission() { 1554 1625 wp_set_current_user( 0 ); 1626 1555 1627 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1556 1628 $request->set_query_params( … … 1566 1638 public function test_get_post_context_without_permission() { 1567 1639 wp_set_current_user( 0 ); 1640 1568 1641 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1569 1642 $request->set_query_params( … … 1605 1678 ); 1606 1679 1607 $post = get_post( $post_id ); 1680 $post = get_post( $post_id ); 1681 1608 1682 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1609 1683 $request->set_param( 'password', '$inthebananastand' ); … … 1626 1700 ); 1627 1701 1628 $post = get_post( $post_id ); 1702 $post = get_post( $post_id ); 1703 1629 1704 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1630 1705 $request->set_param( 'password', 'wrongpassword' ); … … 1635 1710 1636 1711 public function test_get_post_with_password_without_permission() { 1637 $post_id = $this->factory->post->create(1712 $post_id = $this->factory->post->create( 1638 1713 array( 1639 1714 'post_password' => '$inthebananastand', … … 1642 1717 ) 1643 1718 ); 1719 1644 1720 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1645 1721 $response = rest_get_server()->dispatch( $request ); … … 1704 1780 ) 1705 1781 ); 1782 1706 1783 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1707 1784 $request->set_param( 'context', 'edit' ); … … 1714 1791 register_post_status( 'testpubstatus', array( 'public' => true ) ); 1715 1792 register_post_status( 'testprivtatus', array( 'public' => false ) ); 1716 // Public status 1793 1794 // Public status. 1717 1795 wp_update_post( 1718 1796 array( … … 1721 1799 ) 1722 1800 ); 1801 1723 1802 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1724 1803 $response = rest_get_server()->dispatch( $request ); 1725 1804 $this->assertEquals( 200, $response->get_status() ); 1726 // Private status 1805 1806 // Private status. 1727 1807 wp_update_post( 1728 1808 array( … … 1731 1811 ) 1732 1812 ); 1813 1733 1814 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1734 1815 $response = rest_get_server()->dispatch( $request ); … … 1748 1829 public function test_prepare_item_limit_fields() { 1749 1830 wp_set_current_user( self::$editor_id ); 1831 1750 1832 $endpoint = new WP_REST_Posts_Controller( 'post' ); 1751 1833 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); … … 1775 1857 1776 1858 wp_set_current_user( self::$editor_id ); 1859 1777 1860 $endpoint = new WP_REST_Posts_Controller( 'post' ); 1778 $request = new WP_REST_R EQUEST( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );1861 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1779 1862 1780 1863 $request->set_param( 'context', 'edit' ); … … 1810 1893 1811 1894 wp_set_current_user( self::$editor_id ); 1895 1812 1896 $endpoint = new WP_REST_Posts_Controller( 'post' ); 1813 $request = new WP_REST_R EQUEST( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );1897 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1814 1898 1815 1899 $request->set_param( 'context', 'edit' ); … … 1920 2004 public function test_create_post_date( $status, $params, $results ) { 1921 2005 wp_set_current_user( self::$editor_id ); 2006 1922 2007 update_option( 'timezone_string', $params['timezone_string'] ); 1923 2008 … … 1953 2038 public function test_create_item_with_template() { 1954 2039 wp_set_current_user( self::$editor_id ); 2040 1955 2041 add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) ); 1956 2042 … … 2002 2088 public function test_create_item_with_template_none() { 2003 2089 wp_set_current_user( self::$editor_id ); 2090 2004 2091 add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) ); 2005 2092 update_post_meta( self::$post_id, '_wp_page_template', 'post-my-test-template.php' ); … … 2050 2137 public function test_create_post_as_contributor() { 2051 2138 wp_set_current_user( self::$contributor_id ); 2139 2052 2140 update_option( 'timezone_string', 'America/Chicago' ); 2053 2141 … … 2183 2271 public function test_create_post_private_without_permission() { 2184 2272 wp_set_current_user( self::$author_id ); 2273 2185 2274 $user = wp_get_current_user(); 2186 2275 $user->add_cap( 'publish_posts', false ); … … 2204 2293 public function test_create_post_publish_without_permission() { 2205 2294 wp_set_current_user( self::$author_id ); 2295 2206 2296 $user = wp_get_current_user(); 2207 2297 $user->add_cap( 'publish_posts', false ); … … 2409 2499 2410 2500 $data = $response->get_data(); 2411 2412 2501 $this->assertEquals( '0', $data['password'] ); 2413 2502 } … … 2552 2641 $request->set_body_params( $params ); 2553 2642 $response = rest_get_server()->dispatch( $request ); 2554 $new_data = $response->get_data(); 2555 $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] ); 2643 2644 $data = $response->get_data(); 2645 $this->assertEquals( "Rob O'Rourke's Diary", $data['title']['raw'] ); 2556 2646 } 2557 2647 2558 2648 public function test_create_post_with_categories() { 2559 2649 wp_set_current_user( self::$editor_id ); 2650 2560 2651 $category = wp_insert_term( 'Test Category', 'category' ); 2561 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 2562 $params = $this->set_post_data( 2652 2653 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 2654 $params = $this->set_post_data( 2563 2655 array( 2564 2656 'password' => 'testing', … … 2577 2669 public function test_create_post_with_categories_as_csv() { 2578 2670 wp_set_current_user( self::$editor_id ); 2671 2579 2672 $category = wp_insert_term( 'Chicken', 'category' ); 2580 2673 $category2 = wp_insert_term( 'Ribs', 'category' ); 2581 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 2582 $params = $this->set_post_data( 2674 2675 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 2676 $params = $this->set_post_data( 2583 2677 array( 2584 2678 'categories' => $category['term_id'] . ',' . $category2['term_id'], … … 2594 2688 public function test_create_post_with_invalid_categories() { 2595 2689 wp_set_current_user( self::$editor_id ); 2690 2596 2691 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 2597 2692 $params = $this->set_post_data( … … 2618 2713 2619 2714 wp_set_current_user( self::$editor_id ); 2715 2620 2716 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 2621 2717 $params = $this->set_post_data( … … 2664 2760 public function test_update_item_no_change() { 2665 2761 wp_set_current_user( self::$editor_id ); 2762 2666 2763 $post = get_post( self::$post_id ); 2667 2764 … … 2709 2806 // Create a new test post. 2710 2807 $post_id = $this->factory->post->create(); 2808 2711 2809 wp_set_current_user( self::$editor_id ); 2712 2810 2713 2811 // Set the post date to the future. 2714 2812 $future_date = '2919-07-29T18:00:00'; 2715 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2813 2814 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2716 2815 $request->add_header( 'content-type', 'application/json' ); 2717 2816 $params = $this->set_post_data( … … 2797 2896 public function test_update_post_without_permission() { 2798 2897 wp_set_current_user( self::$editor_id ); 2898 2799 2899 $user = wp_get_current_user(); 2800 2900 $user->add_cap( 'edit_published_posts', false ); … … 2951 3051 public function test_update_post_date( $status, $params, $results ) { 2952 3052 wp_set_current_user( self::$editor_id ); 3053 2953 3054 update_option( 'timezone_string', $params['timezone_string'] ); 2954 3055 … … 3013 3114 3014 3115 wp_set_current_user( self::$editor_id ); 3116 3015 3117 update_option( 'timezone_string', 'America/Chicago' ); 3016 3118 … … 3191 3293 public function test_update_post_with_empty_password() { 3192 3294 wp_set_current_user( self::$editor_id ); 3295 3193 3296 wp_update_post( 3194 3297 array( … … 3281 3384 3282 3385 public function test_update_post_with_categories() { 3283 3284 wp_set_current_user( self::$editor_id ); 3386 wp_set_current_user( self::$editor_id ); 3387 3285 3388 $category = wp_insert_term( 'Test Category', 'category' ); 3286 3389 … … 3307 3410 $query = parse_url( $categories_path, PHP_URL_QUERY ); 3308 3411 parse_str( $query, $args ); 3412 3309 3413 $request = new WP_REST_Request( 'GET', $args['rest_route'] ); 3310 3414 unset( $args['rest_route'] ); … … 3317 3421 3318 3422 public function test_update_post_with_empty_categories() { 3319 3320 wp_set_current_user( self::$editor_id ); 3423 wp_set_current_user( self::$editor_id ); 3424 3321 3425 $category = wp_insert_term( 'Test Category', 'category' ); 3322 3426 wp_set_object_terms( self::$post_id, $category['term_id'], 'category' ); … … 3343 3447 3344 3448 wp_set_current_user( self::$editor_id ); 3449 3345 3450 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3346 3451 $params = $this->set_post_data( … … 3364 3469 public function test_update_item_with_template() { 3365 3470 wp_set_current_user( self::$editor_id ); 3471 3366 3472 add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) ); 3367 3473 … … 3393 3499 public function test_update_item_with_template_none() { 3394 3500 wp_set_current_user( self::$editor_id ); 3501 3395 3502 add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) ); 3396 3503 update_post_meta( self::$post_id, '_wp_page_template', 'post-my-test-template.php' ); … … 3425 3532 */ 3426 3533 public function test_update_item_with_same_template_that_no_longer_exists() { 3427 3428 3534 wp_set_current_user( self::$editor_id ); 3429 3535 … … 3598 3704 public function test_post_roundtrip_as_author( $raw, $expected ) { 3599 3705 wp_set_current_user( self::$author_id ); 3706 3600 3707 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); 3601 3708 $this->verify_post_roundtrip( $raw, $expected ); … … 3604 3711 public function test_post_roundtrip_as_editor_unfiltered_html() { 3605 3712 wp_set_current_user( self::$editor_id ); 3713 3606 3714 if ( is_multisite() ) { 3607 3715 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); … … 3655 3763 public function test_post_roundtrip_as_superadmin_unfiltered_html() { 3656 3764 wp_set_current_user( self::$superadmin_id ); 3765 3657 3766 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 3658 3767 $this->verify_post_roundtrip( … … 3681 3790 public function test_delete_item() { 3682 3791 $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) ); 3792 3683 3793 wp_set_current_user( self::$editor_id ); 3684 3794 … … 3695 3805 public function test_delete_item_skip_trash() { 3696 3806 $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) ); 3807 3697 3808 wp_set_current_user( self::$editor_id ); 3698 3809 … … 3709 3820 public function test_delete_item_already_trashed() { 3710 3821 $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) ); 3711 wp_set_current_user( self::$editor_id ); 3822 3823 wp_set_current_user( self::$editor_id ); 3824 3712 3825 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 3713 3826 $response = rest_get_server()->dispatch( $request ); … … 3728 3841 public function test_delete_post_invalid_post_type() { 3729 3842 $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 3843 3730 3844 wp_set_current_user( self::$editor_id ); 3731 3845 … … 3946 4060 ); 3947 4061 3948 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 3949 4062 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 3950 4063 $response = rest_get_server()->dispatch( $request ); 3951 4064 $data = $response->get_data(); … … 3958 4071 $post_id = $this->factory->post->create(); 3959 4072 3960 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 3961 4073 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 3962 4074 $response = rest_get_server()->dispatch( $request ); 3963 4075 $this->assertArrayHasKey( 'my_custom_int', $response->data ); … … 4044 4156 4045 4157 wp_set_current_user( self::$editor_id ); 4158 4046 4159 // Check for error on update. 4047 4160 $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); … … 4072 4185 4073 4186 public function test_publish_action_ldo_registered() { 4074 4075 4187 $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); 4076 4188 $data = $response->get_data(); … … 4084 4196 4085 4197 public function test_sticky_action_ldo_registered_for_posts() { 4086 4087 4198 $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); 4088 4199 $data = $response->get_data(); … … 4096 4207 4097 4208 public function test_sticky_action_ldo_not_registered_for_non_posts() { 4098 4099 4209 $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ) ); 4100 4210 $data = $response->get_data(); … … 4108 4218 4109 4219 public function test_author_action_ldo_registered_for_post_types_with_author_support() { 4110 4111 4220 $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); 4112 4221 $data = $response->get_data(); … … 4120 4229 4121 4230 public function test_author_action_ldo_not_registered_for_post_types_without_author_support() { 4122 4123 4231 remove_post_type_support( 'post', 'author' ); 4124 4232 … … 4140 4248 4141 4249 public function test_term_action_ldos_registered() { 4142 4143 4250 $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); 4144 4251 $data = $response->get_data(); … … 4160 4267 4161 4268 public function test_action_links_only_available_in_edit_context() { 4162 4163 4269 wp_set_current_user( self::$author_id ); 4164 4270 … … 4176 4282 4177 4283 public function test_publish_action_link_exists_for_author() { 4178 4179 4284 wp_set_current_user( self::$author_id ); 4180 4285 … … 4192 4297 4193 4298 public function test_publish_action_link_does_not_exist_for_contributor() { 4194 4195 4299 wp_set_current_user( self::$contributor_id ); 4196 4300 … … 4208 4312 4209 4313 public function test_sticky_action_exists_for_editor() { 4210 4211 4314 wp_set_current_user( self::$editor_id ); 4212 4315 … … 4224 4327 4225 4328 public function test_sticky_action_does_not_exist_for_author() { 4226 4227 4329 wp_set_current_user( self::$author_id ); 4228 4330 … … 4240 4342 4241 4343 public function test_sticky_action_does_not_exist_for_non_post_posts() { 4242 4243 4344 wp_set_current_user( self::$editor_id ); 4244 4345 … … 4262 4363 4263 4364 public function test_assign_author_action_exists_for_editor() { 4264 4265 4365 wp_set_current_user( self::$editor_id ); 4266 4366 … … 4278 4378 4279 4379 public function test_assign_author_action_does_not_exist_for_author() { 4280 4281 4380 wp_set_current_user( self::$author_id ); 4282 4381 … … 4294 4393 4295 4394 public function test_assign_author_action_does_not_exist_for_post_types_without_author_support() { 4296 4297 4395 remove_post_type_support( 'post', 'author' ); 4298 4396 … … 4312 4410 4313 4411 public function test_create_term_action_exists_for_editor() { 4314 4315 4412 wp_set_current_user( self::$editor_id ); 4316 4413 … … 4330 4427 4331 4428 public function test_create_term_action_non_hierarchical_exists_for_author() { 4332 4333 4429 wp_set_current_user( self::$author_id ); 4334 4430 … … 4346 4442 4347 4443 public function test_create_term_action_hierarchical_does_not_exists_for_author() { 4348 4349 4444 wp_set_current_user( self::$author_id ); 4350 4445 … … 4362 4457 4363 4458 public function test_assign_term_action_exists_for_contributor() { 4364 4365 4459 wp_set_current_user( self::$contributor_id ); 4366 4460 … … 4385 4479 public function test_assign_unfiltered_html_action_superadmin() { 4386 4480 $post_id = self::factory()->post->create(); 4481 4387 4482 wp_set_current_user( self::$superadmin_id ); 4483 4388 4484 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 4389 4485 $request->set_param( 'context', 'edit' ); … … 4395 4491 public function test_assign_unfiltered_html_action_editor() { 4396 4492 $post_id = self::factory()->post->create(); 4397 wp_set_current_user( self::$editor_id ); 4493 4494 wp_set_current_user( self::$editor_id ); 4495 4398 4496 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 4399 4497 $request->set_param( 'context', 'edit' ); … … 4410 4508 public function test_assign_unfiltered_html_action_author() { 4411 4509 $post_id = self::factory()->post->create(); 4510 4412 4511 wp_set_current_user( self::$author_id ); 4512 4413 4513 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 4414 4514 $request->set_param( 'context', 'edit' ); … … 4491 4591 */ 4492 4592 public function test_putting_same_publish_date_does_not_remove_floating_date() { 4493 4494 4593 wp_set_current_user( self::$superadmin_id ); 4495 4594 … … 4527 4626 */ 4528 4627 public function test_putting_different_publish_date_removes_floating_date() { 4529 4530 4628 wp_set_current_user( self::$superadmin_id ); 4531 4629 … … 4570 4668 */ 4571 4669 public function test_publishing_post_with_same_date_removes_floating_date() { 4572 4573 4670 wp_set_current_user( self::$superadmin_id ); 4574 4671
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)