REST API: Add unit tests for the 404 template slug handler.

Props ockham, SergeyBiryukov, hellofromTonya, rachelbaker.
Fixes #54680.


git-svn-id: https://develop.svn.wordpress.org/trunk@52436 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras
2022-01-04 14:23:56 +00:00
parent 4581fbea5a
commit 18aa343ec2

View File

@@ -389,6 +389,52 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
);
}
/**
* @ticket 54680
* @covers WP_REST_Templates_Controller::create_item
* @covers WP_REST_Templates_Controller::get_item_schema
*/
public function test_create_item_with_numeric_slug() {
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/templates' );
$request->set_body_params(
array(
'slug' => '404',
'description' => 'Template shown when no content is found.',
'title' => '404',
'author' => self::$admin_id,
)
);
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
unset( $data['_links'] );
unset( $data['wp_id'] );
$this->assertSame(
array(
'id' => 'default//404',
'theme' => 'default',
'content' => array(
'raw' => '',
),
'slug' => '404',
'source' => 'custom',
'origin' => null,
'type' => 'wp_template',
'description' => 'Template shown when no content is found.',
'title' => array(
'raw' => '404',
'rendered' => '404',
),
'status' => 'publish',
'has_theme_file' => false,
'is_custom' => false,
'author' => self::$admin_id,
),
$data
);
}
/**
* @ticket 54422
* @covers WP_REST_Templates_Controller::create_item