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 31, 2024
1 parent f53b447 commit 0c93eab
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/phpunit/tests/rest-api/wpRestTemplateAutosavesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0c93eab

Please sign in to comment.