diff --git a/tests/phpunit/tests/rest-api/rest-global-styles-controller.php b/tests/phpunit/tests/rest-api/rest-global-styles-controller.php index 02d3ec8d5a72c..8e80aa2dfaf33 100644 --- a/tests/phpunit/tests/rest-api/rest-global-styles-controller.php +++ b/tests/phpunit/tests/rest-api/rest-global-styles-controller.php @@ -602,6 +602,55 @@ public function test_update_item_invalid_styles_css() { $this->assertErrorResponse( 'rest_custom_css_illegal_markup', $response, 400 ); } + /** + * Tests the submission of a custom block style variation that was defined + * within a theme style variation and wouldn't be registered at the time + * of saving via the API. + * + * @covers WP_REST_Global_Styles_Controller_Gutenberg::update_item + * @ticket 61312 + */ + public function test_update_item_with_custom_block_style_variations() { + wp_set_current_user( self::$admin_id ); + if ( is_multisite() ) { + grant_super_admin( self::$admin_id ); + } + + $group_variations = array( + 'fromThemeStyleVariation' => array( + 'color' => array( + 'background' => '#ffffff', + 'text' => '#000000', + ), + ), + ); + + $request = new WP_REST_Request( 'PUT', '/wp/v2/global-styles/' . self::$global_styles_id ); + $request->set_body_params( + array( + 'styles' => array( + 'blocks' => array( + 'variations' => array( + 'fromThemeStyleVariation' => array( + 'blockTypes' => array( 'core/group', 'core/columns' ), + 'color' => array( + 'background' => '#000000', + 'text' => '#ffffff', + ), + ), + ), + 'core/group' => array( + 'variations' => $group_variations, + ), + ), + ), + ) + ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + $this->assertSame( $group_variations, $data['styles']['blocks']['core/group']['variations'] ); + } + /** * @doesNotPerformAssertions */