@@ 228-242 (lines=15) @@ | ||
225 | ||
226 | } |
|
227 | ||
228 | public function test_create_item_with_template() { |
|
229 | wp_set_current_user( $this->editor_id ); |
|
230 | ||
231 | $request = new WP_REST_Request( 'POST', '/wp/v2/pages' ); |
|
232 | $params = $this->set_post_data( array( |
|
233 | 'template' => 'page-my-test-template.php', |
|
234 | ) ); |
|
235 | $request->set_body_params( $params ); |
|
236 | $response = $this->server->dispatch( $request ); |
|
237 | ||
238 | $data = $response->get_data(); |
|
239 | $new_post = get_post( $data['id'] ); |
|
240 | $this->assertEquals( 'page-my-test-template.php', $data['template'] ); |
|
241 | $this->assertEquals( 'page-my-test-template.php', get_page_template_slug( $new_post->ID ) ); |
|
242 | } |
|
243 | ||
244 | public function test_create_page_with_parent() { |
|
245 | $page_id = $this->factory->post->create( array( |
@@ 911-925 (lines=15) @@ | ||
908 | $this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 ); |
|
909 | } |
|
910 | ||
911 | public function test_delete_item() { |
|
912 | $user_id = $this->factory->user->create( array( 'display_name' => 'Deleted User' ) ); |
|
913 | ||
914 | $this->allow_user_to_manage_multisite(); |
|
915 | wp_set_current_user( $this->user ); |
|
916 | ||
917 | $userdata = get_userdata( $user_id ); // cache for later |
|
918 | $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/users/%d', $user_id ) ); |
|
919 | $request['force'] = true; |
|
920 | $response = $this->server->dispatch( $request ); |
|
921 | ||
922 | $this->assertEquals( 200, $response->get_status() ); |
|
923 | $data = $response->get_data(); |
|
924 | $this->assertEquals( 'Deleted User', $data['name'] ); |
|
925 | } |
|
926 | ||
927 | public function test_delete_item_no_trash() { |
|
928 | $user_id = $this->factory->user->create( array( 'display_name' => 'Deleted User' ) ); |
@@ 776-790 (lines=15) @@ | ||
773 | $this->assertNull( $data['modified_gmt'] ); |
|
774 | } |
|
775 | ||
776 | public function test_create_post_private() { |
|
777 | wp_set_current_user( $this->editor_id ); |
|
778 | ||
779 | $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); |
|
780 | $params = $this->set_post_data( array( |
|
781 | 'status' => 'private', |
|
782 | ) ); |
|
783 | $request->set_body_params( $params ); |
|
784 | $response = $this->server->dispatch( $request ); |
|
785 | ||
786 | $data = $response->get_data(); |
|
787 | $new_post = get_post( $data['id'] ); |
|
788 | $this->assertEquals( 'private', $data['status'] ); |
|
789 | $this->assertEquals( 'private', $new_post->post_status ); |
|
790 | } |
|
791 | ||
792 | public function test_create_post_private_without_permission() { |
|
793 | wp_set_current_user( $this->author_id ); |
|
@@ 842-856 (lines=15) @@ | ||
839 | $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); |
|
840 | } |
|
841 | ||
842 | public function test_create_post_with_format() { |
|
843 | wp_set_current_user( $this->editor_id ); |
|
844 | ||
845 | $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); |
|
846 | $params = $this->set_post_data( array( |
|
847 | 'format' => 'gallery', |
|
848 | ) ); |
|
849 | $request->set_body_params( $params ); |
|
850 | $response = $this->server->dispatch( $request ); |
|
851 | ||
852 | $data = $response->get_data(); |
|
853 | $new_post = get_post( $data['id'] ); |
|
854 | $this->assertEquals( 'gallery', $data['format'] ); |
|
855 | $this->assertEquals( 'gallery', get_post_format( $new_post->ID ) ); |
|
856 | } |
|
857 | ||
858 | public function test_create_post_with_invalid_format() { |
|
859 | wp_set_current_user( $this->editor_id ); |
|
@@ 1266-1280 (lines=15) @@ | ||
1263 | $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 ); |
|
1264 | } |
|
1265 | ||
1266 | public function test_update_post_with_format() { |
|
1267 | wp_set_current_user( $this->editor_id ); |
|
1268 | ||
1269 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) ); |
|
1270 | $params = $this->set_post_data( array( |
|
1271 | 'format' => 'gallery', |
|
1272 | ) ); |
|
1273 | $request->set_body_params( $params ); |
|
1274 | $response = $this->server->dispatch( $request ); |
|
1275 | ||
1276 | $data = $response->get_data(); |
|
1277 | $new_post = get_post( $data['id'] ); |
|
1278 | $this->assertEquals( 'gallery', $data['format'] ); |
|
1279 | $this->assertEquals( 'gallery', get_post_format( $new_post->ID ) ); |
|
1280 | } |
|
1281 | ||
1282 | public function test_update_post_with_invalid_format() { |
|
1283 | wp_set_current_user( $this->editor_id ); |
|
@@ 1347-1361 (lines=15) @@ | ||
1344 | $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); |
|
1345 | } |
|
1346 | ||
1347 | public function test_update_post_slug() { |
|
1348 | wp_set_current_user( $this->editor_id ); |
|
1349 | ||
1350 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) ); |
|
1351 | $params = $this->set_post_data( array( |
|
1352 | 'slug' => 'sample-slug', |
|
1353 | ) ); |
|
1354 | $request->set_body_params( $params ); |
|
1355 | $response = $this->server->dispatch( $request ); |
|
1356 | ||
1357 | $new_data = $response->get_data(); |
|
1358 | $this->assertEquals( 'sample-slug', $new_data['slug'] ); |
|
1359 | $post = get_post( $new_data['id'] ); |
|
1360 | $this->assertEquals( 'sample-slug', $post->post_name ); |
|
1361 | } |
|
1362 | ||
1363 | public function test_update_post_sticky() { |
|
1364 | wp_set_current_user( $this->editor_id ); |