Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d343f65
WIP: Refactor Font API font family GET POST testing round 1
pbking Dec 12, 2023
4b342c5
Added GET font family collection tests and implementation
pbking Dec 12, 2023
3343b98
add font family IDs to API responses
pbking Dec 12, 2023
3374120
Move data into 'data' object
pbking Dec 12, 2023
8a4c798
Added delete API implementation and tests
pbking Dec 13, 2023
140faf0
Adding 'force' to font family delete api
pbking Dec 13, 2023
7d26ae9
Got basic font family updating service working
pbking Dec 13, 2023
f71111c
Moved implementation of adding font faces to use font family put inst…
pbking Dec 13, 2023
2ed64b2
Removed route tests (testing the routes seems sufficient and they are…
pbking Dec 13, 2023
88d70ba
Renamed controller to 'Font Family Controller'
pbking Dec 13, 2023
dc9fb0b
Renamed controller to 'Font Family Controller' (continued)
pbking Dec 13, 2023
95e9ce5
Refactored font collection API into its own controller
pbking Dec 13, 2023
9ef8086
Simplifying font family update logic (WIP)
pbking Dec 13, 2023
f28f616
Added better error handling for Font Family creation and updating. A…
pbking Dec 14, 2023
47eb63a
Adding tests for font families with downloaded font face assets
pbking Dec 14, 2023
759a08b
Added upload font face asset tests. Cleaned up update logic.
pbking Dec 14, 2023
efb51e8
Refactored existing tests into individual files and cleaned them up
pbking Dec 15, 2023
592faac
Refactored existing tests into individual files and cleaned them up
pbking Dec 15, 2023
8aade9f
Added PATCH operation and remove file assets for font faces that were…
pbking Dec 15, 2023
aa15a94
Added ability to update font family via POST
pbking Dec 15, 2023
53e9001
Removed unused functions, moved 'create font folder' logic to class, …
pbking Dec 15, 2023
edefab4
Refactored font face asset handling to ONLY accept UPLOADED and HOSTE…
pbking Jan 10, 2024
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
Prev Previous commit
Refactored font face asset handling to ONLY accept UPLOADED and HOSTE…
…D actions (determined by presence of files)
  • Loading branch information
pbking committed Jan 10, 2024
commit edefab4d9549928b80a9cf015ba0fa32c3d77014
37 changes: 21 additions & 16 deletions lib/experimental/fonts/font-library/class-wp-font-family.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ private function prepare_font_faces( $font_faces, $files ) {

foreach ( $font_faces as $font_face ) {

if ( ! empty( $font_face['uploadedFile'] ) || ! empty( $font_face['downloadFromUrl'] ) ) {
if ( empty( $font_face['src'] ) ) {
return new WP_Error(
'font_face_asset_missing',
__( 'The font face asset was not defined.', 'gutenberg' )
);
}

if ( $files ) {

if ( ! $this->has_write_permission() ) {
return new WP_Error(
Expand All @@ -266,29 +273,27 @@ private function prepare_font_faces( $font_faces, $files ) {
);
}

if ( ! empty( $font_face['uploadedFile'] ) ) {
if ( ! $files || ! array_key_exists( $font_face['uploadedFile'], $files )) {
return new WP_Error(
'font_face_upload_file_missing',
__( 'The font face assets was not provided.', 'gutenberg' )
);
}
$downloaded_font_face_src = $this->move_font_face_asset( $font_face, $files[ $font_face[ 'uploadedFile' ] ] );
unset( $font_face['uploadedFile'] );
}


if ( ! empty( $font_face['downloadFromUrl'] ) ) {
$downloaded_font_face_src = $this->download_font_face_assets( $font_face );
unset( $font_face['downloadFromUrl'] );
if ( ! $files || ! array_key_exists( $font_face['src'], $files )) {
return new WP_Error(
'font_face_upload_file_missing',
__( 'The font face assets was not provided.', 'gutenberg' )
);
}
$downloaded_font_face_src = $this->move_font_face_asset( $font_face, $files[ $font_face[ 'src' ] ] );

if ( is_wp_error( $downloaded_font_face_src ) ) {
return $downloaded_font_face_src;
}

$font_face['src'] = $downloaded_font_face_src;
}
else if ( str_starts_with( $font_face['src'], 'file' ) ) {
return new WP_Error(
'font_face_upload_file_missing',
__( 'The font face assets was not provided.', 'gutenberg' )
);
}

$ready_font_faces[] = $font_face;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function data_create_font_family_with_improper_inputs() {
'fontFamily' => 'Font Family',
'fontStyle' => 'normal',
'fontWeight' => '400',
'uploadedFile' => 'files0',
'src' => 'files0',
),
),
),
Expand All @@ -139,7 +139,7 @@ public function data_create_font_family_with_improper_inputs() {
'fontFamily' => 'Font Family',
'fontStyle' => 'normal',
'fontWeight' => '400',
'uploadedFile' => 'filesNotCorrectReference',
'src' => 'filesNotCorrectReference',
),
),
),
Expand Down Expand Up @@ -294,55 +294,6 @@ public function data_create_font_family() {
),
),

'Font Family with Font Faces with resources to download' => array(
'request' => array(
'data' => array(
'slug' => 'slug',
'name' => 'Name',
'fontFamily' => 'Family',
'fontFace' => array(
array(
'fontFamily' => 'Family',
'fontStyle' => 'normal',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-normal.svg',
'downloadFromUrl' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
),
array(
'fontFamily' => 'Family',
'fontStyle' => 'italic',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-italic.svg',
'downloadFromUrl' => 'https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf',
),
),
),
),
'expected_response' => array(
'data' => array(
'slug' => 'slug',
'name' => 'Name',
'fontFamily' => 'Family',
'fontFace' => array(
array(
'fontFamily' => 'Family',
'fontStyle' => 'normal',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-normal.svg',
'src' => 'http://localhost:8889/wp-content/fonts/slug_normal_400.ttf',
),
array(
'fontFamily' => 'Family',
'fontStyle' => 'italic',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-italic.svg',
'src' => 'http://localhost:8889/wp-content/fonts/slug_italic_400.ttf',
),
),
),
),
),

'Font Family with Font Faces with uploaded resources' => array(
'request' => array(
'data' => array(
Expand All @@ -354,13 +305,13 @@ public function data_create_font_family() {
'fontFamily' => 'Family',
'fontStyle' => 'normal',
'fontWeight' => '400',
'uploadedFile' => 'files0',
'src' => 'files0',
),
array(
'fontFamily' => 'Family',
'fontStyle' => 'italic',
'fontWeight' => '400',
'uploadedFile' => 'files1',
'src' => 'files1',
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ public function data_update_font_family() {
'fontStyle' => 'normal',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-normal.svg',
'downloadFromUrl' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
'src' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
),
array(
'fontFamily' => 'Family',
'fontStyle' => 'italic',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-italic.svg',
'downloadFromUrl' => 'https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf',
'src' => 'https://fonts.gstatic.com/s/abeezee/v22/esDT31xSG-6AGleN2tCklZUCGpG-GQ.ttf',
),
),
)
Expand All @@ -266,7 +266,7 @@ public function data_update_font_family() {
'fontStyle' => 'normal',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-normal.svg',
'downloadFromUrl' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
'src' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
),
),
)
Expand All @@ -282,7 +282,7 @@ public function data_update_font_family() {
'fontStyle' => 'normal',
'fontWeight' => '400',
'preview' => 'https://s.w.org/images/fonts/16.7/previews/abeezee/abeezee-400-normal.svg',
'src' => 'http://localhost:8889/wp-content/fonts/slug_normal_400.ttf',
'src' => 'https://fonts.gstatic.com/s/abeezee/v22/esDR31xSG-6AGleN6tKukbcHCpE.ttf',
),
),
)
Expand Down