Skip to content

Commit 57b5ab2

Browse files
committed
Tests: Verify settings REST method behavior.
Assert that `POST` on the settings route updates the title and stored option. Check that `DELETE` returns `rest_no_route` on the registered settings route after confirming that `GET` succeeds. Developed in: #14152 Props shailu25. See #66073. git-svn-id: https://develop.svn.wordpress.org/trunk@64291 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ffdef39 commit 57b5ab2

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

‎tests/phpunit/tests/rest-api/rest-settings-controller.php‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,26 @@ public function test_get_item_with_invalid_object_array_in_options() {
413413
}
414414

415415
/**
416-
* @doesNotPerformAssertions
416+
* Settings has no create_item(); POST on the registered route updates.
417+
*
418+
* @ticket 66073
417419
*/
418420
public function test_create_item() {
419-
// Controller does not implement create_item().
421+
wp_set_current_user( self::$administrator );
422+
423+
$route = '/wp/v2/settings';
424+
425+
$response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', $route ) );
426+
$this->assertSame( 200, $response->get_status() );
427+
428+
$request = new WP_REST_Request( 'POST', $route );
429+
$request->set_param( 'title', 'Settings title via POST' );
430+
$response = rest_get_server()->dispatch( $request );
431+
$data = $response->get_data();
432+
433+
$this->assertSame( 200, $response->get_status() );
434+
$this->assertSame( 'Settings title via POST', $data['title'] );
435+
$this->assertSame( get_option( 'blogname' ), $data['title'] );
420436
}
421437

422438
public function test_update_item() {
@@ -721,11 +737,23 @@ public function test_update_item_with_invalid_stored_value_in_options() {
721737
$this->assertErrorResponse( 'rest_invalid_stored_value', $response, 500 );
722738
}
723739

740+
/**
741+
* Settings route is not deletable; delete requests should not match a route.
742+
*
743+
* @ticket 66073
744+
*/
724745
public function test_delete_item() {
725-
/** Settings can't be deleted */
726-
$request = new WP_REST_Request( 'DELETE', '/wp/v2/settings/title' );
746+
wp_set_current_user( self::$administrator );
747+
748+
$route = '/wp/v2/settings';
749+
750+
$response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', $route ) );
751+
$this->assertSame( 200, $response->get_status() );
752+
753+
$request = new WP_REST_Request( 'DELETE', $route );
727754
$response = rest_get_server()->dispatch( $request );
728-
$this->assertSame( 404, $response->get_status() );
755+
756+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
729757
}
730758

731759
/**

0 commit comments

Comments
 (0)