Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ public function get_item_schema() {
'context' => array( 'embed', 'view', 'edit' ),
'required' => true,
'minLength' => 1,
'pattern' => '[a-zA-Z_\-]+',
'pattern' => '[a-zA-Z0-9_\-]+',
),
'theme' => array(
'description' => __( 'Theme identifier for the template.' ),
Expand Down
46 changes: 46 additions & 0 deletions tests/phpunit/tests/rest-api/wpRestTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,52 @@ public function test_create_item() {
);
}

/**
* @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
Expand Down
12 changes: 6 additions & 6 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -5035,7 +5035,7 @@ mockedApiResponse.Schema = {
"description": "Unique slug identifying the template.",
"type": "string",
"minLength": 1,
"pattern": "[a-zA-Z_\\-]+",
"pattern": "[a-zA-Z0-9_\\-]+",
"required": true
},
"theme": {
Expand Down Expand Up @@ -5189,7 +5189,7 @@ mockedApiResponse.Schema = {
"description": "Unique slug identifying the template.",
"type": "string",
"minLength": 1,
"pattern": "[a-zA-Z_\\-]+",
"pattern": "[a-zA-Z0-9_\\-]+",
"required": false
},
"theme": {
Expand Down Expand Up @@ -5503,7 +5503,7 @@ mockedApiResponse.Schema = {
"description": "Unique slug identifying the template.",
"type": "string",
"minLength": 1,
"pattern": "[a-zA-Z_\\-]+",
"pattern": "[a-zA-Z0-9_\\-]+",
"required": false
},
"theme": {
Expand Down Expand Up @@ -5682,7 +5682,7 @@ mockedApiResponse.Schema = {
"description": "Unique slug identifying the template.",
"type": "string",
"minLength": 1,
"pattern": "[a-zA-Z_\\-]+",
"pattern": "[a-zA-Z0-9_\\-]+",
"required": true
},
"theme": {
Expand Down Expand Up @@ -5841,7 +5841,7 @@ mockedApiResponse.Schema = {
"description": "Unique slug identifying the template.",
"type": "string",
"minLength": 1,
"pattern": "[a-zA-Z_\\-]+",
"pattern": "[a-zA-Z0-9_\\-]+",
"required": false
},
"theme": {
Expand Down Expand Up @@ -6160,7 +6160,7 @@ mockedApiResponse.Schema = {
"description": "Unique slug identifying the template.",
"type": "string",
"minLength": 1,
"pattern": "[a-zA-Z_\\-]+",
"pattern": "[a-zA-Z0-9_\\-]+",
"required": false
},
"theme": {
Expand Down