@@ -667,6 +667,25 @@ public function test_update_item_invalid_styles_css() {
667667 $ this ->assertErrorResponse ( 'rest_custom_css_illegal_markup ' , $ response , 400 );
668668 }
669669
670+ /**
671+ * @covers WP_REST_Global_Styles_Controller::update_item
672+ * @ticket 65640
673+ */
674+ public function test_update_item_non_string_styles_css () {
675+ wp_set_current_user ( self ::$ admin_id );
676+ if ( is_multisite () ) {
677+ grant_super_admin ( self ::$ admin_id );
678+ }
679+ $ request = new WP_REST_Request ( 'PUT ' , '/wp/v2/global-styles/ ' . self ::$ global_styles_id );
680+ $ request ->set_body_params (
681+ array (
682+ 'styles ' => array ( 'css ' => array ( 'body { color: red; } ' ) ),
683+ )
684+ );
685+ $ response = rest_get_server ()->dispatch ( $ request );
686+ $ this ->assertErrorResponse ( 'rest_custom_css_invalid_type ' , $ response , 400 );
687+ }
688+
670689 /**
671690 * Tests the submission of a custom block style variation that was defined
672691 * within a theme style variation and wouldn't be registered at the time
@@ -946,4 +965,42 @@ public static function data_custom_css_disallowed(): array {
946965 'truncated "</stYle" ' => array ( '</stYle ' , 'The CSS must not end in "</stYle". ' ),
947966 );
948967 }
968+
969+ /**
970+ * @covers WP_REST_Global_Styles_Controller::validate_custom_css
971+ * @ticket 65640
972+ *
973+ * @dataProvider data_custom_css_non_string
974+ *
975+ * @param mixed $custom_css Non-string value to validate.
976+ */
977+ public function test_validate_custom_css_non_string ( $ custom_css ) {
978+ $ controller = new WP_REST_Global_Styles_Controller ();
979+ $ validate = Closure::bind (
980+ function ( $ css ) {
981+ return $ this ->validate_custom_css ( $ css );
982+ },
983+ $ controller ,
984+ $ controller
985+ );
986+
987+ $ result = $ validate ( $ custom_css );
988+ $ this ->assertWPError ( $ result );
989+ $ this ->assertSame ( 'rest_custom_css_invalid_type ' , $ result ->get_error_code () );
990+ }
991+
992+ /**
993+ * Data provider.
994+ *
995+ * @return array<string, mixed[]>
996+ */
997+ public static function data_custom_css_non_string (): array {
998+ return array (
999+ 'array ' => array ( array ( 'body { color: red; } ' ) ),
1000+ 'integer ' => array ( 123 ),
1001+ 'boolean ' => array ( true ),
1002+ 'null ' => array ( null ),
1003+ 'object ' => array ( new stdClass () ),
1004+ );
1005+ }
9491006}
0 commit comments