Skip to content

Commit

Permalink
Add unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-vlasenko committed Dec 27, 2024
1 parent 57c03f1 commit 900dd4b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,8 @@ public function test_get_item() {
/**
* @ticket 56481
*
* @covers WP_REST_Global_Styles_Controller::get_item
* @covers WP_REST_Global_Styles_Controller::prepare_item_for_response
*
* @param string $method The HTTP method to use.
*/
public function test_get_item_should_return_no_response_body_for_head_requests() {
wp_set_current_user( self::$admin_id );
Expand Down
28 changes: 27 additions & 1 deletion tests/phpunit/tests/rest-api/wpRestTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ public function test_get_items() {
);
}

/**
* @ticket 56481
*
* @covers WP_REST_Templates_Controller::get_items
*/
public function test_get_items_should_return_no_response_body_for_head_requests() {
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'HEAD', '/wp/v2/templates' );
$response = rest_get_server()->dispatch( $request );
$this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
$this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
}

/**
* @covers WP_REST_Templates_Controller::get_items
*/
Expand Down Expand Up @@ -267,6 +280,20 @@ public function test_get_item() {
);
}

/**
* @ticket 56481
*
* @covers WP_REST_Templates_Controller::get_item
* @covers WP_REST_Templates_Controller::prepare_item_for_response
*/
public function test_get_item_should_return_no_response_body_for_head_requests() {
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'GET', '/wp/v2/templates/default//my_template' );
$response = rest_get_server()->dispatch( $request );
$this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
$this->assertNull( $response->get_data(), 'The server should not generate a body in response to a HEAD request.' );
}

/**
* @covers WP_REST_Templates_Controller::get_item
*/
Expand Down Expand Up @@ -311,7 +338,6 @@ public function test_get_item_subscriber() {
wp_set_current_user( self::$subscriber_id );
$request = new WP_REST_Request( 'GET', '/wp/v2/templates/default//my_template' );
$response = rest_get_server()->dispatch( $request );
$response = rest_get_server()->dispatch( $request );
$this->assertErrorResponse( 'rest_cannot_manage_templates', $response, 403 );
}

Expand Down

0 comments on commit 900dd4b

Please sign in to comment.