mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Editor: Add original_source and author_text to the templates REST API.
For the new "All templates" UI to work properly we need the REST API to provide to additional fields original_source, and author_text. Props ntsekouras, get_dave. Fixes #60358. git-svn-id: https://develop.svn.wordpress.org/trunk@57366 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -310,7 +310,7 @@ class Tests_REST_wpRestTemplateAutosavesController extends WP_Test_REST_Controll
|
||||
|
||||
$properties = $data['schema']['properties'];
|
||||
|
||||
$this->assertCount( 16, $properties );
|
||||
$this->assertCount( 18, $properties );
|
||||
$this->assertArrayHasKey( 'id', $properties, 'ID key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'slug', $properties, 'Slug key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'theme', $properties, 'Theme key should exist in properties.' );
|
||||
@@ -326,6 +326,8 @@ class Tests_REST_wpRestTemplateAutosavesController extends WP_Test_REST_Controll
|
||||
$this->assertArrayHasKey( 'modified', $properties, 'modified key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'is_custom', $properties, 'is_custom key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'parent', $properties, 'Parent key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'author_text', $properties, 'Parent key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'original_source', $properties, 'Parent key should exist in properties.' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -449,7 +449,7 @@ class Tests_REST_wpRestTemplateRevisionsController extends WP_Test_REST_Controll
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
|
||||
$this->assertCount( 16, $properties );
|
||||
$this->assertCount( 18, $properties );
|
||||
$this->assertArrayHasKey( 'id', $properties, 'ID key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'slug', $properties, 'Slug key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'theme', $properties, 'Theme key should exist in properties.' );
|
||||
@@ -465,6 +465,8 @@ class Tests_REST_wpRestTemplateRevisionsController extends WP_Test_REST_Controll
|
||||
$this->assertArrayHasKey( 'modified', $properties, 'modified key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'is_custom', $properties, 'is_custom key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'parent', $properties, 'Parent key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'author_text', $properties, 'Parent key should exist in properties.' );
|
||||
$this->assertArrayHasKey( 'original_source', $properties, 'Parent key should exist in properties.' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -102,23 +102,25 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'id' => 'default//my_template',
|
||||
'theme' => 'default',
|
||||
'slug' => 'my_template',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Description of my template.',
|
||||
'title' => array(
|
||||
'id' => 'default//my_template',
|
||||
'theme' => 'default',
|
||||
'slug' => 'my_template',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Description of my template.',
|
||||
'title' => array(
|
||||
'raw' => 'My Template',
|
||||
'rendered' => 'My Template',
|
||||
),
|
||||
'status' => 'publish',
|
||||
'wp_id' => self::$post->ID,
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => 0,
|
||||
'modified' => mysql_to_rfc3339( self::$post->post_modified ),
|
||||
'status' => 'publish',
|
||||
'wp_id' => self::$post->ID,
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => 0,
|
||||
'modified' => mysql_to_rfc3339( self::$post->post_modified ),
|
||||
'author_text' => 'Test Blog',
|
||||
'original_source' => 'site',
|
||||
),
|
||||
$this->find_and_normalize_template_by_id( $data, 'default//my_template' )
|
||||
);
|
||||
@@ -147,23 +149,25 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'id' => 'default//my_template',
|
||||
'theme' => 'default',
|
||||
'slug' => 'my_template',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Description of my template.',
|
||||
'title' => array(
|
||||
'id' => 'default//my_template',
|
||||
'theme' => 'default',
|
||||
'slug' => 'my_template',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Description of my template.',
|
||||
'title' => array(
|
||||
'raw' => 'My Template',
|
||||
'rendered' => 'My Template',
|
||||
),
|
||||
'status' => 'publish',
|
||||
'wp_id' => self::$post->ID,
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => 0,
|
||||
'modified' => mysql_to_rfc3339( self::$post->post_modified ),
|
||||
'status' => 'publish',
|
||||
'wp_id' => self::$post->ID,
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => 0,
|
||||
'modified' => mysql_to_rfc3339( self::$post->post_modified ),
|
||||
'author_text' => 'Test Blog',
|
||||
'original_source' => 'site',
|
||||
),
|
||||
$data
|
||||
);
|
||||
@@ -184,23 +188,25 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'id' => 'default//my_template',
|
||||
'theme' => 'default',
|
||||
'slug' => 'my_template',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Description of my template.',
|
||||
'title' => array(
|
||||
'id' => 'default//my_template',
|
||||
'theme' => 'default',
|
||||
'slug' => 'my_template',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Description of my template.',
|
||||
'title' => array(
|
||||
'raw' => 'My Template',
|
||||
'rendered' => 'My Template',
|
||||
),
|
||||
'status' => 'publish',
|
||||
'wp_id' => self::$post->ID,
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => 0,
|
||||
'modified' => mysql_to_rfc3339( self::$post->post_modified ),
|
||||
'status' => 'publish',
|
||||
'wp_id' => self::$post->ID,
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => 0,
|
||||
'modified' => mysql_to_rfc3339( self::$post->post_modified ),
|
||||
'author_text' => 'Test Blog',
|
||||
'original_source' => 'site',
|
||||
),
|
||||
$data
|
||||
);
|
||||
@@ -241,26 +247,29 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
$data = $response->get_data();
|
||||
unset( $data['content'] );
|
||||
unset( $data['_links'] );
|
||||
$author_name = get_user_by( 'id', self::$admin_id )->get( 'display_name' );
|
||||
|
||||
$this->assertSameSetsWithIndex(
|
||||
array(
|
||||
'id' => "{$theme_dir}//{$template}",
|
||||
'theme' => $theme_dir,
|
||||
'slug' => $template,
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => $args['post_excerpt'],
|
||||
'title' => array(
|
||||
'id' => "{$theme_dir}//{$template}",
|
||||
'theme' => $theme_dir,
|
||||
'slug' => $template,
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => $args['post_excerpt'],
|
||||
'title' => array(
|
||||
'raw' => $args['post_title'],
|
||||
'rendered' => $args['post_title'],
|
||||
),
|
||||
'status' => 'publish',
|
||||
'wp_id' => $post->ID,
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => self::$admin_id,
|
||||
'modified' => mysql_to_rfc3339( $post->post_modified ),
|
||||
'status' => 'publish',
|
||||
'wp_id' => $post->ID,
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => self::$admin_id,
|
||||
'modified' => mysql_to_rfc3339( $post->post_modified ),
|
||||
'author_text' => $author_name,
|
||||
'original_source' => 'user',
|
||||
),
|
||||
$data
|
||||
);
|
||||
@@ -421,27 +430,31 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
unset( $data['_links'] );
|
||||
unset( $data['wp_id'] );
|
||||
|
||||
$author_name = get_user_by( 'id', self::$admin_id )->get( 'display_name' );
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'id' => 'default//my_custom_template',
|
||||
'theme' => 'default',
|
||||
'content' => array(
|
||||
'id' => 'default//my_custom_template',
|
||||
'theme' => 'default',
|
||||
'content' => array(
|
||||
'raw' => 'Content',
|
||||
),
|
||||
'slug' => 'my_custom_template',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Just a description',
|
||||
'title' => array(
|
||||
'slug' => 'my_custom_template',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Just a description',
|
||||
'title' => array(
|
||||
'raw' => 'My Template',
|
||||
'rendered' => 'My Template',
|
||||
),
|
||||
'status' => 'publish',
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => self::$admin_id,
|
||||
'modified' => mysql_to_rfc3339( $modified ),
|
||||
'status' => 'publish',
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => self::$admin_id,
|
||||
'modified' => mysql_to_rfc3339( $modified ),
|
||||
'author_text' => $author_name,
|
||||
'original_source' => 'user',
|
||||
),
|
||||
$data
|
||||
);
|
||||
@@ -469,27 +482,31 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
unset( $data['_links'] );
|
||||
unset( $data['wp_id'] );
|
||||
|
||||
$author_name = get_user_by( 'id', self::$admin_id )->get( 'display_name' );
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'id' => 'default//404',
|
||||
'theme' => 'default',
|
||||
'content' => 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(
|
||||
'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,
|
||||
'modified' => mysql_to_rfc3339( $modified ),
|
||||
'status' => 'publish',
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => false,
|
||||
'author' => self::$admin_id,
|
||||
'modified' => mysql_to_rfc3339( $modified ),
|
||||
'author_text' => $author_name,
|
||||
'original_source' => 'user',
|
||||
),
|
||||
$data
|
||||
);
|
||||
@@ -521,27 +538,31 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
unset( $data['_links'] );
|
||||
unset( $data['wp_id'] );
|
||||
|
||||
$author_name = get_user_by( 'id', self::$admin_id )->get( 'display_name' );
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'id' => 'default//my_custom_template_raw',
|
||||
'theme' => 'default',
|
||||
'content' => array(
|
||||
'id' => 'default//my_custom_template_raw',
|
||||
'theme' => 'default',
|
||||
'content' => array(
|
||||
'raw' => 'Content',
|
||||
),
|
||||
'slug' => 'my_custom_template_raw',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Just a description',
|
||||
'title' => array(
|
||||
'slug' => 'my_custom_template_raw',
|
||||
'source' => 'custom',
|
||||
'origin' => null,
|
||||
'type' => 'wp_template',
|
||||
'description' => 'Just a description',
|
||||
'title' => array(
|
||||
'raw' => 'My Template',
|
||||
'rendered' => 'My Template',
|
||||
),
|
||||
'status' => 'publish',
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => self::$admin_id,
|
||||
'modified' => mysql_to_rfc3339( $modified ),
|
||||
'status' => 'publish',
|
||||
'has_theme_file' => false,
|
||||
'is_custom' => true,
|
||||
'author' => self::$admin_id,
|
||||
'modified' => mysql_to_rfc3339( $modified ),
|
||||
'author_text' => $author_name,
|
||||
'original_source' => 'user',
|
||||
),
|
||||
$data
|
||||
);
|
||||
@@ -700,7 +721,7 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
$this->assertCount( 15, $properties );
|
||||
$this->assertCount( 17, $properties );
|
||||
$this->assertArrayHasKey( 'id', $properties );
|
||||
$this->assertArrayHasKey( 'description', $properties );
|
||||
$this->assertArrayHasKey( 'slug', $properties );
|
||||
@@ -717,6 +738,8 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
$this->assertArrayHasKey( 'is_custom', $properties );
|
||||
$this->assertArrayHasKey( 'author', $properties );
|
||||
$this->assertArrayHasKey( 'modified', $properties );
|
||||
$this->assertArrayHasKey( 'author_text', $properties );
|
||||
$this->assertArrayHasKey( 'original_source', $properties );
|
||||
}
|
||||
|
||||
protected function find_and_normalize_template_by_id( $templates, $id ) {
|
||||
@@ -747,10 +770,13 @@ class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testc
|
||||
|
||||
$request = new WP_REST_Request( 'POST', '/wp/v2/templates' );
|
||||
$request->set_body_params( $body_params );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$modified = get_post( $data['wp_id'] )->post_modified;
|
||||
$expected['modified'] = mysql_to_rfc3339( $modified );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$modified = get_post( $data['wp_id'] )->post_modified;
|
||||
$expected['modified'] = mysql_to_rfc3339( $modified );
|
||||
$expected['author_text'] = get_user_by( 'id', self::$admin_id )->get( 'display_name' );
|
||||
$expected['original_source'] = 'user';
|
||||
|
||||
unset( $data['_links'] );
|
||||
unset( $data['wp_id'] );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user