Skip to content
Closed
Prev Previous commit
Next Next commit
Add unit test
  • Loading branch information
ribaricplusplus committed Jan 10, 2023
commit d40d2985dc288ded955affe29233e567704b8f82
43 changes: 28 additions & 15 deletions phpunit/class-gutenberg-rest-global-styles-controller-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ private function find_and_normalize_global_styles_by_id( $global_styles, $id ) {

public function set_up() {
parent::set_up();
switch_theme( 'emptytheme' );
}

/**
Expand All @@ -38,20 +37,11 @@ public static function wpSetupBeforeClass( $factory ) {
'role' => 'administrator',
)
);

switch_theme( 'emptytheme' );

// This creates the global styles for the current theme.
self::$global_styles_id = wp_insert_post(
array(
'post_content' => '{"version": ' . WP_Theme_JSON_Gutenberg::LATEST_SCHEMA . ', "isGlobalStylesUserThemeJSON": true }',
'post_status' => 'publish',
'post_title' => __( 'Custom Styles', 'default' ),
'post_type' => 'wp_global_styles',
'post_name' => 'wp-global-styles-emptytheme',
'tax_input' => array(
'wp_theme' => 'emptytheme',
),
),
true
);
self::$global_styles_id = WP_Theme_JSON_Resolver_Gutenberg::get_user_global_styles_post_id();
}


Expand Down Expand Up @@ -143,7 +133,30 @@ public function test_get_item() {
}

public function test_create_item() {
$this->markTestIncomplete();
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/global-styles' );
$request->set_body_params(
array(
'title' => 'Custom user variation',
'settings' => new stdClass(),
'styles' => new stdClass(),
)
);
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
unset( $data['_links'] );

$this->assertEquals(
array(
'title' => array(
'raw' => 'Custom user variation',
'rendered' => 'Custom user variation',
),
),
array(
'title' => $data['title'],
)
);
}

public function test_update_item() {
Expand Down