diff --git a/tests/phpunit/tests/rest-api/rest-post-types-controller.php b/tests/phpunit/tests/rest-api/rest-post-types-controller.php index 447e317b7eec9..982fb4e04a23d 100644 --- a/tests/phpunit/tests/rest-api/rest-post-types-controller.php +++ b/tests/phpunit/tests/rest-api/rest-post-types-controller.php @@ -156,25 +156,31 @@ public function test_prepare_item_limit_fields() { ); } + /** + * @ticket 56467 + * + * @covers WP_REST_Post_Types_Controller::get_item_schema + */ public function test_get_item_schema() { $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/types' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertCount( 13, $properties ); - $this->assertArrayHasKey( 'capabilities', $properties, '`capabilities` should be included in the schema.' ); - $this->assertArrayHasKey( 'description', $properties, '`description` should be included in the schema.' ); - $this->assertArrayHasKey( 'hierarchical', $properties, '`hierarchical` should be included in the schema.' ); - $this->assertArrayHasKey( 'viewable', $properties, '`viewable` should be included in the schema.' ); - $this->assertArrayHasKey( 'labels', $properties, '`labels` should be included in the schema.' ); - $this->assertArrayHasKey( 'name', $properties, '`name` should be included in the schema.' ); - $this->assertArrayHasKey( 'slug', $properties, '`slug` should be included in the schema.' ); - $this->assertArrayHasKey( 'supports', $properties, '`supports` should be included in the schema.' ); - $this->assertArrayHasKey( 'taxonomies', $properties, '`taxonomies` should be included in the schema.' ); - $this->assertArrayHasKey( 'rest_base', $properties, '`rest_base` should be included in the schema.' ); - $this->assertArrayHasKey( 'rest_namespace', $properties, '`rest_namespace` should be included in the schema.' ); - $this->assertArrayHasKey( 'visibility', $properties, '`visibility` should be included in the schema.' ); - $this->assertArrayHasKey( 'icon', $properties, '`icon` should be included in the schema.' ); + + $this->assertCount( 13, $properties, 'Schema should have 13 properties' ); + $this->assertArrayHasKey( 'capabilities', $properties, '`capabilities` should be included in the schema' ); + $this->assertArrayHasKey( 'description', $properties, '`description` should be included in the schema' ); + $this->assertArrayHasKey( 'hierarchical', $properties, '`hierarchical` should be included in the schema' ); + $this->assertArrayHasKey( 'viewable', $properties, '`viewable` should be included in the schema' ); + $this->assertArrayHasKey( 'labels', $properties, '`labels` should be included in the schema' ); + $this->assertArrayHasKey( 'name', $properties, '`name` should be included in the schema' ); + $this->assertArrayHasKey( 'slug', $properties, '`slug` should be included in the schema' ); + $this->assertArrayHasKey( 'supports', $properties, '`supports` should be included in the schema' ); + $this->assertArrayHasKey( 'taxonomies', $properties, '`taxonomies` should be included in the schema' ); + $this->assertArrayHasKey( 'rest_base', $properties, '`rest_base` should be included in the schema' ); + $this->assertArrayHasKey( 'rest_namespace', $properties, '`rest_namespace` should be included in the schema' ); + $this->assertArrayHasKey( 'visibility', $properties, '`visibility` should be included in the schema' ); + $this->assertArrayHasKey( 'icon', $properties, '`icon` should be included in the schema' ); } public function test_get_additional_field_registration() { diff --git a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php index b66668b57c89e..0ddd023c012f2 100644 --- a/tests/phpunit/tests/rest-api/wpRestTemplatesController.php +++ b/tests/phpunit/tests/rest-api/wpRestTemplatesController.php @@ -685,26 +685,35 @@ protected function find_and_normalize_template_by_id( $templates, $id ) { } /** + * @dataProvider data_create_item_with_is_wp_suggestion * @ticket 56467 * @covers WP_REST_Templates_Controller::create_item + * + * @param array $body_params Data set to test. + * @param array $expected Expected results. */ - public function test_create_item_with_is_wp_suggestion() { + public function test_create_item_with_is_wp_suggestion( array $body_params, array $expected ) { + // Set up the user. + $body_params['author'] = self::$admin_id; + $expected['author'] = self::$admin_id; wp_set_current_user( self::$admin_id ); + $request = new WP_REST_Request( 'POST', '/wp/v2/templates' ); - // `is_wp_suggestion` true. - $body_params = array( - 'slug' => 'page-rigas', - 'description' => 'Just a description', - 'title' => 'My Template', - 'content' => 'Content', - 'is_wp_suggestion' => true, - 'author' => self::$admin_id, - ); $request->set_body_params( $body_params ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); unset( $data['_links'] ); unset( $data['wp_id'] ); + + $this->assertSame( $expected, $data ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_create_item_with_is_wp_suggestion() { $expected = array( 'id' => 'default//page-rigas', 'theme' => 'default', @@ -723,31 +732,40 @@ public function test_create_item_with_is_wp_suggestion() { 'status' => 'publish', 'has_theme_file' => false, 'is_custom' => false, - 'author' => self::$admin_id, + 'author' => null, ); - $this->assertSame( $expected, $data, 'Incorrect response when `is_wp_suggestion:true` is set.' ); - // `is_wp_suggestion` false. - $body_params = wp_parse_args( - array( - 'slug' => 'page-hi', - 'is_wp_suggestion' => false, + + return array( + 'is_wp_suggestion: true' => array( + 'body_params' => array( + 'slug' => 'page-rigas', + 'description' => 'Just a description', + 'title' => 'My Template', + 'content' => 'Content', + 'is_wp_suggestion' => true, + 'author' => null, + ), + 'expected' => $expected, ), - $body_params - ); - $request->set_body_params( $body_params ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - unset( $data['_links'] ); - unset( $data['wp_id'] ); - $expected = wp_parse_args( - array( - 'id' => 'default//page-hi', - 'slug' => 'page-hi', - 'is_custom' => true, + 'is_wp_suggestion: false' => array( + 'body_params' => array( + 'slug' => 'page-hi', + 'description' => 'Just a description', + 'title' => 'My Template', + 'content' => 'Content', + 'is_wp_suggestion' => false, + 'author' => null, + ), + 'expected' => array_merge( + $expected, + array( + 'id' => 'default//page-hi', + 'slug' => 'page-hi', + 'is_custom' => true, + ) + ), ), - $expected ); - $this->assertSame( $expected, $data, 'Incorrect response when `is_wp_suggestion:false` is set.' ); } /**