Skip to content

Commit 4345535

Browse files
committed
Add test that shows child notes not also trashed
1 parent d1a4644 commit 4345535

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/phpunit/tests/rest-api/rest-comments-controller.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,6 +3969,66 @@ public function test_create_duplicate_note() {
39693969
}
39703970
}
39713971

3972+
/**
3973+
* @ticket 99999
3974+
*/
3975+
public function test_note_responses_are_trashed_when_parent_is() {
3976+
wp_set_current_user( self::$editor_id );
3977+
$post_id = self::factory()->post->create();
3978+
3979+
$params = array(
3980+
'post' => $post_id,
3981+
'author_name' => 'Editor',
3982+
'author_email' => '[email protected]',
3983+
'author_url' => 'https://example.com',
3984+
'author' => self::$editor_id,
3985+
'type' => 'note',
3986+
'content' => 'This is a top-level note',
3987+
);
3988+
$request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
3989+
$request->add_header( 'Content-Type', 'application/json' );
3990+
$request->set_body( wp_json_encode( $params ) );
3991+
$response = rest_get_server()->dispatch( $request );
3992+
$this->assertSame( 201, $response->get_status() );
3993+
3994+
$top_level_note = $response->get_data();
3995+
$nested_notes = array();
3996+
3997+
for ( $i = 0; $i < 2; $i++ ) {
3998+
$params = array(
3999+
'post' => $post_id,
4000+
'parent' => $top_level_note['id'],
4001+
'author_name' => 'Editor',
4002+
'author_email' => '[email protected]',
4003+
'author_url' => 'https://example.com',
4004+
'author' => self::$editor_id,
4005+
'type' => 'note',
4006+
'content' => 'Nested comment #' . $i,
4007+
);
4008+
$child_request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
4009+
$child_request->add_header( 'Content-Type', 'application/json' );
4010+
$child_request->set_body( wp_json_encode( $params ) );
4011+
$child_response = rest_get_server()->dispatch( $child_request );
4012+
$this->assertSame( 201, $child_response->get_status() );
4013+
4014+
$current_reply = $child_response->get_data();
4015+
$nested_notes[] = $current_reply['id'];
4016+
}
4017+
4018+
$delete_request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $top_level_note['id'] ) );
4019+
$delete_request->set_param( 'force', 'false' );
4020+
$delete_response = rest_get_server()->dispatch( $delete_request );
4021+
$this->assertSame( 200, $delete_response->get_status() );
4022+
4023+
$data = $delete_response->get_data();
4024+
$this->assertSame( 'trash', $data['status'] );
4025+
4026+
foreach ( $nested_notes as $comment_id ) {
4027+
$reply_status = wp_get_comment_status( $comment_id );
4028+
$this->assertSame( 'trash', $reply_status );
4029+
}
4030+
}
4031+
39724032
/**
39734033
* @dataProvider data_note_get_items_permissions_data_provider
39744034
* @ticket 64096

0 commit comments

Comments
 (0)