Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Apr 24, 2023
1 parent 2ff2a86 commit bee3b61
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function register_routes() {
array(
'args' => array(
'parent' => array(
'description' => __( 'The ID for the parent of the revision.' ),
'description' => __( 'The ID for the parent of the revision.', 'gutenberg' ),
'type' => 'integer',
),
),
Expand Down Expand Up @@ -219,71 +219,71 @@ public function get_item_schema() {
* Leaves out GUID as global styles shouldn't be accessible via URL.
*/
'author' => array(
'description' => __( 'The ID for the author of the revision.' ),
'description' => __( 'The ID for the author of the revision.', 'gutenberg' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'embed' ),
),
'date' => array(
'description' => __( "The date the revision was published, in the site's timezone." ),
'description' => __( "The date the revision was published, in the site's timezone.", 'gutenberg' ),
'type' => 'string',
'format' => 'date-time',
'context' => array( 'view', 'edit', 'embed' ),
),
'date_gmt' => array(
'description' => __( 'The date the revision was published, as GMT.' ),
'description' => __( 'The date the revision was published, as GMT.', 'gutenberg' ),
'type' => 'string',
'format' => 'date-time',
'context' => array( 'view', 'edit' ),
),
'id' => array(
'description' => __( 'Unique identifier for the revision.' ),
'description' => __( 'Unique identifier for the revision.', 'gutenberg' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'embed' ),
),
'modified' => array(
'description' => __( "The date the revision was last modified, in the site's timezone." ),
'description' => __( "The date the revision was last modified, in the site's timezone.", 'gutenberg' ),
'type' => 'string',
'format' => 'date-time',
'context' => array( 'view', 'edit' ),
),
'modified_gmt' => array(
'description' => __( 'The date the revision was last modified, as GMT.' ),
'description' => __( 'The date the revision was last modified, as GMT.', 'gutenberg' ),
'type' => 'string',
'format' => 'date-time',
'context' => array( 'view', 'edit' ),
),
'parent' => array(
'description' => __( 'The ID for the parent of the revision.' ),
'description' => __( 'The ID for the parent of the revision.', 'gutenberg' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'embed' ),
),

// Adds custom global styles revisions schema.
'author_display_name' => array(
'description' => __( 'The display name of the author.' ),
'description' => __( 'The display name of the author.', 'gutenberg' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),

'author_avatar_url' => array(
'description' => __( 'A URL to the avatar image of the author' ),
'description' => __( 'A URL to the avatar image of the author', 'gutenberg' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),

'date_display' => array(
'description' => __( 'A human-friendly rendering of the date' ),
'description' => __( 'A human-friendly rendering of the date', 'gutenberg' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
// Adds settings and styles from the WP_REST_Global_Styles_Controller parent schema.
'styles' => array(
'description' => __( 'Global styles.' ),
'description' => __( 'Global styles.', 'gutenberg' ),
'type' => array( 'object' ),
'context' => array( 'view', 'edit' ),
),
'settings' => array(
'description' => __( 'Global settings.' ),
'description' => __( 'Global settings.', 'gutenberg' ),
'type' => array( 'object' ),
'context' => array( 'view', 'edit' ),
),
Expand Down Expand Up @@ -312,7 +312,7 @@ public function get_item_permissions_check( $request ) {
if ( ! current_user_can( 'read_post', $post->ID ) ) {
return new WP_Error(
'rest_cannot_view',
__( 'Sorry, you are not allowed to view revisions for this global style.' ),
__( 'Sorry, you are not allowed to view revisions for this global style.', 'gutenberg' ),
array( 'status' => rest_authorization_required_code() )
);
}
Expand All @@ -331,7 +331,7 @@ public function get_item_permissions_check( $request ) {
protected function get_parent( $parent_post_id ) {
$error = new WP_Error(
'rest_post_invalid_parent',
__( 'Invalid post parent ID.' ),
__( 'Invalid post parent ID.', 'gutenberg' ),
array( 'status' => 404 )
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static function wpSetupBeforeClass( $factory ) {
);
}

/**
* @covers Gutenberg_REST_Global_Styles_Revisions_Controller::register_routes
*/
public function test_register_routes() {
$routes = rest_get_server()->get_routes();
$this->assertArrayHasKey(
Expand All @@ -53,6 +56,9 @@ public function test_register_routes() {
);
}

/**
* @covers Gutenberg_REST_Global_Styles_Revisions_Controller::get_items
*/
public function test_get_items() {
wp_set_current_user( self::$admin_id );
// Update post to create a new revision.
Expand Down Expand Up @@ -80,7 +86,6 @@ public function test_get_items() {
$this->assertArrayHasKey( 'id', $data[0], 'Check that an id key exists' );
$this->assertEquals( self::$global_styles_id, $data[0]['parent'], 'Check that an id for the parent exists' );


// Dates.
$this->assertArrayHasKey( 'date', $data[0], 'Check that an date key exists' );
$this->assertArrayHasKey( 'date_gmt', $data[0], 'Check that an date_gmt key exists' );
Expand Down Expand Up @@ -114,6 +119,29 @@ public function test_get_items() {
);
}

/**
* @covers Gutenberg_REST_Global_Styles_Revisions_Controller::get_item_schema
*/
public function test_get_item_schema() {
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$properties = $data['schema']['properties'];
$this->assertCount( 12, $properties, 'Schema properties array does not have exactly 4 elements' );
$this->assertArrayHasKey( 'id', $properties, 'Schema properties array does not have "id" key' );
$this->assertArrayHasKey( 'styles', $properties, 'Schema properties array does not have "styles" key' );
$this->assertArrayHasKey( 'settings', $properties, 'Schema properties array does not have "settings" key' );
$this->assertArrayHasKey( 'parent', $properties, 'Schema properties array does not have "parent" key' );
$this->assertArrayHasKey( 'author', $properties, 'Schema properties array does not have "author" key' );
$this->assertArrayHasKey( 'author_display_name', $properties, 'Schema properties array does not have "author_display_name" key' );
$this->assertArrayHasKey( 'author_avatar_url', $properties, 'Schema properties array does not have "author_avatar_url" key' );
$this->assertArrayHasKey( 'date', $properties, 'Schema properties array does not have "date" key' );
$this->assertArrayHasKey( 'date_gmt', $properties, 'Schema properties array does not have "date_gmt" key' );
$this->assertArrayHasKey( 'date_display', $properties, 'Schema properties array does not have "date_display" key' );
$this->assertArrayHasKey( 'modified', $properties, 'Schema properties array does not have "modified" key' );
$this->assertArrayHasKey( 'modified_gmt', $properties, 'Schema properties array does not have "modified_gmt" key' );
}

/**
* @doesNotPerformAssertions
*/
Expand Down Expand Up @@ -152,7 +180,7 @@ public function test_prepare_item() {
/**
* @doesNotPerformAssertions
*/
public function test_get_item_schema() {
// Covered by the core.
public function test_update_item() {
// Controller does not implement update_item().
}
}

0 comments on commit bee3b61

Please sign in to comment.