From 18aa343ec2362be1bc7b0440de582ece2a3352c4 Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Tue, 4 Jan 2022 14:23:56 +0000 Subject: [PATCH] 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 --- .../rest-api/wpRestTemplatesController.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php index 477467d644..5242436bd6 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php @@ -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