Skip to content

Commit 7148cd9

Browse files
committed
Tests: Reject unsupported widget type requests.
Assert that collection creation and item update and deletion requests return `rest_no_route`. Verify the widget type item route accepts `GET` before checking unsupported write methods. Developed in: #14113 Props shailu25. See #66073. git-svn-id: https://develop.svn.wordpress.org/trunk@64274 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e1a8605 commit 7148cd9

1 file changed

Lines changed: 36 additions & 9 deletions

File tree

‎tests/phpunit/tests/rest-api/rest-widget-types-controller.php‎

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -653,29 +653,56 @@ public function test_encode_form_data_no_raw() {
653653
}
654654

655655
/**
656-
* The create_item() method does not exist for widget types.
656+
* Widget types is read-only; create requests should not match a route.
657657
*
658-
* @doesNotPerformAssertions
658+
* @ticket 66073
659659
*/
660660
public function test_create_item() {
661-
// Controller does not implement create_item().
661+
wp_set_current_user( self::$admin_id );
662+
663+
$request = new WP_REST_Request( 'POST', '/wp/v2/widget-types' );
664+
$response = rest_get_server()->dispatch( $request );
665+
666+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
662667
}
663668

664669
/**
665-
* The update_item() method does not exist for widget types.
670+
* Widget types is read-only; update requests should not match a route.
666671
*
667-
* @doesNotPerformAssertions
672+
* @ticket 66073
668673
*/
669674
public function test_update_item() {
670-
// Controller does not implement update_item().
675+
wp_set_current_user( self::$admin_id );
676+
677+
$route = '/wp/v2/widget-types/calendar';
678+
679+
$response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', $route ) );
680+
$this->assertSame( 200, $response->get_status() );
681+
682+
foreach ( array( 'POST', 'PUT', 'PATCH' ) as $method ) {
683+
$request = new WP_REST_Request( $method, $route );
684+
$response = rest_get_server()->dispatch( $request );
685+
686+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
687+
}
671688
}
672689

673690
/**
674-
* The delete_item() method does not exist for widget types.
691+
* Widget types is read-only; delete requests should not match a route.
675692
*
676-
* @doesNotPerformAssertions
693+
* @ticket 66073
677694
*/
678695
public function test_delete_item() {
679-
// Controller does not implement delete_item().
696+
wp_set_current_user( self::$admin_id );
697+
698+
$route = '/wp/v2/widget-types/calendar';
699+
700+
$response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', $route ) );
701+
$this->assertSame( 200, $response->get_status() );
702+
703+
$request = new WP_REST_Request( 'DELETE', $route );
704+
$response = rest_get_server()->dispatch( $request );
705+
706+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
680707
}
681708
}

0 commit comments

Comments
 (0)