Skip to content

Commit

Permalink
added a test for the revisions endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Dec 23, 2022
1 parent 82badb4 commit 3c8fb4d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions phpunit/class-gutenberg-rest-global-styles-controller-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,49 @@ public function test_get_item() {
);
}

public function test_get_item_revisions() {
wp_set_current_user( self::$admin_id );
// Update post to create a new revision.
$config = array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'isGlobalStylesUserThemeJSON' => true,
'styles' => array(
'color' => array(
'background' => 'hotpink',
),
),
);
$new_styles_post = array(
'ID' => self::$global_styles_id,
'post_content' => wp_json_encode( $config ),
);

wp_update_post( $new_styles_post, true, false );

$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();

$this->assertCount( 1, $data, 'Check that only one revision exists' );
$this->assertArrayHasKey( 'id', $data[0], 'Check that an id key exists' );
$this->assertArrayHasKey( 'raw', $data[0]['title'], 'Check that a raw title key exists' );
$this->assertArrayHasKey( 'rendered', $data[0]['title'], 'Check that a rendered title key exists' );
$this->assertEquals(
$data[0]['settings'],
new stdClass(),
'Check that the revision settings exist in the response.'
);
$this->assertEquals(
$data[0]['styles'],
array(
'color' => array(
'background' => 'hotpink',
),
),
'Check that the revision styles match the last updated styles.'
);
}

public function test_create_item() {
$this->markTestIncomplete();
}
Expand Down

0 comments on commit 3c8fb4d

Please sign in to comment.