Skip to content

Commit ca2204c

Browse files
committed
Tests: Assert unsupported URL Details requests.
Replace empty REST test stubs with assertions that unsupported requests return `rest_no_route`. Check `POST`, `PUT`, `PATCH`, and `DELETE` on the actual endpoint, and retain a separate check for the absent item route. Developed in: #14109 Props shailu25. See #66073. git-svn-id: https://develop.svn.wordpress.org/trunk@64278 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a52e34f commit ca2204c

1 file changed

Lines changed: 38 additions & 8 deletions

File tree

‎tests/phpunit/tests/rest-api/wpRestUrlDetailsController.php‎

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,31 +1070,61 @@ public function test_context_param() {
10701070
}
10711071

10721072
/**
1073-
* @doesNotPerformAssertions
1073+
* URL Details has no item route.
1074+
*
1075+
* @ticket 66073
10741076
*/
10751077
public function test_get_item() {
1076-
// Controller does not implement get_item().
1078+
wp_set_current_user( self::$admin_id );
1079+
1080+
$request = new WP_REST_Request( 'GET', static::REQUEST_ROUTE . '/example' );
1081+
$response = rest_get_server()->dispatch( $request );
1082+
1083+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
10771084
}
10781085

10791086
/**
1080-
* @doesNotPerformAssertions
1087+
* URL Details is read-only; create requests should not match a route.
1088+
*
1089+
* @ticket 66073
10811090
*/
10821091
public function test_create_item() {
1083-
// Controller does not implement create_item().
1092+
wp_set_current_user( self::$admin_id );
1093+
1094+
$request = new WP_REST_Request( 'POST', static::REQUEST_ROUTE );
1095+
$response = rest_get_server()->dispatch( $request );
1096+
1097+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
10841098
}
10851099

10861100
/**
1087-
* @doesNotPerformAssertions
1101+
* URL Details is read-only; update requests on the real endpoint should not match a route.
1102+
*
1103+
* @ticket 66073
10881104
*/
10891105
public function test_update_item() {
1090-
// Controller does not implement update_item().
1106+
wp_set_current_user( self::$admin_id );
1107+
1108+
foreach ( array( 'PUT', 'PATCH' ) as $method ) {
1109+
$request = new WP_REST_Request( $method, static::REQUEST_ROUTE );
1110+
$response = rest_get_server()->dispatch( $request );
1111+
1112+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
1113+
}
10911114
}
10921115

10931116
/**
1094-
* @doesNotPerformAssertions
1117+
* URL Details is read-only; delete requests on the real endpoint should not match a route.
1118+
*
1119+
* @ticket 66073
10951120
*/
10961121
public function test_delete_item() {
1097-
// Controller does not implement delete_item().
1122+
wp_set_current_user( self::$admin_id );
1123+
1124+
$request = new WP_REST_Request( 'DELETE', static::REQUEST_ROUTE );
1125+
$response = rest_get_server()->dispatch( $request );
1126+
1127+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
10981128
}
10991129

11001130
/**

0 commit comments

Comments
 (0)