From 0c93eab360cd667bb94c2ab2e15dbc6e6df7f159 Mon Sep 17 00:00:00 2001 From: Anton Vlasenko Date: Tue, 31 Dec 2024 15:49:31 +0100 Subject: [PATCH] Add unit tests. --- .../wpRestTemplateAutosavesController.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php b/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php index 550eb8e5fe999..6164f84a70649 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php @@ -208,6 +208,28 @@ public function test_get_items() { ); } + /** + * @ticket 56481 + */ + public function test_get_items_should_return_no_response_body_for_head_requests() { + wp_set_current_user( self::$admin_id ); + $autosave_post_id = wp_create_post_autosave( + array( + 'post_content' => 'Autosave content.', + 'post_ID' => self::$template_post->ID, + 'post_type' => self::PARENT_POST_TYPE, + ) + ); + + $request = new WP_REST_Request( + 'HEAD', + '/wp/v2/templates/' . self::TEST_THEME . '/' . self::TEMPLATE_NAME . '/autosaves' + ); + $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_Template_Autosaves_Controller::get_item * @ticket 56922 @@ -243,6 +265,26 @@ public function test_get_item() { ); } + /** + * @ticket 56481 + */ + public function test_get_item_should_return_no_response_body_for_head_requests() { + wp_set_current_user( self::$admin_id ); + + $autosave_post_id = wp_create_post_autosave( + array( + 'post_content' => 'Autosave content.', + 'post_ID' => self::$template_post->ID, + 'post_type' => self::PARENT_POST_TYPE, + ) + ); + + $request = new WP_REST_Request( 'HEAD', '/wp/v2/templates/' . self::TEST_THEME . '/' . self::TEMPLATE_NAME . '/autosaves/' . $autosave_post_id ); + $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_Template_Autosaves_Controller::prepare_item_for_response * @ticket 56922