- Timestamp:
- 11/15/2018 12:56:54 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/tests/phpunit/tests/rest-api/rest-autosaves-controller.php
r43768 r43897 14 14 protected static $post_id; 15 15 protected static $page_id; 16 protected static $draft_page_id; 16 17 17 18 protected static $autosave_post_id; … … 20 21 protected static $editor_id; 21 22 protected static $contributor_id; 23 24 protected static $parent_page_id; 25 protected static $child_page_id; 26 protected static $child_draft_page_id; 22 27 23 28 protected function set_post_data( $args = array() ) { … … 77 82 ); 78 83 84 self::$draft_page_id = $factory->post->create( array( 85 'post_type' => 'page', 86 'post_status' => 'draft', 87 ) ); 88 self::$parent_page_id = $factory->post->create( array( 89 'post_type' => 'page', 90 ) ); 91 self::$child_page_id = $factory->post->create( array( 92 'post_type' => 'page', 93 'post_parent' => self::$parent_page_id, 94 ) ); 95 self::$child_draft_page_id = $factory->post->create( array( 96 'post_type' => 'page', 97 'post_parent' => self::$parent_page_id, 98 // The "update post" behavior of the autosave endpoint only occurs 99 // when saving a draft/auto-draft authored by the current user. 100 'post_status' => 'draft', 101 'post_author' => self::$editor_id, 102 ) ); 79 103 } 80 104 … … 97 121 public function test_register_routes() { 98 122 $routes = rest_get_server()->get_routes(); 99 $this->assertArrayHasKey( '/wp/v2/posts/(?P< parent>[\d]+)/autosaves', $routes );123 $this->assertArrayHasKey( '/wp/v2/posts/(?P<id>[\d]+)/autosaves', $routes ); 100 124 $this->assertArrayHasKey( '/wp/v2/posts/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+)', $routes ); 101 $this->assertArrayHasKey( '/wp/v2/pages/(?P< parent>[\d]+)/autosaves', $routes );125 $this->assertArrayHasKey( '/wp/v2/pages/(?P<id>[\d]+)/autosaves', $routes ); 102 126 $this->assertArrayHasKey( '/wp/v2/pages/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+)', $routes ); 103 127 } … … 118 142 $this->assertEquals( 'view', $data['endpoints'][0]['args']['context']['default'] ); 119 143 $this->assertEqualSets( array( 'view', 'edit', 'embed' ), $data['endpoints'][0]['args']['context']['enum'] ); 144 } 145 146 public function test_registered_query_params() { 147 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id . '/autosaves' ); 148 $response = $this->server->dispatch( $request ); 149 $data = $response->get_data(); 150 $keys = array_keys( $data['endpoints'][0]['args'] ); 151 sort( $keys ); 152 $this->assertEquals( array( 153 'context', 154 'parent', 155 ), $keys ); 120 156 } 121 157 … … 518 554 } 519 555 556 public function test_update_item_draft_page_with_parent() { 557 wp_set_current_user( self::$editor_id ); 558 $request = new WP_REST_Request( 'POST', '/wp/v2/pages/' . self::$child_draft_page_id . '/autosaves' ); 559 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 560 561 $params = $this->set_post_data( 562 array( 563 'id' => self::$child_draft_page_id, 564 'author' => self::$editor_id, 565 ) 566 ); 567 568 $request->set_body_params( $params ); 569 $response = rest_get_server()->dispatch( $request ); 570 $data = $response->get_data(); 571 572 $this->assertEquals( self::$child_draft_page_id, $data['id'] ); 573 $this->assertEquals( self::$parent_page_id, $data['parent'] ); 574 } 575 576 public function test_schema_validation_is_applied() { 577 wp_set_current_user( self::$editor_id ); 578 579 $request = new WP_REST_Request( 'POST', '/wp/v2/pages/' . self::$draft_page_id . '/autosaves' ); 580 $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); 581 582 $params = $this->set_post_data( array( 583 'id' => self::$draft_page_id, 584 'comment_status' => 'garbage', 585 ) ); 586 587 $request->set_body_params( $params ); 588 589 $response = rest_get_server()->dispatch( $request ); 590 $this->assertNotEquals( 'garbage', get_post( self::$draft_page_id )->comment_status ); 591 } 520 592 }
Note: See TracChangeset
for help on using the changeset viewer.