Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions tests/phpunit/tests/rest-api/rest-comments-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3969,6 +3969,66 @@
}
}

/**
* @ticket 99999
*/
public function test_note_responses_are_trashed_when_parent_is() {
wp_set_current_user( self::$editor_id );
$post_id = self::factory()->post->create();

$params = array(
'post' => $post_id,
'author_name' => 'Editor',
'author_email' => '[email protected]',
'author_url' => 'https://example.com',
'author' => self::$editor_id,
'type' => 'note',
'content' => 'This is a top-level note',
);
$request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
$request->add_header( 'Content-Type', 'application/json' );
$request->set_body( wp_json_encode( $params ) );
$response = rest_get_server()->dispatch( $request );
$this->assertSame( 201, $response->get_status() );

$top_level_note = $response->get_data();
$nested_notes = array();

Check warning on line 3995 in tests/phpunit/tests/rest-api/rest-comments-controller.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

for ( $i = 0; $i < 2; $i++ ) {
$params = array(

Check warning on line 3998 in tests/phpunit/tests/rest-api/rest-comments-controller.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Equals sign not aligned with surrounding assignments; expected 8 spaces but found 2 spaces
'post' => $post_id,
'parent' => $top_level_note['id'],
'author_name' => 'Editor',
'author_email' => '[email protected]',
'author_url' => 'https://example.com',
'author' => self::$editor_id,
'type' => 'note',
'content' => 'Nested comment #' . $i,
);
$child_request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
$child_request->add_header( 'Content-Type', 'application/json' );
$child_request->set_body( wp_json_encode( $params ) );
$child_response = rest_get_server()->dispatch( $child_request );
$this->assertSame( 201, $child_response->get_status() );

$current_reply = $child_response->get_data();

Check warning on line 4014 in tests/phpunit/tests/rest-api/rest-comments-controller.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
$nested_notes[] = $current_reply['id'];
}

$delete_request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $top_level_note['id'] ) );
$delete_request->set_param( 'force', 'false' );
$delete_response = rest_get_server()->dispatch( $delete_request );
$this->assertSame( 200, $delete_response->get_status() );

$data = $delete_response->get_data();
$this->assertSame( 'trash', $data['status'] );

foreach ( $nested_notes as $comment_id ) {
$reply_status = wp_get_comment_status( $comment_id );
$this->assertSame( 'trash', $reply_status );
}
}

/**
* @dataProvider data_note_get_items_permissions_data_provider
* @ticket 64096
Expand Down
Loading