- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r42056 r42343 26 26 self::$post_id = $factory->post->create(); 27 27 28 self::$superadmin_id = $factory->user->create( array( 29 'role' => 'administrator', 30 'user_login' => 'superadmin', 31 ) ); 32 self::$editor_id = $factory->user->create( array( 33 'role' => 'editor', 34 ) ); 35 self::$author_id = $factory->user->create( array( 36 'role' => 'author', 37 ) ); 38 self::$contributor_id = $factory->user->create( array( 39 'role' => 'contributor', 40 ) ); 28 self::$superadmin_id = $factory->user->create( 29 array( 30 'role' => 'administrator', 31 'user_login' => 'superadmin', 32 ) 33 ); 34 self::$editor_id = $factory->user->create( 35 array( 36 'role' => 'editor', 37 ) 38 ); 39 self::$author_id = $factory->user->create( 40 array( 41 'role' => 'author', 42 ) 43 ); 44 self::$contributor_id = $factory->user->create( 45 array( 46 'role' => 'contributor', 47 ) 48 ); 41 49 42 50 if ( is_multisite() ) { … … 67 75 public function setUp() { 68 76 parent::setUp(); 69 register_post_type( 'youseeme', array( 'supports' => array(), 'show_in_rest' => true ) ); 77 register_post_type( 78 'youseeme', array( 79 'supports' => array(), 80 'show_in_rest' => true, 81 ) 82 ); 70 83 add_filter( 'rest_pre_dispatch', array( $this, 'wpSetUpBeforeRequest' ), 10, 3 ); 71 84 add_filter( 'posts_clauses', array( $this, 'save_posts_clauses' ), 10, 2 ); … … 108 121 public function test_context_param() { 109 122 // Collection 110 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );111 $response = $this->server->dispatch( $request ); 112 $data = $response->get_data();123 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 124 $response = $this->server->dispatch( $request ); 125 $data = $response->get_data(); 113 126 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 114 127 $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); 115 128 // Single 116 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id );117 $response = $this->server->dispatch( $request ); 118 $data = $response->get_data();129 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id ); 130 $response = $this->server->dispatch( $request ); 131 $data = $response->get_data(); 119 132 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 120 133 $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); … … 122 135 123 136 public function test_registered_query_params() { 124 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );125 $response = $this->server->dispatch( $request ); 126 $data = $response->get_data();127 $keys = array_keys( $data['endpoints'][0]['args'] );137 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 138 $response = $this->server->dispatch( $request ); 139 $data = $response->get_data(); 140 $keys = array_keys( $data['endpoints'][0]['args'] ); 128 141 sort( $keys ); 129 $this->assertEquals( array( 130 'after', 131 'author', 132 'author_exclude', 133 'before', 134 'categories', 135 'categories_exclude', 136 'context', 137 'exclude', 138 'include', 139 'offset', 140 'order', 141 'orderby', 142 'page', 143 'per_page', 144 'search', 145 'slug', 146 'status', 147 'sticky', 148 'tags', 149 'tags_exclude', 150 ), $keys ); 142 $this->assertEquals( 143 array( 144 'after', 145 'author', 146 'author_exclude', 147 'before', 148 'categories', 149 'categories_exclude', 150 'context', 151 'exclude', 152 'include', 153 'offset', 154 'order', 155 'orderby', 156 'page', 157 'per_page', 158 'search', 159 'slug', 160 'status', 161 'sticky', 162 'tags', 163 'tags_exclude', 164 ), $keys 165 ); 151 166 } 152 167 153 168 public function test_registered_get_item_params() { 154 $request = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) );155 $response = $this->server->dispatch( $request ); 156 $data = $response->get_data();157 $keys = array_keys( $data['endpoints'][0]['args'] );169 $request = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 170 $response = $this->server->dispatch( $request ); 171 $data = $response->get_data(); 172 $keys = array_keys( $data['endpoints'][0]['args'] ); 158 173 sort( $keys ); 159 174 $this->assertEquals( array( 'context', 'id', 'password' ), $keys ); … … 161 176 162 177 public function test_get_items() { 163 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );178 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 164 179 $response = $this->server->dispatch( $request ); 165 180 … … 174 189 public function test_get_items_empty_query() { 175 190 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 176 $request->set_query_params( array( 177 'author' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, 178 ) ); 191 $request->set_query_params( 192 array( 193 'author' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, 194 ) 195 ); 179 196 $response = $this->server->dispatch( $request ); 180 197 … … 187 204 $this->factory->post->create( array( 'post_author' => self::$author_id ) ); 188 205 // All 3 posts 189 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );206 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 190 207 $response = $this->server->dispatch( $request ); 191 208 $this->assertEquals( 200, $response->get_status() ); … … 213 230 $this->factory->post->create( array( 'post_author' => self::$author_id ) ); 214 231 // All 3 posts 215 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );232 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 216 233 $response = $this->server->dispatch( $request ); 217 234 $this->assertEquals( 200, $response->get_status() ); … … 245 262 $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 246 263 $this->factory->post->create( array( 'post_status' => 'publish' ) ); 247 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );264 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 248 265 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 249 266 // Orderby=>desc 250 267 $request->set_param( 'include', array( $id1, $id3 ) ); 251 268 $response = $this->server->dispatch( $request ); 252 $data = $response->get_data();269 $data = $response->get_data(); 253 270 $this->assertEquals( 2, count( $data ) ); 254 271 $this->assertEquals( $id3, $data[0]['id'] ); … … 257 274 $request->set_param( 'orderby', 'include' ); 258 275 $response = $this->server->dispatch( $request ); 259 $data = $response->get_data();276 $data = $response->get_data(); 260 277 $this->assertEquals( 2, count( $data ) ); 261 278 $this->assertEquals( $id1, $data[0]['id'] ); … … 269 286 270 287 public function test_get_items_orderby_author_query() { 271 $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id ) ); 272 $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id ) ); 273 $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$author_id ) ); 288 $id2 = $this->factory->post->create( 289 array( 290 'post_status' => 'publish', 291 'post_author' => self::$editor_id, 292 ) 293 ); 294 $id3 = $this->factory->post->create( 295 array( 296 'post_status' => 'publish', 297 'post_author' => self::$editor_id, 298 ) 299 ); 300 $id1 = $this->factory->post->create( 301 array( 302 'post_status' => 'publish', 303 'post_author' => self::$author_id, 304 ) 305 ); 274 306 275 307 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); … … 278 310 279 311 $response = $this->server->dispatch( $request ); 280 $data = $response->get_data();312 $data = $response->get_data(); 281 313 282 314 $this->assertEquals( 200, $response->get_status() ); … … 302 334 303 335 $response = $this->server->dispatch( $request ); 304 $data = $response->get_data();336 $data = $response->get_data(); 305 337 306 338 $this->assertEquals( 200, $response->get_status() ); … … 313 345 314 346 public function test_get_items_orderby_parent_query() { 315 $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) ); 316 $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) ); 317 $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', 'post_parent' => $id1 ) ); 347 $id1 = $this->factory->post->create( 348 array( 349 'post_status' => 'publish', 350 'post_type' => 'page', 351 ) 352 ); 353 $id2 = $this->factory->post->create( 354 array( 355 'post_status' => 'publish', 356 'post_type' => 'page', 357 ) 358 ); 359 $id3 = $this->factory->post->create( 360 array( 361 'post_status' => 'publish', 362 'post_type' => 'page', 363 'post_parent' => $id1, 364 ) 365 ); 318 366 319 367 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); … … 322 370 323 371 $response = $this->server->dispatch( $request ); 324 $data = $response->get_data();372 $data = $response->get_data(); 325 373 326 374 $this->assertEquals( 200, $response->get_status() ); … … 335 383 336 384 public function test_get_items_exclude_query() { 337 $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) );338 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );339 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );340 $response = $this->server->dispatch( $request ); 341 $data = $response->get_data();385 $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 386 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 387 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 388 $response = $this->server->dispatch( $request ); 389 $data = $response->get_data(); 342 390 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 343 391 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); … … 345 393 $request->set_param( 'exclude', array( $id2 ) ); 346 394 $response = $this->server->dispatch( $request ); 347 $data = $response->get_data();395 $data = $response->get_data(); 348 396 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 349 397 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); … … 351 399 $request->set_param( 'exclude', "$id2" ); 352 400 $response = $this->server->dispatch( $request ); 353 $data = $response->get_data();401 $data = $response->get_data(); 354 402 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 355 403 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); … … 364 412 $this->factory->post->create( array( 'post_status' => 'publish' ) ); 365 413 } 366 $this->factory->post->create( array( 'post_title' => 'Search Result', 'post_status' => 'publish' ) ); 367 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 414 $this->factory->post->create( 415 array( 416 'post_title' => 'Search Result', 417 'post_status' => 'publish', 418 ) 419 ); 420 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 368 421 $response = $this->server->dispatch( $request ); 369 422 $this->assertEquals( 7, count( $response->get_data() ) ); … … 371 424 $request->set_param( 'search', 'Search Result' ); 372 425 $response = $this->server->dispatch( $request ); 373 $data = $response->get_data();426 $data = $response->get_data(); 374 427 $this->assertEquals( 1, count( $data ) ); 375 428 $this->assertEquals( 'Search Result', $data[0]['title']['rendered'] ); … … 377 430 378 431 public function test_get_items_slug_query() { 379 $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) ); 380 $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) ); 432 $this->factory->post->create( 433 array( 434 'post_title' => 'Apple', 435 'post_status' => 'publish', 436 ) 437 ); 438 $this->factory->post->create( 439 array( 440 'post_title' => 'Banana', 441 'post_status' => 'publish', 442 ) 443 ); 381 444 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 382 445 $request->set_param( 'slug', 'apple' ); … … 389 452 390 453 public function test_get_items_multiple_slugs_array_query() { 391 $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) ); 392 $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) ); 393 $this->factory->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish' ) ); 454 $this->factory->post->create( 455 array( 456 'post_title' => 'Apple', 457 'post_status' => 'publish', 458 ) 459 ); 460 $this->factory->post->create( 461 array( 462 'post_title' => 'Banana', 463 'post_status' => 'publish', 464 ) 465 ); 466 $this->factory->post->create( 467 array( 468 'post_title' => 'Peach', 469 'post_status' => 'publish', 470 ) 471 ); 394 472 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 395 473 $request->set_param( 'slug', array( 'banana', 'peach' ) ); … … 407 485 408 486 public function test_get_items_multiple_slugs_string_query() { 409 $this->factory->post->create( array( 'post_title' => 'Apple', 'post_status' => 'publish' ) ); 410 $this->factory->post->create( array( 'post_title' => 'Banana', 'post_status' => 'publish' ) ); 411 $this->factory->post->create( array( 'post_title' => 'Peach', 'post_status' => 'publish' ) ); 487 $this->factory->post->create( 488 array( 489 'post_title' => 'Apple', 490 'post_status' => 'publish', 491 ) 492 ); 493 $this->factory->post->create( 494 array( 495 'post_title' => 'Banana', 496 'post_status' => 'publish', 497 ) 498 ); 499 $this->factory->post->create( 500 array( 501 'post_title' => 'Peach', 502 'post_status' => 'publish', 503 ) 504 ); 412 505 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 413 506 $request->set_param( 'slug', 'apple,banana' ); … … 507 600 508 601 public function test_get_items_status_without_permissions() { 509 $draft_id = $this->factory->post->create( array( 510 'post_status' => 'draft', 511 ) ); 602 $draft_id = $this->factory->post->create( 603 array( 604 'post_status' => 'draft', 605 ) 606 ); 512 607 wp_set_current_user( 0 ); 513 608 514 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );609 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 515 610 $response = $this->server->dispatch( $request ); 516 611 … … 524 619 525 620 public function test_get_items_order_and_orderby() { 526 $this->factory->post->create( array( 'post_title' => 'Apple Pie', 'post_status' => 'publish' ) ); 527 $this->factory->post->create( array( 'post_title' => 'Apple Sauce', 'post_status' => 'publish' ) ); 528 $this->factory->post->create( array( 'post_title' => 'Apple Cobbler', 'post_status' => 'publish' ) ); 529 $this->factory->post->create( array( 'post_title' => 'Apple Coffee Cake', 'post_status' => 'publish' ) ); 621 $this->factory->post->create( 622 array( 623 'post_title' => 'Apple Pie', 624 'post_status' => 'publish', 625 ) 626 ); 627 $this->factory->post->create( 628 array( 629 'post_title' => 'Apple Sauce', 630 'post_status' => 'publish', 631 ) 632 ); 633 $this->factory->post->create( 634 array( 635 'post_title' => 'Apple Cobbler', 636 'post_status' => 'publish', 637 ) 638 ); 639 $this->factory->post->create( 640 array( 641 'post_title' => 'Apple Coffee Cake', 642 'post_status' => 'publish', 643 ) 644 ); 530 645 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 531 646 $request->set_param( 'search', 'Apple' ); … … 533 648 $request->set_param( 'orderby', 'title' ); 534 649 $response = $this->server->dispatch( $request ); 535 $data = $response->get_data();650 $data = $response->get_data(); 536 651 $this->assertEquals( 'Apple Sauce', $data[0]['title']['rendered'] ); 537 652 $this->assertPostsOrderedBy( '{posts}.post_title DESC' ); … … 539 654 $request->set_param( 'order', 'asc' ); 540 655 $response = $this->server->dispatch( $request ); 541 $data = $response->get_data();656 $data = $response->get_data(); 542 657 $this->assertEquals( 'Apple Cobbler', $data[0]['title']['rendered'] ); 543 658 $this->assertPostsOrderedBy( '{posts}.post_title ASC' ); … … 564 679 565 680 public function test_get_items_with_orderby_id() { 566 $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-13 02:26:48' ) ); 567 $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-12 02:26:48' ) ); 568 $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-11 02:26:48' ) ); 681 $id1 = $this->factory->post->create( 682 array( 683 'post_status' => 'publish', 684 'post_date' => '2016-01-13 02:26:48', 685 ) 686 ); 687 $id2 = $this->factory->post->create( 688 array( 689 'post_status' => 'publish', 690 'post_date' => '2016-01-12 02:26:48', 691 ) 692 ); 693 $id3 = $this->factory->post->create( 694 array( 695 'post_status' => 'publish', 696 'post_date' => '2016-01-11 02:26:48', 697 ) 698 ); 569 699 570 700 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); … … 573 703 574 704 $response = $this->server->dispatch( $request ); 575 $data = $response->get_data();705 $data = $response->get_data(); 576 706 577 707 // Default ORDER is DESC. … … 583 713 584 714 public function test_get_items_with_orderby_slug() { 585 $id1 = $this->factory->post->create( array( 'post_title' => 'ABC', 'post_name' => 'xyz', 'post_status' => 'publish' ) ); 586 $id2 = $this->factory->post->create( array( 'post_title' => 'XYZ', 'post_name' => 'abc', 'post_status' => 'publish' ) ); 715 $id1 = $this->factory->post->create( 716 array( 717 'post_title' => 'ABC', 718 'post_name' => 'xyz', 719 'post_status' => 'publish', 720 ) 721 ); 722 $id2 = $this->factory->post->create( 723 array( 724 'post_title' => 'XYZ', 725 'post_name' => 'abc', 726 'post_status' => 'publish', 727 ) 728 ); 587 729 588 730 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); … … 591 733 592 734 $response = $this->server->dispatch( $request ); 593 $data = $response->get_data();735 $data = $response->get_data(); 594 736 595 737 // Default ORDER is DESC. … … 602 744 $slugs = array( 'burrito', 'taco', 'chalupa' ); 603 745 foreach ( $slugs as $slug ) { 604 $this->factory->post->create( array( 'post_title' => $slug, 'post_name' => $slug, 'post_status' => 'publish' ) ); 746 $this->factory->post->create( 747 array( 748 'post_title' => $slug, 749 'post_name' => $slug, 750 'post_status' => 'publish', 751 ) 752 ); 605 753 } 606 754 … … 610 758 611 759 $response = $this->server->dispatch( $request ); 612 $data = $response->get_data();760 $data = $response->get_data(); 613 761 614 762 $this->assertEquals( 'taco', $data[0]['slug'] ); … … 618 766 619 767 public function test_get_items_with_orderby_relevance() { 620 $id1 = $this->factory->post->create( array( 'post_title' => 'Title is more relevant', 'post_content' => 'Content is', 'post_status' => 'publish' ) ); 621 $id2 = $this->factory->post->create( array( 'post_title' => 'Title is', 'post_content' => 'Content is less relevant', 'post_status' => 'publish' ) ); 768 $id1 = $this->factory->post->create( 769 array( 770 'post_title' => 'Title is more relevant', 771 'post_content' => 'Content is', 772 'post_status' => 'publish', 773 ) 774 ); 775 $id2 = $this->factory->post->create( 776 array( 777 'post_title' => 'Title is', 778 'post_content' => 'Content is less relevant', 779 'post_status' => 'publish', 780 ) 781 ); 622 782 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 623 783 $request->set_param( 'orderby', 'relevance' ); … … 633 793 634 794 public function test_get_items_with_orderby_relevance_two_terms() { 635 $id1 = $this->factory->post->create( array( 'post_title' => 'Title is more relevant', 'post_content' => 'Content is', 'post_status' => 'publish' ) ); 636 $id2 = $this->factory->post->create( array( 'post_title' => 'Title is', 'post_content' => 'Content is less relevant', 'post_status' => 'publish' ) ); 795 $id1 = $this->factory->post->create( 796 array( 797 'post_title' => 'Title is more relevant', 798 'post_content' => 'Content is', 799 'post_status' => 'publish', 800 ) 801 ); 802 $id2 = $this->factory->post->create( 803 array( 804 'post_title' => 'Title is', 805 'post_content' => 'Content is less relevant', 806 'post_status' => 'publish', 807 ) 808 ); 637 809 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 638 810 $request->set_param( 'orderby', 'relevance' ); … … 655 827 656 828 public function test_get_items_offset_query() { 657 $id1 = self::$post_id;658 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );659 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );660 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );829 $id1 = self::$post_id; 830 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 831 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 832 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 661 833 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 662 834 $request->set_param( 'offset', 1 ); … … 689 861 690 862 $response = $this->server->dispatch( $request ); 691 $data = $response->get_data();863 $data = $response->get_data(); 692 864 $this->assertCount( 1, $data ); 693 865 $this->assertEquals( $id1, $data[0]['id'] ); … … 706 878 707 879 $response = $this->server->dispatch( $request ); 708 $data = $response->get_data();880 $data = $response->get_data(); 709 881 $this->assertCount( 3, $data ); 710 882 $this->assertEquals( $id4, $data[0]['id'] ); … … 714 886 715 887 public function test_get_items_tags_and_categories_query() { 716 $id1 = self::$post_id;717 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );718 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );719 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );720 $tag = wp_insert_term( 'My Tag', 'post_tag' );888 $id1 = self::$post_id; 889 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 890 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 891 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 892 $tag = wp_insert_term( 'My Tag', 'post_tag' ); 721 893 $category = wp_insert_term( 'My Category', 'category' ); 722 894 … … 738 910 739 911 public function test_get_items_tags_and_categories_exclude_query() { 740 $id1 = self::$post_id;741 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );742 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );743 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );744 $tag = wp_insert_term( 'My Tag', 'post_tag' );912 $id1 = self::$post_id; 913 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 914 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 915 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 916 $tag = wp_insert_term( 'My Tag', 'post_tag' ); 745 917 $category = wp_insert_term( 'My Category', 'category' ); 746 918 … … 754 926 755 927 $response = $this->server->dispatch( $request ); 756 $data = $response->get_data();928 $data = $response->get_data(); 757 929 $this->assertCount( 1, $data ); 758 930 $this->assertEquals( $id2, $data[0]['id'] ); … … 776 948 777 949 $posts = $response->get_data(); 778 $post = $posts[0];950 $post = $posts[0]; 779 951 $this->assertEquals( $id2, $post['id'] ); 780 952 … … 815 987 816 988 $posts = $response->get_data(); 817 $post = $posts[0];989 $post = $posts[0]; 818 990 $this->assertEquals( $id1, $post['id'] ); 819 991 … … 871 1043 872 1044 $posts = $response->get_data(); 873 $post = $posts[0];1045 $post = $posts[0]; 874 1046 $this->assertEquals( $id1, $post['id'] ); 875 1047 … … 892 1064 893 1065 $posts = $response->get_data(); 894 $post = $posts[0];1066 $post = $posts[0]; 895 1067 $this->assertEquals( $id1, $post['id'] ); 896 1068 … … 913 1085 914 1086 $posts = $response->get_data(); 915 $ids = wp_list_pluck( $posts, 'id' );1087 $ids = wp_list_pluck( $posts, 'id' ); 916 1088 sort( $ids ); 917 1089 $this->assertEquals( array( $id1, $id2 ), $ids ); … … 923 1095 // Start of the index 924 1096 for ( $i = 0; $i < 49; $i++ ) { 925 $this->factory->post->create( array( 926 'post_title' => "Post {$i}", 927 ) ); 1097 $this->factory->post->create( 1098 array( 1099 'post_title' => "Post {$i}", 1100 ) 1101 ); 928 1102 } 929 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );930 $response = $this->server->dispatch( $request ); 931 $headers = $response->get_headers();1103 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1104 $response = $this->server->dispatch( $request ); 1105 $headers = $response->get_headers(); 932 1106 $this->assertEquals( 50, $headers['X-WP-Total'] ); 933 1107 $this->assertEquals( 5, $headers['X-WP-TotalPages'] ); 934 $next_link = add_query_arg( array( 935 'page' => 2, 936 ), rest_url( '/wp/v2/posts' ) ); 1108 $next_link = add_query_arg( 1109 array( 1110 'page' => 2, 1111 ), rest_url( '/wp/v2/posts' ) 1112 ); 937 1113 $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) ); 938 1114 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 939 1115 // 3rd page 940 $this->factory->post->create( array( 941 'post_title' => 'Post 51', 942 ) ); 1116 $this->factory->post->create( 1117 array( 1118 'post_title' => 'Post 51', 1119 ) 1120 ); 943 1121 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 944 1122 $request->set_param( 'page', 3 ); 945 1123 $response = $this->server->dispatch( $request ); 946 $headers = $response->get_headers();1124 $headers = $response->get_headers(); 947 1125 $this->assertEquals( 51, $headers['X-WP-Total'] ); 948 1126 $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); 949 $prev_link = add_query_arg( array( 950 'page' => 2, 951 ), rest_url( '/wp/v2/posts' ) ); 1127 $prev_link = add_query_arg( 1128 array( 1129 'page' => 2, 1130 ), rest_url( '/wp/v2/posts' ) 1131 ); 952 1132 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 953 $next_link = add_query_arg( array( 954 'page' => 4, 955 ), rest_url( '/wp/v2/posts' ) ); 1133 $next_link = add_query_arg( 1134 array( 1135 'page' => 4, 1136 ), rest_url( '/wp/v2/posts' ) 1137 ); 956 1138 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 957 1139 // Last page … … 959 1141 $request->set_param( 'page', 6 ); 960 1142 $response = $this->server->dispatch( $request ); 961 $headers = $response->get_headers();1143 $headers = $response->get_headers(); 962 1144 $this->assertEquals( 51, $headers['X-WP-Total'] ); 963 1145 $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); 964 $prev_link = add_query_arg( array( 965 'page' => 5, 966 ), rest_url( '/wp/v2/posts' ) ); 1146 $prev_link = add_query_arg( 1147 array( 1148 'page' => 5, 1149 ), rest_url( '/wp/v2/posts' ) 1150 ); 967 1151 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 968 1152 $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); … … 972 1156 $request->set_param( 'page', 8 ); 973 1157 $response = $this->server->dispatch( $request ); 974 $headers = $response->get_headers();1158 $headers = $response->get_headers(); 975 1159 $this->assertErrorResponse( 'rest_post_invalid_page_number', $response, 400 ); 976 1160 977 1161 // With query params. 978 1162 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 979 $request->set_query_params( array( 'per_page' => 5, 'page' => 2 ) ); 980 $response = $this->server->dispatch( $request ); 981 $headers = $response->get_headers(); 1163 $request->set_query_params( 1164 array( 1165 'per_page' => 5, 1166 'page' => 2, 1167 ) 1168 ); 1169 $response = $this->server->dispatch( $request ); 1170 $headers = $response->get_headers(); 982 1171 $this->assertEquals( 51, $headers['X-WP-Total'] ); 983 1172 $this->assertEquals( 11, $headers['X-WP-TotalPages'] ); 984 $prev_link = add_query_arg( array( 985 'per_page' => 5, 986 'page' => 1, 987 ), rest_url( '/wp/v2/posts' ) ); 1173 $prev_link = add_query_arg( 1174 array( 1175 'per_page' => 5, 1176 'page' => 1, 1177 ), rest_url( '/wp/v2/posts' ) 1178 ); 988 1179 $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); 989 $next_link = add_query_arg( array( 990 'per_page' => 5, 991 'page' => 3, 992 ), rest_url( '/wp/v2/posts' ) ); 1180 $next_link = add_query_arg( 1181 array( 1182 'per_page' => 5, 1183 'page' => 3, 1184 ), rest_url( '/wp/v2/posts' ) 1185 ); 993 1186 $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] ); 994 1187 } … … 998 1191 wp_set_current_user( 0 ); 999 1192 $draft_id = $this->factory->post->create( array( 'post_status' => 'draft' ) ); 1000 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );1193 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1001 1194 $request->set_param( 'status', 'draft' ); 1002 1195 $response = $this->server->dispatch( $request ); … … 1006 1199 wp_set_current_user( self::$editor_id ); 1007 1200 $response = $this->server->dispatch( $request ); 1008 $data = $response->get_data();1201 $data = $response->get_data(); 1009 1202 $this->assertCount( 1, $data ); 1010 1203 $this->assertEquals( $draft_id, $data[0]['id'] ); … … 1053 1246 $request->set_param( 'before', '2016-01-17T00:00:00Z' ); 1054 1247 $response = $this->server->dispatch( $request ); 1055 $data = $response->get_data();1248 $data = $response->get_data(); 1056 1249 $this->assertCount( 1, $data ); 1057 1250 $this->assertEquals( $post2, $data[0]['id'] ); … … 1059 1252 1060 1253 public function test_get_items_all_post_formats() { 1061 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );1062 $response = $this->server->dispatch( $request ); 1063 $data = $response->get_data();1254 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 1255 $response = $this->server->dispatch( $request ); 1256 $data = $response->get_data(); 1064 1257 1065 1258 $formats = array_values( get_post_format_slugs() ); … … 1069 1262 1070 1263 public function test_get_item() { 1071 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );1264 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1072 1265 $response = $this->server->dispatch( $request ); 1073 1266 … … 1076 1269 1077 1270 public function test_get_item_links() { 1078 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );1271 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1079 1272 $response = $this->server->dispatch( $request ); 1080 1273 … … 1097 1290 1098 1291 $term_links = $links['https://api.w.org/term']; 1099 $tag_link = $cat_link = $format_link = null;1292 $tag_link = $cat_link = $format_link = null; 1100 1293 foreach ( $term_links as $link ) { 1101 1294 if ( 'post_tag' === $link['attributes']['taxonomy'] ) { … … 1119 1312 1120 1313 public function test_get_item_links_no_author() { 1121 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );1122 $response = $this->server->dispatch( $request ); 1123 $links = $response->get_links();1314 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1315 $response = $this->server->dispatch( $request ); 1316 $links = $response->get_links(); 1124 1317 $this->assertFalse( isset( $links['author'] ) ); 1125 wp_update_post( array( 'ID' => self::$post_id, 'post_author' => self::$author_id ) ); 1126 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1127 $response = $this->server->dispatch( $request ); 1128 $links = $response->get_links(); 1318 wp_update_post( 1319 array( 1320 'ID' => self::$post_id, 1321 'post_author' => self::$author_id, 1322 ) 1323 ); 1324 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1325 $response = $this->server->dispatch( $request ); 1326 $links = $response->get_links(); 1129 1327 $this->assertEquals( rest_url( '/wp/v2/users/' . self::$author_id ), $links['author'][0]['href'] ); 1130 1328 } 1131 1329 1132 1330 public function test_get_post_without_permission() { 1133 $draft_id = $this->factory->post->create( array( 1134 'post_status' => 'draft', 1135 ) ); 1331 $draft_id = $this->factory->post->create( 1332 array( 1333 'post_status' => 'draft', 1334 ) 1335 ); 1136 1336 wp_set_current_user( 0 ); 1137 1337 1138 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $draft_id ) );1338 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $draft_id ) ); 1139 1339 $response = $this->server->dispatch( $request ); 1140 1340 … … 1143 1343 1144 1344 public function test_get_post_invalid_id() { 1145 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );1345 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 1146 1346 $response = $this->server->dispatch( $request ); 1147 1347 … … 1151 1351 public function test_get_post_list_context_with_permission() { 1152 1352 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1153 $request->set_query_params( array( 1154 'context' => 'edit', 1155 ) ); 1353 $request->set_query_params( 1354 array( 1355 'context' => 'edit', 1356 ) 1357 ); 1156 1358 1157 1359 wp_set_current_user( self::$editor_id ); … … 1165 1367 wp_set_current_user( 0 ); 1166 1368 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1167 $request->set_query_params( array( 1168 'context' => 'edit', 1169 ) ); 1369 $request->set_query_params( 1370 array( 1371 'context' => 'edit', 1372 ) 1373 ); 1170 1374 $response = $this->server->dispatch( $request ); 1171 1375 … … 1176 1380 wp_set_current_user( 0 ); 1177 1381 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1178 $request->set_query_params( array( 1179 'context' => 'edit', 1180 ) ); 1382 $request->set_query_params( 1383 array( 1384 'context' => 'edit', 1385 ) 1386 ); 1181 1387 $response = $this->server->dispatch( $request ); 1182 1388 … … 1185 1391 1186 1392 public function test_get_post_with_password() { 1187 $post_id = $this->factory->post->create( array( 1188 'post_password' => '$inthebananastand', 1189 ) ); 1190 1191 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1393 $post_id = $this->factory->post->create( 1394 array( 1395 'post_password' => '$inthebananastand', 1396 ) 1397 ); 1398 1399 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1192 1400 $response = $this->server->dispatch( $request ); 1193 1401 … … 1202 1410 1203 1411 public function test_get_post_with_password_using_password() { 1204 $post_id = $this->factory->post->create( array( 1205 'post_password' => '$inthebananastand', 1206 'post_content' => 'Some secret content.', 1207 'post_excerpt' => 'Some secret excerpt.', 1208 ) ); 1209 1210 $post = get_post( $post_id ); 1412 $post_id = $this->factory->post->create( 1413 array( 1414 'post_password' => '$inthebananastand', 1415 'post_content' => 'Some secret content.', 1416 'post_excerpt' => 'Some secret excerpt.', 1417 ) 1418 ); 1419 1420 $post = get_post( $post_id ); 1211 1421 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1212 1422 $request->set_param( 'password', '$inthebananastand' ); … … 1223 1433 1224 1434 public function test_get_post_with_password_using_incorrect_password() { 1225 $post_id = $this->factory->post->create( array( 1226 'post_password' => '$inthebananastand', 1227 ) ); 1228 1229 $post = get_post( $post_id ); 1435 $post_id = $this->factory->post->create( 1436 array( 1437 'post_password' => '$inthebananastand', 1438 ) 1439 ); 1440 1441 $post = get_post( $post_id ); 1230 1442 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1231 1443 $request->set_param( 'password', 'wrongpassword' ); … … 1236 1448 1237 1449 public function test_get_post_with_password_without_permission() { 1238 $post_id = $this->factory->post->create( array( 1239 'post_password' => '$inthebananastand', 1240 'post_content' => 'Some secret content.', 1241 'post_excerpt' => 'Some secret excerpt.', 1242 ) ); 1243 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1244 $response = $this->server->dispatch( $request ); 1245 $data = $response->get_data(); 1450 $post_id = $this->factory->post->create( 1451 array( 1452 'post_password' => '$inthebananastand', 1453 'post_content' => 'Some secret content.', 1454 'post_excerpt' => 'Some secret excerpt.', 1455 ) 1456 ); 1457 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 1458 $response = $this->server->dispatch( $request ); 1459 $data = $response->get_data(); 1246 1460 $this->check_get_post_response( $response, 'view' ); 1247 1461 $this->assertEquals( '', $data['content']['rendered'] ); … … 1255 1469 register_post_status( 'testprivtatus', array( 'public' => false ) ); 1256 1470 // Public status 1257 wp_update_post( array( 'ID' => self::$post_id, 'post_status' => 'testpubstatus' ) ); 1258 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1471 wp_update_post( 1472 array( 1473 'ID' => self::$post_id, 1474 'post_status' => 'testpubstatus', 1475 ) 1476 ); 1477 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1259 1478 $response = $this->server->dispatch( $request ); 1260 1479 $this->assertEquals( 200, $response->get_status() ); 1261 1480 // Private status 1262 wp_update_post( array( 'ID' => self::$post_id, 'post_status' => 'testprivtatus' ) ); 1263 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1481 wp_update_post( 1482 array( 1483 'ID' => self::$post_id, 1484 'post_status' => 'testprivtatus', 1485 ) 1486 ); 1487 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1264 1488 $response = $this->server->dispatch( $request ); 1265 1489 $this->assertEquals( 403, $response->get_status() ); … … 1298 1522 1299 1523 $cases_short = array( 1300 'set date without timezone' => array(1524 'set date without timezone' => array( 1301 1525 'statuses' => $all_statuses, 1302 1526 'params' => array( … … 1304 1528 'date' => '2016-12-12T14:00:00', 1305 1529 ), 1306 'results' => array(1307 'date' => '2016-12-12T14:00:00',1308 'date_gmt' => '2016-12-12T19:00:00',1530 'results' => array( 1531 'date' => '2016-12-12T14:00:00', 1532 'date_gmt' => '2016-12-12T19:00:00', 1309 1533 ), 1310 1534 ), … … 1315 1539 'date_gmt' => '2016-12-12T19:00:00', 1316 1540 ), 1317 'results' => array(1318 'date' => '2016-12-12T14:00:00',1319 'date_gmt' => '2016-12-12T19:00:00',1541 'results' => array( 1542 'date' => '2016-12-12T14:00:00', 1543 'date_gmt' => '2016-12-12T19:00:00', 1320 1544 ), 1321 1545 ), 1322 'set date with timezone' => array(1546 'set date with timezone' => array( 1323 1547 'statuses' => array( 'draft', 'publish' ), 1324 1548 'params' => array( … … 1326 1550 'date' => '2016-12-12T18:00:00-01:00', 1327 1551 ), 1328 'results' => array(1329 'date' => '2016-12-12T14:00:00',1330 'date_gmt' => '2016-12-12T19:00:00',1552 'results' => array( 1553 'date' => '2016-12-12T14:00:00', 1554 'date_gmt' => '2016-12-12T19:00:00', 1331 1555 ), 1332 1556 ), 1333 'set date_gmt with timezone' => array(1557 'set date_gmt with timezone' => array( 1334 1558 'statuses' => array( 'draft', 'publish' ), 1335 1559 'params' => array( … … 1337 1561 'date_gmt' => '2016-12-12T18:00:00-01:00', 1338 1562 ), 1339 'results' => array(1340 'date' => '2016-12-12T14:00:00',1341 'date_gmt' => '2016-12-12T19:00:00',1563 'results' => array( 1564 'date' => '2016-12-12T14:00:00', 1565 'date_gmt' => '2016-12-12T19:00:00', 1342 1566 ), 1343 1567 ), … … 1400 1624 // reregister the route as we now have a template available. 1401 1625 $GLOBALS['wp_rest_server']->override_by_default = true; 1402 $controller = new WP_REST_Posts_Controller( 'post' );1626 $controller = new WP_REST_Posts_Controller( 'post' ); 1403 1627 $controller->register_routes(); 1404 1628 $GLOBALS['wp_rest_server']->override_by_default = false; 1405 1629 1406 1630 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1407 $params = $this->set_post_data( array( 1408 'template' => 'post-my-test-template.php', 1409 ) ); 1410 $request->set_body_params( $params ); 1411 $response = $this->server->dispatch( $request ); 1412 1413 $data = $response->get_data(); 1631 $params = $this->set_post_data( 1632 array( 1633 'template' => 'post-my-test-template.php', 1634 ) 1635 ); 1636 $request->set_body_params( $params ); 1637 $response = $this->server->dispatch( $request ); 1638 1639 $data = $response->get_data(); 1414 1640 $post_template = get_page_template_slug( get_post( $data['id'] ) ); 1415 1641 … … 1427 1653 1428 1654 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1429 $params = $this->set_post_data( array( 1430 'template' => 'post-my-test-template.php', 1431 ) ); 1655 $params = $this->set_post_data( 1656 array( 1657 'template' => 'post-my-test-template.php', 1658 ) 1659 ); 1432 1660 $request->set_body_params( $params ); 1433 1661 $response = $this->server->dispatch( $request ); … … 1445 1673 1446 1674 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1447 $params = $this->set_post_data( array( 1448 'template' => '', 1449 ) ); 1450 $request->set_body_params( $params ); 1451 $response = $this->server->dispatch( $request ); 1452 1453 $data = $response->get_data(); 1675 $params = $this->set_post_data( 1676 array( 1677 'template' => '', 1678 ) 1679 ); 1680 $request->set_body_params( $params ); 1681 $response = $this->server->dispatch( $request ); 1682 1683 $data = $response->get_data(); 1454 1684 $post_template = get_page_template_slug( get_post( $data['id'] ) ); 1455 1685 … … 1474 1704 1475 1705 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1476 $params = $this->set_post_data( array( 1477 'id' => '3', 1478 ) ); 1706 $params = $this->set_post_data( 1707 array( 1708 'id' => '3', 1709 ) 1710 ); 1479 1711 $request->set_body_params( $params ); 1480 1712 $response = $this->server->dispatch( $request ); … … 1488 1720 1489 1721 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1490 $params = $this->set_post_data( array( 1491 // This results in a special `post_date_gmt` value of 1492 // '0000-00-00 00:00:00'. See #38883. 1493 'status' => 'pending', 1494 ) ); 1722 $params = $this->set_post_data( 1723 array( 1724 // This results in a special `post_date_gmt` value of 1725 // '0000-00-00 00:00:00'. See #38883. 1726 'status' => 'pending', 1727 ) 1728 ); 1495 1729 1496 1730 $request->set_body_params( $params ); … … 1512 1746 1513 1747 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1514 $params = $this->set_post_data( array( 1515 'sticky' => true, 1516 ) ); 1748 $params = $this->set_post_data( 1749 array( 1750 'sticky' => true, 1751 ) 1752 ); 1517 1753 $request->set_body_params( $params ); 1518 1754 $response = $this->server->dispatch( $request ); … … 1528 1764 1529 1765 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1530 $params = $this->set_post_data( array( 1531 'sticky' => true, 1532 'status' => 'pending', 1533 ) ); 1766 $params = $this->set_post_data( 1767 array( 1768 'sticky' => true, 1769 'status' => 'pending', 1770 ) 1771 ); 1534 1772 $request->set_body_params( $params ); 1535 1773 $response = $this->server->dispatch( $request ); … … 1542 1780 1543 1781 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1544 $params = $this->set_post_data(array( 1545 'author' => self::$editor_id, 1546 )); 1782 $params = $this->set_post_data( 1783 array( 1784 'author' => self::$editor_id, 1785 ) 1786 ); 1547 1787 $request->set_body_params( $params ); 1548 1788 $response = $this->server->dispatch( $request ); … … 1555 1795 1556 1796 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1557 $params = $this->set_post_data( array( 1558 'status' => 'draft', 1559 ) ); 1797 $params = $this->set_post_data( 1798 array( 1799 'status' => 'draft', 1800 ) 1801 ); 1560 1802 $request->set_body_params( $params ); 1561 1803 $response = $this->server->dispatch( $request ); … … 1568 1810 1569 1811 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1570 $params = $this->set_post_data( array( 1571 'status' => 'draft', 1572 ) ); 1573 $request->set_body_params( $params ); 1574 $response = $this->server->dispatch( $request ); 1575 1576 $data = $response->get_data(); 1812 $params = $this->set_post_data( 1813 array( 1814 'status' => 'draft', 1815 ) 1816 ); 1817 $request->set_body_params( $params ); 1818 $response = $this->server->dispatch( $request ); 1819 1820 $data = $response->get_data(); 1577 1821 $new_post = get_post( $data['id'] ); 1578 1822 $this->assertEquals( 'draft', $data['status'] ); … … 1580 1824 // Confirm dates are shimmed for gmt_offset 1581 1825 $post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 1582 $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) );1826 $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 1583 1827 1584 1828 $this->assertEquals( mysql_to_rfc3339( $post_modified_gmt ), $data['modified_gmt'] ); … … 1590 1834 1591 1835 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1592 $params = $this->set_post_data( array( 1593 'status' => 'private', 1594 ) ); 1595 $request->set_body_params( $params ); 1596 $response = $this->server->dispatch( $request ); 1597 1598 $data = $response->get_data(); 1836 $params = $this->set_post_data( 1837 array( 1838 'status' => 'private', 1839 ) 1840 ); 1841 $request->set_body_params( $params ); 1842 $response = $this->server->dispatch( $request ); 1843 1844 $data = $response->get_data(); 1599 1845 $new_post = get_post( $data['id'] ); 1600 1846 $this->assertEquals( 'private', $data['status'] ); … … 1611 1857 1612 1858 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1613 $params = $this->set_post_data( array( 1614 'status' => 'private', 1615 'author' => self::$author_id, 1616 ) ); 1859 $params = $this->set_post_data( 1860 array( 1861 'status' => 'private', 1862 'author' => self::$author_id, 1863 ) 1864 ); 1617 1865 $request->set_body_params( $params ); 1618 1866 $response = $this->server->dispatch( $request ); … … 1630 1878 1631 1879 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1632 $params = $this->set_post_data( array( 1633 'status' => 'publish', 1634 ) ); 1880 $params = $this->set_post_data( 1881 array( 1882 'status' => 'publish', 1883 ) 1884 ); 1635 1885 $request->set_body_params( $params ); 1636 1886 $response = $this->server->dispatch( $request ); … … 1643 1893 1644 1894 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1645 $params = $this->set_post_data( array( 1646 'status' => 'teststatus', 1647 ) ); 1895 $params = $this->set_post_data( 1896 array( 1897 'status' => 'teststatus', 1898 ) 1899 ); 1648 1900 $request->set_body_params( $params ); 1649 1901 $response = $this->server->dispatch( $request ); … … 1656 1908 1657 1909 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1658 $params = $this->set_post_data( array( 1659 'format' => 'gallery', 1660 ) ); 1661 $request->set_body_params( $params ); 1662 $response = $this->server->dispatch( $request ); 1663 1664 $data = $response->get_data(); 1910 $params = $this->set_post_data( 1911 array( 1912 'format' => 'gallery', 1913 ) 1914 ); 1915 $request->set_body_params( $params ); 1916 $response = $this->server->dispatch( $request ); 1917 1918 $data = $response->get_data(); 1665 1919 $new_post = get_post( $data['id'] ); 1666 1920 $this->assertEquals( 'gallery', $data['format'] ); … … 1672 1926 1673 1927 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1674 $params = $this->set_post_data( array( 1675 'format' => 'standard', 1676 ) ); 1677 $request->set_body_params( $params ); 1678 $response = $this->server->dispatch( $request ); 1679 1680 $data = $response->get_data(); 1928 $params = $this->set_post_data( 1929 array( 1930 'format' => 'standard', 1931 ) 1932 ); 1933 $request->set_body_params( $params ); 1934 $response = $this->server->dispatch( $request ); 1935 1936 $data = $response->get_data(); 1681 1937 $new_post = get_post( $data['id'] ); 1682 1938 $this->assertEquals( 'standard', $data['format'] ); … … 1688 1944 1689 1945 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1690 $params = $this->set_post_data( array( 1691 'format' => 'testformat', 1692 ) ); 1946 $params = $this->set_post_data( 1947 array( 1948 'format' => 'testformat', 1949 ) 1950 ); 1693 1951 $request->set_body_params( $params ); 1694 1952 $response = $this->server->dispatch( $request ); … … 1706 1964 1707 1965 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1708 $params = $this->set_post_data( array( 1709 'format' => 'link', 1710 ) ); 1966 $params = $this->set_post_data( 1967 array( 1968 'format' => 'link', 1969 ) 1970 ); 1711 1971 $request->set_body_params( $params ); 1712 1972 $response = $this->server->dispatch( $request ); … … 1719 1979 public function test_create_update_post_with_featured_media() { 1720 1980 1721 $file = DIR_TESTDATA . '/images/canola.jpg'; 1722 $this->attachment_id = $this->factory->attachment->create_object( $file, 0, array( 1723 'post_mime_type' => 'image/jpeg', 1724 'menu_order' => rand( 1, 100 ), 1725 ) ); 1981 $file = DIR_TESTDATA . '/images/canola.jpg'; 1982 $this->attachment_id = $this->factory->attachment->create_object( 1983 $file, 0, array( 1984 'post_mime_type' => 'image/jpeg', 1985 'menu_order' => rand( 1, 100 ), 1986 ) 1987 ); 1726 1988 1727 1989 wp_set_current_user( self::$editor_id ); 1728 1990 1729 1991 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1730 $params = $this->set_post_data( array( 1731 'featured_media' => $this->attachment_id, 1732 ) ); 1733 $request->set_body_params( $params ); 1734 $response = $this->server->dispatch( $request ); 1735 $data = $response->get_data(); 1992 $params = $this->set_post_data( 1993 array( 1994 'featured_media' => $this->attachment_id, 1995 ) 1996 ); 1997 $request->set_body_params( $params ); 1998 $response = $this->server->dispatch( $request ); 1999 $data = $response->get_data(); 1736 2000 $new_post = get_post( $data['id'] ); 1737 2001 $this->assertEquals( $this->attachment_id, $data['featured_media'] ); … … 1739 2003 1740 2004 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . $new_post->ID ); 1741 $params = $this->set_post_data( array( 1742 'featured_media' => 0, 1743 ) ); 1744 $request->set_body_params( $params ); 1745 $response = $this->server->dispatch( $request ); 1746 $data = $response->get_data(); 2005 $params = $this->set_post_data( 2006 array( 2007 'featured_media' => 0, 2008 ) 2009 ); 2010 $request->set_body_params( $params ); 2011 $response = $this->server->dispatch( $request ); 2012 $data = $response->get_data(); 1747 2013 $this->assertEquals( 0, $data['featured_media'] ); 1748 2014 $this->assertEquals( 0, (int) get_post_thumbnail_id( $new_post->ID ) ); … … 1753 2019 1754 2020 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1755 $params = $this->set_post_data( array( 1756 'author' => -1, 1757 ) ); 2021 $params = $this->set_post_data( 2022 array( 2023 'author' => -1, 2024 ) 2025 ); 1758 2026 $request->set_body_params( $params ); 1759 2027 $response = $this->server->dispatch( $request ); … … 1766 2034 1767 2035 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1768 $params = $this->set_post_data( array( 1769 'author' => self::$editor_id, 1770 ) ); 2036 $params = $this->set_post_data( 2037 array( 2038 'author' => self::$editor_id, 2039 ) 2040 ); 1771 2041 $request->set_body_params( $params ); 1772 2042 $response = $this->server->dispatch( $request ); … … 1779 2049 1780 2050 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1781 $params = $this->set_post_data( array( 1782 'password' => 'testing', 1783 ) ); 2051 $params = $this->set_post_data( 2052 array( 2053 'password' => 'testing', 2054 ) 2055 ); 1784 2056 $request->set_body_params( $params ); 1785 2057 $response = $this->server->dispatch( $request ); … … 1793 2065 1794 2066 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1795 $params = $this->set_post_data( array( 1796 'password' => '0', 1797 ) ); 2067 $params = $this->set_post_data( 2068 array( 2069 'password' => '0', 2070 ) 2071 ); 1798 2072 $request->set_body_params( $params ); 1799 2073 $response = $this->server->dispatch( $request ); … … 1808 2082 1809 2083 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1810 $params = $this->set_post_data( array( 1811 'password' => '', 1812 'sticky' => true, 1813 ) ); 2084 $params = $this->set_post_data( 2085 array( 2086 'password' => '', 2087 'sticky' => true, 2088 ) 2089 ); 1814 2090 $request->set_body_params( $params ); 1815 2091 $response = $this->server->dispatch( $request ); … … 1824 2100 1825 2101 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1826 $params = $this->set_post_data( array( 1827 'password' => '123', 1828 'sticky' => true, 1829 ) ); 2102 $params = $this->set_post_data( 2103 array( 2104 'password' => '123', 2105 'sticky' => true, 2106 ) 2107 ); 1830 2108 $request->set_body_params( $params ); 1831 2109 $response = $this->server->dispatch( $request ); … … 1838 2116 1839 2117 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1840 $params = $this->set_post_data( array( 1841 'date' => '2010-01-01T02:00:00Z', 1842 ) ); 1843 $request->set_body_params( $params ); 1844 $response = $this->server->dispatch( $request ); 1845 1846 $data = $response->get_data(); 2118 $params = $this->set_post_data( 2119 array( 2120 'date' => '2010-01-01T02:00:00Z', 2121 ) 2122 ); 2123 $request->set_body_params( $params ); 2124 $response = $this->server->dispatch( $request ); 2125 2126 $data = $response->get_data(); 1847 2127 $new_post = get_post( $data['id'] ); 1848 $time = gmmktime( 2, 0, 0, 1, 1, 2010 );2128 $time = gmmktime( 2, 0, 0, 1, 1, 2010 ); 1849 2129 $this->assertEquals( '2010-01-01T02:00:00', $data['date'] ); 1850 2130 $this->assertEquals( $time, strtotime( $new_post->post_date ) ); … … 1855 2135 1856 2136 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1857 $params = $this->set_post_data( array( 1858 'date' => '2010-01-01T02:00:00-10:00', 1859 ) ); 1860 $request->set_body_params( $params ); 1861 $response = $this->server->dispatch( $request ); 1862 1863 $data = $response->get_data(); 2137 $params = $this->set_post_data( 2138 array( 2139 'date' => '2010-01-01T02:00:00-10:00', 2140 ) 2141 ); 2142 $request->set_body_params( $params ); 2143 $response = $this->server->dispatch( $request ); 2144 2145 $data = $response->get_data(); 1864 2146 $new_post = get_post( $data['id'] ); 1865 $time = gmmktime( 12, 0, 0, 1, 1, 2010 );2147 $time = gmmktime( 12, 0, 0, 1, 1, 2010 ); 1866 2148 1867 2149 $this->assertEquals( '2010-01-01T12:00:00', $data['date'] ); … … 1898 2180 1899 2181 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1900 $params = $this->set_post_data( array( 1901 'date' => '2010-60-01T02:00:00Z', 1902 ) ); 2182 $params = $this->set_post_data( 2183 array( 2184 'date' => '2010-60-01T02:00:00Z', 2185 ) 2186 ); 1903 2187 $request->set_body_params( $params ); 1904 2188 $response = $this->server->dispatch( $request ); … … 1911 2195 1912 2196 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1913 $params = $this->set_post_data( array( 1914 'date_gmt' => '2010-60-01T02:00:00', 1915 ) ); 2197 $params = $this->set_post_data( 2198 array( 2199 'date_gmt' => '2010-60-01T02:00:00', 2200 ) 2201 ); 1916 2202 $request->set_body_params( $params ); 1917 2203 $response = $this->server->dispatch( $request ); … … 1924 2210 1925 2211 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1926 $params = $this->set_post_data( array( 1927 'title' => "Rob O'Rourke's Diary", 1928 ) ); 2212 $params = $this->set_post_data( 2213 array( 2214 'title' => "Rob O'Rourke's Diary", 2215 ) 2216 ); 1929 2217 $request->set_body_params( $params ); 1930 2218 $response = $this->server->dispatch( $request ); … … 1936 2224 wp_set_current_user( self::$editor_id ); 1937 2225 $category = wp_insert_term( 'Test Category', 'category' ); 1938 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1939 $params = $this->set_post_data( array( 1940 'password' => 'testing', 1941 'categories' => array( 1942 $category['term_id'] 1943 ), 1944 ) ); 2226 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 2227 $params = $this->set_post_data( 2228 array( 2229 'password' => 'testing', 2230 'categories' => array( 2231 $category['term_id'], 2232 ), 2233 ) 2234 ); 1945 2235 $request->set_body_params( $params ); 1946 2236 $response = $this->server->dispatch( $request ); … … 1952 2242 public function test_create_post_with_categories_as_csv() { 1953 2243 wp_set_current_user( self::$editor_id ); 1954 $category = wp_insert_term( 'Chicken', 'category' );2244 $category = wp_insert_term( 'Chicken', 'category' ); 1955 2245 $category2 = wp_insert_term( 'Ribs', 'category' ); 1956 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1957 $params = $this->set_post_data( array( 1958 'categories' => $category['term_id'] . ',' . $category2['term_id'], 1959 ) ); 2246 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 2247 $params = $this->set_post_data( 2248 array( 2249 'categories' => $category['term_id'] . ',' . $category2['term_id'], 2250 ) 2251 ); 1960 2252 $request->set_body_params( $params ); 1961 2253 $response = $this->server->dispatch( $request ); … … 1968 2260 wp_set_current_user( self::$editor_id ); 1969 2261 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1970 $params = $this->set_post_data( array( 1971 'password' => 'testing', 1972 'categories' => array( 1973 REST_TESTS_IMPOSSIBLY_HIGH_NUMBER 1974 ), 1975 ) ); 2262 $params = $this->set_post_data( 2263 array( 2264 'password' => 'testing', 2265 'categories' => array( 2266 REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, 2267 ), 2268 ) 2269 ); 1976 2270 $request->set_body_params( $params ); 1977 2271 $response = $this->server->dispatch( $request ); … … 1985 2279 */ 1986 2280 public function test_create_post_with_categories_that_cannot_be_assigned_by_current_user() { 1987 $cats = self::factory()->category->create_many( 2 );2281 $cats = self::factory()->category->create_many( 2 ); 1988 2282 $this->forbidden_cat = $cats[1]; 1989 2283 1990 2284 wp_set_current_user( self::$editor_id ); 1991 2285 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 1992 $params = $this->set_post_data( array( 1993 'password' => 'testing', 1994 'categories' => $cats, 1995 ) ); 2286 $params = $this->set_post_data( 2287 array( 2288 'password' => 'testing', 2289 'categories' => $cats, 2290 ) 2291 ); 1996 2292 $request->set_body_params( $params ); 1997 2293 … … 2093 2389 2094 2390 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2095 $params = $this->set_post_data();2391 $params = $this->set_post_data(); 2096 2392 unset( $params['type'] ); 2097 2393 unset( $params['name'] ); … … 2113 2409 2114 2410 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2115 $params = $this->set_post_data();2411 $params = $this->set_post_data(); 2116 2412 $request->set_body_params( $params ); 2117 2413 $response = $this->server->dispatch( $request ); … … 2124 2420 2125 2421 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2126 $params = $this->set_post_data( array( 2127 'sticky' => true, 2128 'status' => 'pending', 2129 ) ); 2422 $params = $this->set_post_data( 2423 array( 2424 'sticky' => true, 2425 'status' => 'pending', 2426 ) 2427 ); 2130 2428 $request->set_body_params( $params ); 2131 2429 $response = $this->server->dispatch( $request ); … … 2137 2435 wp_set_current_user( self::$editor_id ); 2138 2436 2139 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );2437 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) ); 2140 2438 $response = $this->server->dispatch( $request ); 2141 2439 … … 2146 2444 wp_set_current_user( self::$editor_id ); 2147 2445 2148 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', self::$post_id ) );2446 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', self::$post_id ) ); 2149 2447 $response = $this->server->dispatch( $request ); 2150 2448 … … 2156 2454 2157 2455 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2158 $params = $this->set_post_data( array( 2159 'format' => 'gallery', 2160 ) ); 2161 $request->set_body_params( $params ); 2162 $response = $this->server->dispatch( $request ); 2163 2164 $data = $response->get_data(); 2456 $params = $this->set_post_data( 2457 array( 2458 'format' => 'gallery', 2459 ) 2460 ); 2461 $request->set_body_params( $params ); 2462 $response = $this->server->dispatch( $request ); 2463 2464 $data = $response->get_data(); 2165 2465 $new_post = get_post( $data['id'] ); 2166 2466 $this->assertEquals( 'gallery', $data['format'] ); … … 2172 2472 2173 2473 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2174 $params = $this->set_post_data( array( 2175 'format' => 'standard', 2176 ) ); 2177 $request->set_body_params( $params ); 2178 $response = $this->server->dispatch( $request ); 2179 2180 $data = $response->get_data(); 2474 $params = $this->set_post_data( 2475 array( 2476 'format' => 'standard', 2477 ) 2478 ); 2479 $request->set_body_params( $params ); 2480 $response = $this->server->dispatch( $request ); 2481 2482 $data = $response->get_data(); 2181 2483 $new_post = get_post( $data['id'] ); 2182 2484 $this->assertEquals( 'standard', $data['format'] ); … … 2188 2490 2189 2491 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2190 $params = $this->set_post_data( array( 2191 'format' => 'testformat', 2192 ) ); 2492 $params = $this->set_post_data( 2493 array( 2494 'format' => 'testformat', 2495 ) 2496 ); 2193 2497 $request->set_body_params( $params ); 2194 2498 $response = $this->server->dispatch( $request ); … … 2206 2510 2207 2511 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2208 $params = $this->set_post_data( array( 2209 'format' => 'link', 2210 ) ); 2512 $params = $this->set_post_data( 2513 array( 2514 'format' => 'link', 2515 ) 2516 ); 2211 2517 $request->set_body_params( $params ); 2212 2518 $response = $this->server->dispatch( $request ); … … 2220 2526 wp_set_current_user( self::$editor_id ); 2221 2527 2222 $new_content = rand_str();2528 $new_content = rand_str(); 2223 2529 $expected_modified = current_time( 'mysql' ); 2224 2530 2225 2531 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2226 $params = $this->set_post_data( array( 2227 'modified' => '2010-06-01T02:00:00Z', 2228 'content' => $new_content, 2229 ) ); 2532 $params = $this->set_post_data( 2533 array( 2534 'modified' => '2010-06-01T02:00:00Z', 2535 'content' => $new_content, 2536 ) 2537 ); 2230 2538 $request->set_body_params( $params ); 2231 2539 $response = $this->server->dispatch( $request ); 2232 2540 2233 2541 // The readonly modified param should be ignored, request should be a success. 2234 $data = $response->get_data();2542 $data = $response->get_data(); 2235 2543 $new_post = get_post( $data['id'] ); 2236 2544 … … 2280 2588 2281 2589 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2282 $params = $this->set_post_data( array( 2283 'date' => rand_str(), 2284 ) ); 2590 $params = $this->set_post_data( 2591 array( 2592 'date' => rand_str(), 2593 ) 2594 ); 2285 2595 $request->set_body_params( $params ); 2286 2596 $response = $this->server->dispatch( $request ); … … 2293 2603 2294 2604 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2295 $params = $this->set_post_data( array( 2296 'date_gmt' => rand_str(), 2297 ) ); 2605 $params = $this->set_post_data( 2606 array( 2607 'date_gmt' => rand_str(), 2608 ) 2609 ); 2298 2610 $request->set_body_params( $params ); 2299 2611 $response = $this->server->dispatch( $request ); … … 2326 2638 2327 2639 $post = get_post( $post_id ); 2328 $this->assertEquals( $post->post_date, '2016-02-23 12:00:00' );2640 $this->assertEquals( $post->post_date, '2016-02-23 12:00:00' ); 2329 2641 $this->assertEquals( $post->post_date_gmt, '0000-00-00 00:00:00' ); 2330 2642 2331 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );2643 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2332 2644 $response = $this->server->dispatch( $request ); 2333 2645 $this->assertEquals( 200, $response->get_status() ); … … 2347 2659 2348 2660 $post = get_post( $post_id ); 2349 $this->assertEquals( $post->post_date, '2016-02-23 13:00:00' );2661 $this->assertEquals( $post->post_date, '2016-02-23 13:00:00' ); 2350 2662 $this->assertEquals( $post->post_date_gmt, '2016-02-23 19:00:00' ); 2351 2663 … … 2357 2669 2358 2670 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2359 $params = $this->set_post_data( array( 2360 'slug' => 'sample-slug', 2361 ) ); 2671 $params = $this->set_post_data( 2672 array( 2673 'slug' => 'sample-slug', 2674 ) 2675 ); 2362 2676 $request->set_body_params( $params ); 2363 2677 $response = $this->server->dispatch( $request ); … … 2373 2687 2374 2688 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2375 $params = $this->set_post_data( array( 2376 'slug' => 'tęst-acceńted-chäræcters', 2377 ) ); 2689 $params = $this->set_post_data( 2690 array( 2691 'slug' => 'tęst-acceńted-chäræcters', 2692 ) 2693 ); 2378 2694 $request->set_body_params( $params ); 2379 2695 $response = $this->server->dispatch( $request ); … … 2389 2705 2390 2706 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2391 $params = $this->set_post_data( array( 2392 'sticky' => true, 2393 ) ); 2707 $params = $this->set_post_data( 2708 array( 2709 'sticky' => true, 2710 ) 2711 ); 2394 2712 $request->set_body_params( $params ); 2395 2713 $response = $this->server->dispatch( $request ); … … 2402 2720 // Updating another field shouldn't change sticky status 2403 2721 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2404 $params = $this->set_post_data( array( 2405 'title' => 'This should not reset sticky', 2406 ) ); 2722 $params = $this->set_post_data( 2723 array( 2724 'title' => 'This should not reset sticky', 2725 ) 2726 ); 2407 2727 $request->set_body_params( $params ); 2408 2728 $response = $this->server->dispatch( $request ); … … 2418 2738 2419 2739 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2420 $request->set_body_params( array( 2421 'excerpt' => 'An Excerpt', 2422 ) ); 2740 $request->set_body_params( 2741 array( 2742 'excerpt' => 'An Excerpt', 2743 ) 2744 ); 2423 2745 2424 2746 $response = $this->server->dispatch( $request ); … … 2431 2753 2432 2754 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2433 $request->set_body_params( array( 2434 'excerpt' => '', 2435 ) ); 2755 $request->set_body_params( 2756 array( 2757 'excerpt' => '', 2758 ) 2759 ); 2436 2760 2437 2761 $response = $this->server->dispatch( $request ); … … 2444 2768 2445 2769 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2446 $request->set_body_params( array( 2447 'content' => 'Some Content', 2448 ) ); 2770 $request->set_body_params( 2771 array( 2772 'content' => 'Some Content', 2773 ) 2774 ); 2449 2775 2450 2776 $response = $this->server->dispatch( $request ); … … 2457 2783 2458 2784 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2459 $request->set_body_params( array( 2460 'content' => '', 2461 ) ); 2785 $request->set_body_params( 2786 array( 2787 'content' => '', 2788 ) 2789 ); 2462 2790 2463 2791 $response = $this->server->dispatch( $request ); … … 2468 2796 public function test_update_post_with_empty_password() { 2469 2797 wp_set_current_user( self::$editor_id ); 2470 wp_update_post( array( 2471 'ID' => self::$post_id, 2472 'post_password' => 'foo', 2473 ) ); 2798 wp_update_post( 2799 array( 2800 'ID' => self::$post_id, 2801 'post_password' => 'foo', 2802 ) 2803 ); 2474 2804 2475 2805 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2476 $params = $this->set_post_data( array( 2477 'password' => '', 2478 ) ); 2479 $request->set_body_params( $params ); 2480 $response = $this->server->dispatch( $request ); 2481 $data = $response->get_data(); 2806 $params = $this->set_post_data( 2807 array( 2808 'password' => '', 2809 ) 2810 ); 2811 $request->set_body_params( $params ); 2812 $response = $this->server->dispatch( $request ); 2813 $data = $response->get_data(); 2482 2814 $this->assertEquals( '', $data['password'] ); 2483 2815 } … … 2487 2819 2488 2820 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2489 $params = $this->set_post_data( array( 2490 'password' => '123', 2491 'sticky' => true, 2492 ) ); 2821 $params = $this->set_post_data( 2822 array( 2823 'password' => '123', 2824 'sticky' => true, 2825 ) 2826 ); 2493 2827 $request->set_body_params( $params ); 2494 2828 $response = $this->server->dispatch( $request ); … … 2503 2837 2504 2838 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2505 $params = $this->set_post_data( array( 2506 'password' => '123', 2507 ) ); 2839 $params = $this->set_post_data( 2840 array( 2841 'password' => '123', 2842 ) 2843 ); 2508 2844 $request->set_body_params( $params ); 2509 2845 $response = $this->server->dispatch( $request ); … … 2515 2851 wp_set_current_user( self::$editor_id ); 2516 2852 2517 wp_update_post( array( 'ID' => self::$post_id, 'post_password' => '123' ) ); 2853 wp_update_post( 2854 array( 2855 'ID' => self::$post_id, 2856 'post_password' => '123', 2857 ) 2858 ); 2518 2859 2519 2860 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2520 $params = $this->set_post_data( array( 2521 'sticky' => true, 2522 ) ); 2861 $params = $this->set_post_data( 2862 array( 2863 'sticky' => true, 2864 ) 2865 ); 2523 2866 $request->set_body_params( $params ); 2524 2867 $response = $this->server->dispatch( $request ); … … 2531 2874 2532 2875 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2533 $params = $this->set_post_data( array( 2534 'title' => "Rob O'Rourke's Diary", 2535 ) ); 2876 $params = $this->set_post_data( 2877 array( 2878 'title' => "Rob O'Rourke's Diary", 2879 ) 2880 ); 2536 2881 $request->set_body_params( $params ); 2537 2882 $response = $this->server->dispatch( $request ); … … 2546 2891 2547 2892 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2548 $params = $this->set_post_data( array( 2549 'title' => 'Tester', 2550 'categories' => array( 2551 $category['term_id'], 2552 ), 2553 ) ); 2893 $params = $this->set_post_data( 2894 array( 2895 'title' => 'Tester', 2896 'categories' => array( 2897 $category['term_id'], 2898 ), 2899 ) 2900 ); 2554 2901 $request->set_body_params( $params ); 2555 2902 $response = $this->server->dispatch( $request ); … … 2557 2904 $this->assertEquals( array( $category['term_id'] ), $new_data['categories'] ); 2558 2905 $categories_path = ''; 2559 $links = $response->get_links();2906 $links = $response->get_links(); 2560 2907 foreach ( $links['https://api.w.org/term'] as $link ) { 2561 2908 if ( 'category' === $link['attributes']['taxonomy'] ) { … … 2569 2916 $request->set_query_params( $args ); 2570 2917 $response = $this->server->dispatch( $request ); 2571 $data = $response->get_data();2918 $data = $response->get_data(); 2572 2919 $this->assertCount( 1, $data ); 2573 2920 $this->assertEquals( 'Test Category', $data[0]['name'] ); … … 2581 2928 2582 2929 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2583 $params = $this->set_post_data( array( 2584 'title' => 'Tester', 2585 'categories' => array(), 2586 ) ); 2930 $params = $this->set_post_data( 2931 array( 2932 'title' => 'Tester', 2933 'categories' => array(), 2934 ) 2935 ); 2587 2936 $request->set_body_params( $params ); 2588 2937 $response = $this->server->dispatch( $request ); … … 2595 2944 */ 2596 2945 public function test_update_post_with_categories_that_cannot_be_assigned_by_current_user() { 2597 $cats = self::factory()->category->create_many( 2 );2946 $cats = self::factory()->category->create_many( 2 ); 2598 2947 $this->forbidden_cat = $cats[1]; 2599 2948 2600 2949 wp_set_current_user( self::$editor_id ); 2601 2950 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2602 $params = $this->set_post_data( array( 2603 'password' => 'testing', 2604 'categories' => $cats, 2605 ) ); 2951 $params = $this->set_post_data( 2952 array( 2953 'password' => 'testing', 2954 'categories' => $cats, 2955 ) 2956 ); 2606 2957 $request->set_body_params( $params ); 2607 2958 … … 2622 2973 // reregister the route as we now have a template available. 2623 2974 $GLOBALS['wp_rest_server']->override_by_default = true; 2624 $controller = new WP_REST_Posts_Controller( 'post' );2975 $controller = new WP_REST_Posts_Controller( 'post' ); 2625 2976 $controller->register_routes(); 2626 2977 $GLOBALS['wp_rest_server']->override_by_default = false; 2627 2978 2628 2979 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2629 $params = $this->set_post_data( array( 2630 'template' => 'post-my-test-template.php', 2631 ) ); 2632 $request->set_body_params( $params ); 2633 $response = $this->server->dispatch( $request ); 2634 2635 $data = $response->get_data(); 2980 $params = $this->set_post_data( 2981 array( 2982 'template' => 'post-my-test-template.php', 2983 ) 2984 ); 2985 $request->set_body_params( $params ); 2986 $response = $this->server->dispatch( $request ); 2987 2988 $data = $response->get_data(); 2636 2989 $post_template = get_page_template_slug( get_post( $data['id'] ) ); 2637 2990 … … 2650 3003 // reregister the route as we now have a template available. 2651 3004 $GLOBALS['wp_rest_server']->override_by_default = true; 2652 $controller = new WP_REST_Posts_Controller( 'post' );3005 $controller = new WP_REST_Posts_Controller( 'post' ); 2653 3006 $controller->register_routes(); 2654 3007 $GLOBALS['wp_rest_server']->override_by_default = false; 2655 3008 2656 3009 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2657 $params = $this->set_post_data( array( 2658 'template' => '', 2659 ) ); 2660 $request->set_body_params( $params ); 2661 $response = $this->server->dispatch( $request ); 2662 2663 $data = $response->get_data(); 3010 $params = $this->set_post_data( 3011 array( 3012 'template' => '', 3013 ) 3014 ); 3015 $request->set_body_params( $params ); 3016 $response = $this->server->dispatch( $request ); 3017 3018 $data = $response->get_data(); 2664 3019 $post_template = get_page_template_slug( get_post( $data['id'] ) ); 2665 3020 … … 2681 3036 2682 3037 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2683 $params = $this->set_post_data( array( 2684 'template' => 'post-my-invalid-template.php', 2685 ) ); 3038 $params = $this->set_post_data( 3039 array( 3040 'template' => 'post-my-invalid-template.php', 3041 ) 3042 ); 2686 3043 $request->set_body_params( $params ); 2687 3044 $response = $this->server->dispatch( $request ); … … 2689 3046 $this->assertEquals( 200, $response->get_status() ); 2690 3047 2691 $data = $response->get_data();3048 $data = $response->get_data(); 2692 3049 $post_template = get_page_template_slug( get_post( $data['id'] ) ); 2693 3050 … … 2707 3064 2708 3065 // Compare expected API output to actual API output 2709 $this->assertEquals( $expected_output['title']['raw'] , $actual_output['title']['raw'] );2710 $this->assertEquals( $expected_output['title']['rendered'] , trim( $actual_output['title']['rendered'] ) );2711 $this->assertEquals( $expected_output['content']['raw'] , $actual_output['content']['raw'] );3066 $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] ); 3067 $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); 3068 $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] ); 2712 3069 $this->assertEquals( $expected_output['content']['rendered'], trim( $actual_output['content']['rendered'] ) ); 2713 $this->assertEquals( $expected_output['excerpt']['raw'] , $actual_output['excerpt']['raw'] );3070 $this->assertEquals( $expected_output['excerpt']['raw'], $actual_output['excerpt']['raw'] ); 2714 3071 $this->assertEquals( $expected_output['excerpt']['rendered'], trim( $actual_output['excerpt']['rendered'] ) ); 2715 3072 2716 3073 // Compare expected API output to WP internal values 2717 3074 $post = get_post( $actual_output['id'] ); 2718 $this->assertEquals( $expected_output['title']['raw'] , $post->post_title );3075 $this->assertEquals( $expected_output['title']['raw'], $post->post_title ); 2719 3076 $this->assertEquals( $expected_output['content']['raw'], $post->post_content ); 2720 3077 $this->assertEquals( $expected_output['excerpt']['raw'], $post->post_excerpt ); … … 2730 3087 2731 3088 // Compare expected API output to actual API output 2732 $this->assertEquals( $expected_output['title']['raw'] , $actual_output['title']['raw'] );2733 $this->assertEquals( $expected_output['title']['rendered'] , trim( $actual_output['title']['rendered'] ) );2734 $this->assertEquals( $expected_output['content']['raw'] , $actual_output['content']['raw'] );3089 $this->assertEquals( $expected_output['title']['raw'], $actual_output['title']['raw'] ); 3090 $this->assertEquals( $expected_output['title']['rendered'], trim( $actual_output['title']['rendered'] ) ); 3091 $this->assertEquals( $expected_output['content']['raw'], $actual_output['content']['raw'] ); 2735 3092 $this->assertEquals( $expected_output['content']['rendered'], trim( $actual_output['content']['rendered'] ) ); 2736 $this->assertEquals( $expected_output['excerpt']['raw'] , $actual_output['excerpt']['raw'] );3093 $this->assertEquals( $expected_output['excerpt']['raw'], $actual_output['excerpt']['raw'] ); 2737 3094 $this->assertEquals( $expected_output['excerpt']['rendered'], trim( $actual_output['excerpt']['rendered'] ) ); 2738 3095 2739 3096 // Compare expected API output to WP internal values 2740 3097 $post = get_post( $actual_output['id'] ); 2741 $this->assertEquals( $expected_output['title']['raw'] , $post->post_title );3098 $this->assertEquals( $expected_output['title']['raw'], $post->post_title ); 2742 3099 $this->assertEquals( $expected_output['content']['raw'], $post->post_content ); 2743 3100 $this->assertEquals( $expected_output['excerpt']['raw'], $post->post_excerpt ); … … 2755 3112 // Expected returned values. 2756 3113 array( 2757 'title' => array(3114 'title' => array( 2758 3115 'raw' => '\o/ ¯\_(ツ)_/¯', 2759 3116 'rendered' => '\o/ ¯\_(ツ)_/¯', … … 2767 3124 'rendered' => '<p>\o/ ¯\_(ツ)_/¯</p>', 2768 3125 ), 2769 ) 3126 ), 2770 3127 ), 2771 3128 array( … … 2778 3135 // Expected returned values. 2779 3136 array( 2780 'title' => array(3137 'title' => array( 2781 3138 'raw' => '\\\&\\\ & &invalid; < < &lt;', 2782 3139 'rendered' => '\\\&\\\ & &invalid; < < &lt;', … … 2801 3158 // Expected returned values. 2802 3159 array( 2803 'title' => array( 3160 'title' => array( 3161 'raw' => 'div <strong>strong</strong> oh noes', 3162 'rendered' => 'div <strong>strong</strong> oh noes', 3163 ), 3164 'content' => array( 3165 'raw' => '<div>div</div> <strong>strong</strong> oh noes', 3166 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> oh noes</p>", 3167 ), 3168 'excerpt' => array( 3169 'raw' => '<div>div</div> <strong>strong</strong> oh noes', 3170 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> oh noes</p>", 3171 ), 3172 ), 3173 ), 3174 array( 3175 // Raw values. 3176 array( 3177 'title' => '<a href="#" target="_blank" data-unfiltered=true>link</a>', 3178 'content' => '<a href="#" target="_blank" data-unfiltered=true>link</a>', 3179 'excerpt' => '<a href="#" target="_blank" data-unfiltered=true>link</a>', 3180 ), 3181 // Expected returned values. 3182 array( 3183 'title' => array( 3184 'raw' => '<a href="#">link</a>', 3185 'rendered' => '<a href="#">link</a>', 3186 ), 3187 'content' => array( 3188 'raw' => '<a href="#" target="_blank">link</a>', 3189 'rendered' => '<p><a href="#" target="_blank">link</a></p>', 3190 ), 3191 'excerpt' => array( 3192 'raw' => '<a href="#" target="_blank">link</a>', 3193 'rendered' => '<p><a href="#" target="_blank">link</a></p>', 3194 ), 3195 ), 3196 ), 3197 ); 3198 } 3199 3200 /** 3201 * @dataProvider post_roundtrip_provider 3202 */ 3203 public function test_post_roundtrip_as_author( $raw, $expected ) { 3204 wp_set_current_user( self::$author_id ); 3205 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); 3206 $this->verify_post_roundtrip( $raw, $expected ); 3207 } 3208 3209 public function test_post_roundtrip_as_editor_unfiltered_html() { 3210 wp_set_current_user( self::$editor_id ); 3211 if ( is_multisite() ) { 3212 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); 3213 $this->verify_post_roundtrip( 3214 array( 3215 'title' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 3216 'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 3217 'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 3218 ), array( 3219 'title' => array( 2804 3220 'raw' => 'div <strong>strong</strong> oh noes', 2805 3221 'rendered' => 'div <strong>strong</strong> oh noes', … … 2814 3230 ), 2815 3231 ) 2816 ), 2817 array( 2818 // Raw values. 3232 ); 3233 } else { 3234 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 3235 $this->verify_post_roundtrip( 2819 3236 array( 2820 'title' => '<a href="#" target="_blank" data-unfiltered=true>link</a>', 2821 'content' => '<a href="#" target="_blank" data-unfiltered=true>link</a>', 2822 'excerpt' => '<a href="#" target="_blank" data-unfiltered=true>link</a>', 2823 ), 2824 // Expected returned values. 2825 array( 2826 'title' => array( 2827 'raw' => '<a href="#">link</a>', 2828 'rendered' => '<a href="#">link</a>', 3237 'title' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 3238 'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 3239 'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 3240 ), array( 3241 'title' => array( 3242 'raw' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 3243 'rendered' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2829 3244 ), 2830 3245 'content' => array( 2831 'raw' => '< a href="#" target="_blank">link</a>',2832 'rendered' => '<p><a href="#" target="_blank">link</a></p>',3246 'raw' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 3247 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>", 2833 3248 ), 2834 3249 'excerpt' => array( 2835 'raw' => '< a href="#" target="_blank">link</a>',2836 'rendered' => '<p><a href="#" target="_blank">link</a></p>',3250 'raw' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 3251 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>", 2837 3252 ), 2838 3253 ) 2839 ), 2840 ); 2841 } 2842 2843 /** 2844 * @dataProvider post_roundtrip_provider 2845 */ 2846 public function test_post_roundtrip_as_author( $raw, $expected ) { 2847 wp_set_current_user( self::$author_id ); 2848 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); 2849 $this->verify_post_roundtrip( $raw, $expected ); 2850 } 2851 2852 public function test_post_roundtrip_as_editor_unfiltered_html() { 2853 wp_set_current_user( self::$editor_id ); 2854 if ( is_multisite() ) { 2855 $this->assertFalse( current_user_can( 'unfiltered_html' ) ); 2856 $this->verify_post_roundtrip( array( 3254 ); 3255 } 3256 } 3257 3258 public function test_post_roundtrip_as_superadmin_unfiltered_html() { 3259 wp_set_current_user( self::$superadmin_id ); 3260 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 3261 $this->verify_post_roundtrip( 3262 array( 2857 3263 'title' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2858 3264 'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2859 3265 'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2860 3266 ), array( 2861 'title' => array( 2862 'raw' => 'div <strong>strong</strong> oh noes', 2863 'rendered' => 'div <strong>strong</strong> oh noes', 2864 ), 2865 'content' => array( 2866 'raw' => '<div>div</div> <strong>strong</strong> oh noes', 2867 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> oh noes</p>", 2868 ), 2869 'excerpt' => array( 2870 'raw' => '<div>div</div> <strong>strong</strong> oh noes', 2871 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> oh noes</p>", 2872 ), 2873 ) ); 2874 } else { 2875 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 2876 $this->verify_post_roundtrip( array( 2877 'title' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2878 'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2879 'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2880 ), array( 2881 'title' => array( 3267 'title' => array( 2882 3268 'raw' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2883 3269 'rendered' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', … … 2891 3277 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>", 2892 3278 ), 2893 ) ); 2894 } 2895 } 2896 2897 public function test_post_roundtrip_as_superadmin_unfiltered_html() { 2898 wp_set_current_user( self::$superadmin_id ); 2899 $this->assertTrue( current_user_can( 'unfiltered_html' ) ); 2900 $this->verify_post_roundtrip( array( 2901 'title' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2902 'content' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2903 'excerpt' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2904 ), array( 2905 'title' => array( 2906 'raw' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2907 'rendered' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2908 ), 2909 'content' => array( 2910 'raw' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2911 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>", 2912 ), 2913 'excerpt' => array( 2914 'raw' => '<div>div</div> <strong>strong</strong> <script>oh noes</script>', 2915 'rendered' => "<div>div</div>\n<p> <strong>strong</strong> <script>oh noes</script></p>", 2916 ), 2917 ) ); 3279 ) 3280 ); 2918 3281 } 2919 3282 … … 2936 3299 wp_set_current_user( self::$editor_id ); 2937 3300 2938 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );3301 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2939 3302 $request['force'] = true; 2940 $response = $this->server->dispatch( $request );3303 $response = $this->server->dispatch( $request ); 2941 3304 2942 3305 $this->assertEquals( 200, $response->get_status() ); … … 2949 3312 $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) ); 2950 3313 wp_set_current_user( self::$editor_id ); 2951 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );3314 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) ); 2952 3315 $response = $this->server->dispatch( $request ); 2953 3316 $this->assertEquals( 200, $response->get_status() ); … … 2959 3322 wp_set_current_user( self::$editor_id ); 2960 3323 2961 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );3324 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 2962 3325 $response = $this->server->dispatch( $request ); 2963 3326 … … 2969 3332 wp_set_current_user( self::$editor_id ); 2970 3333 2971 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $page_id );3334 $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $page_id ); 2972 3335 $response = $this->server->dispatch( $request ); 2973 3336 … … 2978 3341 wp_set_current_user( self::$author_id ); 2979 3342 2980 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', self::$post_id ) );3343 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2981 3344 $response = $this->server->dispatch( $request ); 2982 3345 … … 2986 3349 public function test_register_post_type_invalid_controller() { 2987 3350 2988 register_post_type( 'invalid-controller', array( 'show_in_rest' => true, 'rest_controller_class' => 'Fake_Class_Baba' ) ); 3351 register_post_type( 3352 'invalid-controller', array( 3353 'show_in_rest' => true, 3354 'rest_controller_class' => 'Fake_Class_Baba', 3355 ) 3356 ); 2989 3357 create_initial_rest_routes(); 2990 3358 $routes = $this->server->get_routes(); … … 2995 3363 2996 3364 public function test_get_item_schema() { 2997 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );2998 $response = $this->server->dispatch( $request );2999 $data = $response->get_data();3365 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 3366 $response = $this->server->dispatch( $request ); 3367 $data = $response->get_data(); 3000 3368 $properties = $data['schema']['properties']; 3001 3369 $this->assertEquals( 24, count( $properties ) ); … … 3033 3401 $request->set_param( 'context', 'view' ); 3034 3402 $response = $this->server->dispatch( $request ); 3035 $keys = array_keys( $response->get_data() );3403 $keys = array_keys( $response->get_data() ); 3036 3404 sort( $keys ); 3037 3405 … … 3071 3439 $request->set_param( 'context', 'edit' ); 3072 3440 $response = $this->server->dispatch( $request ); 3073 $keys = array_keys( $response->get_data() );3441 $keys = array_keys( $response->get_data() ); 3074 3442 sort( $keys ); 3075 3443 … … 3108 3476 $request->set_param( 'context', 'embed' ); 3109 3477 $response = $this->server->dispatch( $request ); 3110 $keys = array_keys( $response->get_data() );3478 $keys = array_keys( $response->get_data() ); 3111 3479 sort( $keys ); 3112 3480 … … 3127 3495 3128 3496 public function test_status_array_enum_args() { 3129 $request = new WP_REST_Request( 'GET', '/wp/v2' );3130 $response = $this->server->dispatch( $request );3131 $data = $response->get_data();3497 $request = new WP_REST_Request( 'GET', '/wp/v2' ); 3498 $response = $this->server->dispatch( $request ); 3499 $data = $response->get_data(); 3132 3500 $list_posts_args = $data['routes']['/wp/v2/posts']['endpoints'][0]['args']; 3133 $status_arg = $list_posts_args['status'];3501 $status_arg = $list_posts_args['status']; 3134 3502 $this->assertEquals( 'array', $status_arg['type'] ); 3135 $this->assertEquals( array( 3136 'type' => 'string', 3137 'enum' => array( 'publish', 'future', 'draft', 'pending', 'private', 'trash', 'auto-draft', 'inherit', 'any' ), 3138 ), $status_arg['items'] ); 3503 $this->assertEquals( 3504 array( 3505 'type' => 'string', 3506 'enum' => array( 'publish', 'future', 'draft', 'pending', 'private', 'trash', 'auto-draft', 'inherit', 'any' ), 3507 ), $status_arg['items'] 3508 ); 3139 3509 } 3140 3510 … … 3148 3518 ); 3149 3519 3150 register_rest_field( 'post', 'my_custom_int', array( 3151 'schema' => $schema, 3152 'get_callback' => array( $this, 'additional_field_get_callback' ), 3153 'update_callback' => array( $this, 'additional_field_update_callback' ), 3154 ) ); 3520 register_rest_field( 3521 'post', 'my_custom_int', array( 3522 'schema' => $schema, 3523 'get_callback' => array( $this, 'additional_field_get_callback' ), 3524 'update_callback' => array( $this, 'additional_field_update_callback' ), 3525 ) 3526 ); 3155 3527 3156 3528 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); 3157 3529 3158 3530 $response = $this->server->dispatch( $request ); 3159 $data = $response->get_data();3531 $data = $response->get_data(); 3160 3532 3161 3533 $this->assertArrayHasKey( 'my_custom_int', $data['schema']['properties'] ); … … 3172 3544 3173 3545 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . $post_id ); 3174 $request->set_body_params(array( 3175 'my_custom_int' => 123, 3176 )); 3546 $request->set_body_params( 3547 array( 3548 'my_custom_int' => 123, 3549 ) 3550 ); 3177 3551 3178 3552 $response = $this->server->dispatch( $request ); … … 3180 3554 3181 3555 $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); 3182 $request->set_body_params(array( 3183 'my_custom_int' => 123, 3184 'title' => 'hello', 3185 )); 3556 $request->set_body_params( 3557 array( 3558 'my_custom_int' => 123, 3559 'title' => 'hello', 3560 ) 3561 ); 3186 3562 3187 3563 $response = $this->server->dispatch( $request ); … … 3201 3577 ); 3202 3578 3203 register_rest_field( 'post', 'my_custom_int', array( 3204 'schema' => $schema, 3205 'get_callback' => array( $this, 'additional_field_get_callback' ), 3206 'update_callback' => array( $this, 'additional_field_update_callback' ), 3207 ) ); 3579 register_rest_field( 3580 'post', 'my_custom_int', array( 3581 'schema' => $schema, 3582 'get_callback' => array( $this, 'additional_field_get_callback' ), 3583 'update_callback' => array( $this, 'additional_field_update_callback' ), 3584 ) 3585 ); 3208 3586 3209 3587 wp_set_current_user( self::$editor_id ); 3210 3588 // Check for error on update. 3211 3589 $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 3212 $request->set_body_params( array( 3213 'my_custom_int' => 'returnError', 3214 ) ); 3590 $request->set_body_params( 3591 array( 3592 'my_custom_int' => 'returnError', 3593 ) 3594 ); 3215 3595 3216 3596 $response = $this->server->dispatch( $request );
Note: See TracChangeset
for help on using the changeset viewer.