| 4844 | /** |
| 4845 | * @ticket 47443 |
| 4846 | */ |
| 4847 | public function test_edit_published_post_without_publish_posts_capability() { |
| 4848 | wp_set_current_user( self::$editor_id ); |
| 4849 | $user = wp_get_current_user(); |
| 4850 | $user->add_cap( 'publish_posts', false ); |
| 4851 | $user->add_cap( 'edit_published_posts', true ); |
| 4852 | |
| 4853 | // Flush capabilities, https://core.trac.wordpress.org/ticket/28374 |
| 4854 | $user->get_role_caps(); |
| 4855 | $user->update_user_level_from_caps(); |
| 4856 | |
| 4857 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 4858 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
| 4859 | $params = $this->set_post_data( array( |
| 4860 | 'title' => 'Hello World', |
| 4861 | 'content' => 'Hello, world.', |
| 4862 | 'excerpt' => 'Hello', |
| 4863 | 'name' => 'test', |
| 4864 | 'status' => 'future', |
| 4865 | 'author' => get_current_user_id(), |
| 4866 | 'type' => 'post', |
| 4867 | ) ); |
| 4868 | |
| 4869 | $request->set_body_params( $params ); |
| 4870 | $response = rest_get_server()->dispatch( $request ); |
| 4871 | $this->check_update_post_response( $response ); |
| 4872 | $new_data = $response->get_data(); |
| 4873 | |
| 4874 | $this->assertEquals( self::$post_id, $new_data['id'] ); |
| 4875 | $this->assertEquals( $params['title'], $new_data['title']['raw'] ); |
| 4876 | $this->assertEquals( $params['content'], $new_data['content']['raw'] ); |
| 4877 | $this->assertEquals( $params['excerpt'], $new_data['excerpt']['raw'] ); |
| 4878 | $post = get_post( self::$post_id ); |
| 4879 | $this->assertEquals( 'Hello World', $post->post_title ); |
| 4880 | $this->assertEquals( 'Hello, world.', $post->post_content ); |
| 4881 | $this->assertEquals( 'Hello', $post->post_excerpt ); |
| 4882 | |
| 4883 | $request2 = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 4884 | $request2->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
| 4885 | $params2 = $this->set_post_data( array( |
| 4886 | 'content' => 'Hello again.', |
| 4887 | 'status' => 'future', |
| 4888 | ) ); |
| 4889 | $request2->set_body_params( $params2 ); |
| 4890 | $response2 = rest_get_server()->dispatch( $request2 ); |
| 4891 | $this->check_update_post_response( $response2 ); |
| 4892 | $data2 = $response2->get_data(); |
| 4893 | $post2 = get_post( self::$post_id ); |
| 4894 | $this->assertEquals( 'Hello again.', $post2->post_content ); |
| 4895 | } |
| 4896 | |