Skip to content

Commit

Permalink
Font Library: use snake_case instead of camelCase on fontFamilies end…
Browse files Browse the repository at this point in the history
…point param (#54977)

* use snake_case instead of camelCase on endpoint param

* updating test
  • Loading branch information
matiasbenedetto authored Oct 2, 2023
1 parent 1445cc2 commit 1980712
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
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 @@ -55,7 +55,7 @@ describe( 'makeFormDataFromFontFamilies', () => {
fontFamily: 'Bebas',
},
];
expect( JSON.parse( formData.get( 'fontFamilies' ) ) ).toEqual(
expect( JSON.parse( formData.get( 'font_families' ) ) ).toEqual(
expectedFontFamilies
);
} );
Expand Down
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

1 comment on commit 1980712

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 1980712.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6384522106
📝 Reported issues:

Please sign in to comment.