Changeset 61765
- Timestamp:
- 02/27/2026 10:58:26 PM (2 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php (modified) (1 diff)
-
src/wp-includes/rest-api/endpoints/class-wp-rest-font-families-controller.php (modified) (1 diff)
-
tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php (modified) (1 diff)
-
tests/phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php
r58353 r61765 162 162 */ 163 163 public function validate_create_font_face_settings( $value, $request ) { 164 // Enforce JSON Schema validity for field before applying custom validation logic. 165 $args = $this->get_create_params(); 166 $validity = rest_validate_value_from_schema( $value, $args['font_face_settings'], 'font_face_settings' ); 167 168 if ( is_wp_error( $validity ) ) { 169 return $validity; 170 } 171 164 172 $settings = json_decode( $value, true ); 165 173 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-families-controller.php
r58328 r61765 88 88 */ 89 89 public function validate_font_family_settings( $value, $request ) { 90 // Enforce JSON Schema validity for field before applying custom validation logic. 91 $args = $this->get_endpoint_args_for_item_schema( $request->get_method() ); 92 $validity = rest_validate_value_from_schema( $value, $args['font_family_settings'], 'font_family_settings' ); 93 94 if ( is_wp_error( $validity ) ) { 95 return $validity; 96 } 97 90 98 $settings = json_decode( $value, true ); 91 99 -
trunk/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php
r61622 r61765 766 766 $this->assertErrorResponse( 'rest_invalid_param', $response, 400, 'The response should return an error for "rest_invalid_param" with 400 status.' ); 767 767 $expected_message = 'font_face_settings parameter must be a valid JSON string.'; 768 $message = $response->as_error()->get_all_error_data()[0]['params']['font_face_settings']; 769 $this->assertSame( $expected_message, $message, 'The response error message should match.' ); 770 } 771 772 /** 773 * @covers WP_REST_Font_Faces_Controller::validate_create_font_face_settings 774 */ 775 public function test_create_item_non_string_settings() { 776 wp_set_current_user( self::$admin_id ); 777 $request = new WP_REST_Request( 'POST', '/wp/v2/font-families/' . self::$font_family_id . '/font-faces' ); 778 $request->set_param( 'theme_json_version', WP_REST_Font_Faces_Controller::LATEST_THEME_JSON_VERSION_SUPPORTED ); 779 $request->set_param( 'font_face_settings', self::$default_settings ); 780 781 $response = rest_get_server()->dispatch( $request ); 782 783 $this->assertErrorResponse( 'rest_invalid_param', $response, 400, 'The response should return an error for "rest_invalid_param" with 400 status.' ); 784 $expected_message = 'font_face_settings is not of type string.'; 768 785 $message = $response->as_error()->get_all_error_data()[0]['params']['font_face_settings']; 769 786 $this->assertSame( $expected_message, $message, 'The response error message should match.' ); -
trunk/tests/phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php
r61622 r61765 630 630 631 631 /** 632 * @covers WP_REST_Font_Family_Controller::validate_font_family_settings 633 */ 634 public function test_create_item_non_string_settings() { 635 wp_set_current_user( self::$admin_id ); 636 $request = new WP_REST_Request( 'POST', '/wp/v2/font-families' ); 637 $request->set_param( 'theme_json_version', WP_REST_Font_Families_Controller::LATEST_THEME_JSON_VERSION_SUPPORTED ); 638 $request->set_param( 'font_family_settings', self::$default_settings ); 639 640 $response = rest_get_server()->dispatch( $request ); 641 642 $this->assertErrorResponse( 'rest_invalid_param', $response, 400, 'The response should return an error for "rest_invalid_param" with 400 status.' ); 643 $expected_message = 'font_family_settings is not of type string.'; 644 $message = $response->as_error()->get_all_error_data()[0]['params']['font_family_settings']; 645 $this->assertSame( $expected_message, $message, 'The response error message should match.' ); 646 } 647 648 /** 632 649 * @covers WP_REST_Font_Family_Controller::create_item 633 650 */ … … 831 848 832 849 /** 850 * @covers WP_REST_Font_Family_Controller::validate_font_family_settings 851 */ 852 public function test_update_item_non_string_settings() { 853 wp_set_current_user( self::$admin_id ); 854 $request = new WP_REST_Request( 'POST', '/wp/v2/font-families/' . self::$font_family_id1 ); 855 $request->set_param( 'font_family_settings', self::$default_settings ); 856 857 $response = rest_get_server()->dispatch( $request ); 858 859 $this->assertErrorResponse( 'rest_invalid_param', $response, 400, 'The response should return an error for "rest_invalid_param" with 400 status.' ); 860 $expected_message = 'font_family_settings is not of type string.'; 861 $message = $response->as_error()->get_all_error_data()[0]['params']['font_family_settings']; 862 $this->assertSame( $expected_message, $message, 'The response error message should match.' ); 863 } 864 865 /** 833 866 * @covers WP_REST_Font_Families_Controller::update_item 834 867 */
Note: See TracChangeset
for help on using the changeset viewer.