| 2483 | /** |
| 2484 | * @ticket 47024 |
| 2485 | * |
| 2486 | * @todo flip logic to test for 200 if #41037 is addressed. |
| 2487 | */ |
| 2488 | public function test_update_comment_when_comment_author_but_not_post_author() { |
| 2489 | wp_set_current_user( self::$author_id ); |
| 2490 | |
| 2491 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); |
| 2492 | $params = array( |
| 2493 | 'content' => 'Updated comment.', |
| 2494 | 'date' => '2019-10-07T23:14:25', |
| 2495 | ); |
| 2496 | $request->add_header( 'content-type', 'application/json' ); |
| 2497 | $request->set_body( wp_json_encode( $params ) ); |
| 2498 | |
| 2499 | $response = rest_get_server()->dispatch( $request ); |
| 2500 | $this->assertErrorResponse( 'rest_cannot_edit', $response, 403 ); |
| 2501 | } |
| 2502 | |
| 2503 | /** |
| 2504 | * @ticket 47024 |
| 2505 | */ |
| 2506 | public function test_update_comment_when_can_manage_comments() { |
| 2507 | wp_set_current_user( self::$editor_id ); |
| 2508 | |
| 2509 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); |
| 2510 | $params = array( |
| 2511 | 'content' => 'Updated comment.', |
| 2512 | 'date' => '2019-10-07T23:14:25', |
| 2513 | ); |
| 2514 | $request->add_header( 'content-type', 'application/json' ); |
| 2515 | $request->set_body( wp_json_encode( $params ) ); |
| 2516 | |
| 2517 | $response = rest_get_server()->dispatch( $request ); |
| 2518 | $this->assertEquals( 200, $response->get_status() ); |
| 2519 | |
| 2520 | $comment = $response->get_data(); |
| 2521 | $updated = get_comment( self::$approved_id ); |
| 2522 | |
| 2523 | $this->assertEquals( $params['content'], $comment['content']['raw'] ); |
| 2524 | $this->assertEquals( self::$post_id, $comment['post'] ); |
| 2525 | $this->assertEquals( mysql_to_rfc3339( $updated->comment_date ), $comment['date'] ); |
| 2526 | $this->assertEquals( '2019-10-07T23:14:25', $comment['date'] ); |
| 2527 | } |
| 2528 | |