Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Library: use snake_case instead of camelCase on fontFamilies endpoint param #54977

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function register_routes() {
'callback' => array( $this, 'install_fonts' ),
'permission_callback' => array( $this, 'update_font_library_permissions_check' ),
'args' => array(
'fontFamilies' => array(
'font_families' => array(
'required' => true,
'type' => 'string',
'validate_callback' => array( $this, 'validate_install_font_families' ),
Expand Down Expand Up @@ -147,13 +147,13 @@ private function get_validation_errors( $font_families, $files ) {
$error_messages = array();

if ( ! is_array( $font_families ) ) {
$error_messages[] = __( 'fontFamilies should be an array of font families.', 'gutenberg' );
$error_messages[] = __( 'font_families should be an array of font families.', 'gutenberg' );
return $error_messages;
}

// Checks if there is at least one font family.
if ( count( $font_families ) < 1 ) {
$error_messages[] = __( 'fontFamilies should have at least one font family definition.', 'gutenberg' );
$error_messages[] = __( 'font_families should have at least one font family definition.', 'gutenberg' );
return $error_messages;
}

Expand Down Expand Up @@ -260,7 +260,7 @@ public function validate_install_font_families( $param, $request ) {
*/
public function uninstall_schema() {
return array(
'fontFamilies' => array(
'font_families' => array(
'type' => 'array',
'description' => __( 'The font families to install.', 'gutenberg' ),
'required' => true,
Expand Down Expand Up @@ -289,7 +289,7 @@ public function uninstall_schema() {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function uninstall_fonts( $request ) {
$fonts_to_uninstall = $request->get_param( 'fontFamilies' );
$fonts_to_uninstall = $request->get_param( 'font_families' );

$errors = array();
$successes = array();
Expand Down Expand Up @@ -397,7 +397,7 @@ private function needs_write_permission( $font_families ) {
*/
public function install_fonts( $request ) {
// Get new fonts to install.
$fonts_param = $request->get_param( 'fontFamilies' );
$fonts_param = $request->get_param( 'font_families' );

/*
* As this is receiving form data, the font families are encoded as a string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function fetchInstallFonts( data ) {

export async function fetchUninstallFonts( fonts ) {
const data = {
fontFamilies: fonts,
font_families: fonts,
};
const config = {
path: '/wp/v2/fonts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ export function makeFormDataFromFontFamilies( fontFamilies ) {
}
return family;
} );
formData.append( 'fontFamilies', JSON.stringify( newFontFamilies ) );
formData.append( 'font_families', JSON.stringify( newFontFamilies ) );
return formData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Tests_Fonts_WPRESTFontLibraryController_InstallFonts extends WP_REST_Font_
public function test_install_fonts( $font_families, $files, $expected_response ) {
$install_request = new WP_REST_Request( 'POST', '/wp/v2/fonts' );
$font_families_json = json_encode( $font_families );
$install_request->set_param( 'fontFamilies', $font_families_json );
$install_request->set_param( 'font_families', $font_families_json );
$install_request->set_file_params( $files );
$response = rest_get_server()->dispatch( $install_request );
$data = $response->get_data();
Expand Down Expand Up @@ -309,7 +309,7 @@ public function data_install_fonts() {
public function test_install_with_improper_inputs( $font_families, $files = array() ) {
$install_request = new WP_REST_Request( 'POST', '/wp/v2/fonts' );
$font_families_json = json_encode( $font_families );
$install_request->set_param( 'fontFamilies', $font_families_json );
$install_request->set_param( 'font_families', $font_families_json );
$install_request->set_file_params( $files );

$response = rest_get_server()->dispatch( $install_request );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function set_up() {

$install_request = new WP_REST_Request( 'POST', '/wp/v2/fonts' );
$font_families_json = json_encode( $mock_families );
$install_request->set_param( 'fontFamilies', $font_families_json );
$install_request->set_param( 'font_families', $font_families_json );
rest_get_server()->dispatch( $install_request );
}

Expand All @@ -68,7 +68,7 @@ public function test_uninstall() {
);

$uninstall_request = new WP_REST_Request( 'DELETE', '/wp/v2/fonts' );
$uninstall_request->set_param( 'fontFamilies', $font_families_to_uninstall );
$uninstall_request->set_param( 'font_families', $font_families_to_uninstall );
$response = rest_get_server()->dispatch( $uninstall_request );
$this->assertSame( 200, $response->get_status(), 'The response status is not 200.' );
}
Expand All @@ -88,7 +88,7 @@ public function test_uninstall_non_existing_fonts() {
),
);

$uninstall_request->set_param( 'fontFamilies', $non_existing_font_data );
$uninstall_request->set_param( 'font_families', $non_existing_font_data );
$response = rest_get_server()->dispatch( $uninstall_request );
$data = $response->get_data();
$this->assertCount( 2, $data['errors'], 'The response should have 2 errors, one for each font family uninstall failure.' );
Expand Down
Loading