Skip to content

Commit

Permalink
Genericize error message and create a test to ensure the correct pare…
Browse files Browse the repository at this point in the history
…nt ID is returned in the error message.
  • Loading branch information
ramonjd committed Dec 21, 2023
1 parent ff84ef6 commit c5f48bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public function get_item( $request ) {
return new WP_Error(
'rest_revision_parent_id_mismatch',
/* translators: %d: A post revision id. */
sprintf( __( 'Parent does not have a revision with id of "%d"' ), $request['id'] ),
sprintf( __( 'The revision does not belong to the specified parent with id of "%d"' ), $parent->ID ),
array( 'status' => 404 )
);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/rest-api/rest-revisions-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ public function test_get_item_invalid_parent_id() {
$request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_2_1_id );
$response = rest_get_server()->dispatch( $request );
$this->assertErrorResponse( 'rest_revision_parent_id_mismatch', $response, 404 );

$expected_message = 'The revision does not belong to the specified parent with id of "' . self::$post_id . '"';
$this->assertSame( $expected_message, $response->as_error()->get_error_messages()[0], 'The message must contain the correct parent ID.' );
}

public function test_delete_item() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ public function test_get_item_invalid_parent_id() {

$response = rest_get_server()->dispatch( $request );
$this->assertErrorResponse( 'rest_revision_parent_id_mismatch', $response, 404 );

$expected_message = 'The revision does not belong to the specified parent with id of "' . self::$template_post_2->ID . '"';
$this->assertSame( $expected_message, $response->as_error()->get_error_messages()[0], 'The message must contain the correct parent ID.' );
}

/**
Expand Down

0 comments on commit c5f48bd

Please sign in to comment.