Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8f87db5
Add support to post types
talldan Nov 24, 2021
77a5e68
Add author support to templates REST API controller
talldan Nov 24, 2021
bdb04b3
Update unit tests
talldan Nov 24, 2021
0095e94
Fix linting issue
talldan Nov 25, 2021
39e5f91
Add origin field to templates
talldan Nov 25, 2021
11e1a10
Handle errors from `prepare_item_for_database` in REST templates cont…
talldan Nov 25, 2021
8888852
Update tests to support origin
talldan Nov 25, 2021
63d008a
Address review feedback
talldan Nov 25, 2021
51c768e
Linting fix
talldan Nov 25, 2021
89ea62c
Remove empty lines
talldan Nov 29, 2021
0b939f4
Update @wordpress packages
noisysocks Nov 29, 2021
36bbe07
Changes from lib/class-wp-theme-json-gutenberg.php
noisysocks Nov 29, 2021
2f870e0
Changes from lib/class-wp-theme-json-resolver-gutenberg.php
noisysocks Nov 29, 2021
b494b8e
Changes from lib/class-gutenberg-rest-global-styles-controller.php
noisysocks Nov 29, 2021
ac24a4d
Changes from lib/compat/wordpress-5.9/class-gutenberg-rest-templates-…
noisysocks Nov 29, 2021
c693450
Changes from lib/compat/wordpress-5.9/get-global-styles-and-settings.php
noisysocks Nov 29, 2021
2f4b9c0
Changes from lib/compat/wordpress-5.9/rest-active-global-styles.php
noisysocks Nov 29, 2021
a40c236
Changes from lib/full-site-editing/edit-site-page.php
noisysocks Nov 29, 2021
8177764
Changes from lib/global-styles.php
noisysocks Nov 29, 2021
d7bc3a2
Changes from phpunit/class-gutenberg-rest-template-controller-test.php
noisysocks Nov 29, 2021
0f23bca
Changes from phpunit/class-wp-theme-json-resolver-test.php
noisysocks Nov 29, 2021
7771284
Changes from phpunit/class-wp-theme-json-test.php
noisysocks Nov 29, 2021
c0cc27a
Merge remote-tracking branch 'talldan/add/author-support-to-templates…
noisysocks Nov 29, 2021
f8745dc
Move call to maybe_opt_in_into_settings() to right place
noisysocks Nov 29, 2021
fa3f5c7
Use WP class names
noisysocks Nov 29, 2021
9a4ec9f
Fix 'is_custom' assertions in PHPUnit tests
Mamaduka Nov 29, 2021
df9d23f
Update tests/phpunit/tests/rest-api/wpRestTemplatesController.php
noisysocks Nov 29, 2021
cdabd26
Update tests/phpunit/tests/rest-api/wpRestTemplatesController.php
noisysocks Nov 29, 2021
bd3461a
Update tests/phpunit/tests/rest-api/wpRestTemplatesController.php
noisysocks Nov 29, 2021
00ba632
Sort keys alphabetically so it is easier to compare
oandregal Nov 29, 2021
a633c19
Add missing appearanceTools flag
oandregal Nov 29, 2021
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
Prev Previous commit
Next Next commit
Update unit tests
  • Loading branch information
talldan committed Nov 24, 2021
commit bdb04b39d7a8b5d56b879d404be2de2d63e94f86
25 changes: 24 additions & 1 deletion tests/phpunit/tests/rest-api/wpRestTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function test_get_items() {
'status' => 'publish',
'wp_id' => self::$post->ID,
'has_theme_file' => false,
'author' => 0,
),
$this->find_and_normalize_template_by_id( $data, 'default//my_template' )
);
Expand Down Expand Up @@ -143,6 +144,7 @@ public function test_get_item() {
'status' => 'publish',
'wp_id' => self::$post->ID,
'has_theme_file' => false,
'author' => 0,
),
$data
);
Expand All @@ -161,6 +163,7 @@ public function test_create_item() {
'description' => 'Just a description',
'title' => 'My Template',
'content' => 'Content',
'author' => self::$admin_id,
)
);
$response = rest_get_server()->dispatch( $request );
Expand All @@ -185,6 +188,7 @@ public function test_create_item() {
),
'status' => 'publish',
'has_theme_file' => false,
'author' => self::$admin_id,
),
$data
);
Expand All @@ -207,6 +211,7 @@ public function test_create_item_raw() {
'content' => array(
'raw' => 'Content',
),
'author' => self::$admin_id,
)
);
$response = rest_get_server()->dispatch( $request );
Expand All @@ -231,11 +236,28 @@ public function test_create_item_raw() {
),
'status' => 'publish',
'has_theme_file' => false,
'author' => self::$admin_id,
),
$data
);
}

public function test_create_item_invalid_author() {
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/templates' );
$request->set_body_params(
array(
'slug' => 'my_custom_template_invalid_author',
'description' => 'Just a description',
'title' => 'My Template',
'content' => 'Content',
'author' => -999,
)
);
$response = rest_get_server()->dispatch( $request );
$this->assertErrorResponse( 'rest_invalid_author', $response, 400 );
}

/**
* @covers WP_REST_Templates_Controller::update_item
*/
Expand Down Expand Up @@ -370,7 +392,7 @@ public function test_get_item_schema() {
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$properties = $data['schema']['properties'];
$this->assertCount( 11, $properties );
$this->assertCount( 12, $properties );
$this->assertArrayHasKey( 'id', $properties );
$this->assertArrayHasKey( 'description', $properties );
$this->assertArrayHasKey( 'slug', $properties );
Expand All @@ -383,6 +405,7 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'status', $properties );
$this->assertArrayHasKey( 'wp_id', $properties );
$this->assertArrayHasKey( 'has_theme_file', $properties );
$this->assertArrayHasKey( 'author', $properties );
}

protected function find_and_normalize_template_by_id( $templates, $id ) {
Expand Down
30 changes: 30 additions & 0 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -5117,6 +5117,11 @@ mockedApiResponse.Schema = {
"private"
],
"required": false
},
"author": {
"description": "The ID for the author of the template.",
"type": "integer",
"required": false
}
}
}
Expand Down Expand Up @@ -5262,6 +5267,11 @@ mockedApiResponse.Schema = {
"private"
],
"required": false
},
"author": {
"description": "The ID for the author of the template.",
"type": "integer",
"required": false
}
}
},
Expand Down Expand Up @@ -5571,6 +5581,11 @@ mockedApiResponse.Schema = {
"private"
],
"required": false
},
"author": {
"description": "The ID for the author of the template.",
"type": "integer",
"required": false
}
}
}
Expand Down Expand Up @@ -5750,6 +5765,11 @@ mockedApiResponse.Schema = {
],
"required": false
},
"author": {
"description": "The ID for the author of the template.",
"type": "integer",
"required": false
},
"area": {
"description": "Where the template part is intended for use (header, footer, etc.)",
"type": "string",
Expand Down Expand Up @@ -5900,6 +5920,11 @@ mockedApiResponse.Schema = {
],
"required": false
},
"author": {
"description": "The ID for the author of the template.",
"type": "integer",
"required": false
},
"area": {
"description": "Where the template part is intended for use (header, footer, etc.)",
"type": "string",
Expand Down Expand Up @@ -6214,6 +6239,11 @@ mockedApiResponse.Schema = {
],
"required": false
},
"author": {
"description": "The ID for the author of the template.",
"type": "integer",
"required": false
},
"area": {
"description": "Where the template part is intended for use (header, footer, etc.)",
"type": "string",
Expand Down