Skip to content

Commit 00e446b

Browse files
validate individual comment endpoint returns correct status
1 parent 05d53d4 commit 00e446b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4180,6 +4180,16 @@ public function test_get_items_type_arg_authenticated( $comment_type, $count ) {
41804180

41814181
$comments = $response->get_data();
41824182
$this->assertCount( 'comment' === $comment_type ? $count + self::$total_comments: $count, $comments );
4183+
4184+
// Next, test getting the individual comments.
4185+
foreach( $comments as $comment ) {
4186+
$request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $comment['id'] ) );
4187+
$response = rest_get_server()->dispatch( $request );
4188+
4189+
$this->assertEquals( 200, $response->get_status() );
4190+
$data = $response->get_data();
4191+
$this->assertEquals( $comment_type, $data['type'] );
4192+
}
41834193
}
41844194

41854195
/**
@@ -4202,8 +4212,10 @@ public function test_get_items_type_arg_unauthenticated( $comment_type, $count )
42024212
'comment_type' => $comment_type,
42034213
);
42044214

4215+
$comments = array();
4216+
42054217
for ( $i = 0; $i < $count; $i++ ) {
4206-
self::factory()->comment->create( $args );
4218+
$comments[] = self::factory()->comment->create( $args );
42074219
}
42084220

42094221
// Log out and test as unauthenticated user.
@@ -4218,6 +4230,13 @@ public function test_get_items_type_arg_unauthenticated( $comment_type, $count )
42184230
if ( 'comment' !== $comment_type ) {
42194231
$this->assertErrorResponse( 'rest_forbidden_param', $response, 401 );
42204232
}
4233+
4234+
// Next, test getting the individual comments.
4235+
foreach( $comments as $comment ) {
4236+
$request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $comment ) );
4237+
$response = rest_get_server()->dispatch( $request );
4238+
$this->assertEquals( 'comment' === $comment_type ? 200 : 401, $response->get_status() );
4239+
}
42214240
}
42224241

42234242
/**

0 commit comments

Comments
 (0)