Skip to content
Open
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 @@ -1106,7 +1106,7 @@ public function get_item_schema() {
),
'origin' => array(
'description' => __( 'Source of a customized template' ),
'type' => 'string',
'type' => array( 'string', 'null' ),
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/tests/rest-api/wpRestTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,38 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'plugin', $properties );
}

/**
* @ticket 64168
* @covers WP_REST_Templates_Controller::get_item_schema
*/
public function test_get_item_schema_origin_allows_null() {
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/templates' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$properties = $data['schema']['properties'];

$this->assertArrayHasKey( 'origin', $properties );
$this->assertSame(
array( 'string', 'null' ),
$properties['origin']['type'],
'The origin property type should allow string and null.'
);
}


/**
* @ticket 64168
* @covers WP_REST_Templates_Controller::prepare_item_for_response
*/
public function test_get_item_with_theme_template_returns_null_origin() {
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'GET', '/wp/v2/templates/default//my_template' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();

$this->assertNull( $data['origin'], 'Theme template origin should be null.' );
}

protected function find_and_normalize_template_by_id( $templates, $id ) {
foreach ( $templates as $template ) {
if ( $template['id'] === $id ) {
Expand Down
Loading