Repository navigation
Conversation
|
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/fonts/font-library/class-wp-font-family.php ❔ lib/experimental/fonts/font-library/class-wp-font-library.php ❔ phpunit/tests/fonts/font-library/wpFontFamily/base.php ❔ phpunit/tests/fonts/font-library/wpFontFamily/install.php ❔ phpunit/tests/fonts/font-library/wpFontLibrary/getFontsDir.php ❔ phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php ❔ phpunit/tests/fonts/font-library/wpRestFontLibraryController/installFonts.php |
matiasbenedetto
left a comment
There was a problem hiding this comment.
@matiasbenedetto what is the best way to test this, or is the tests passing sufficient?
Yep, it should be enough because we are testing if the files exist in the right location.
gutenberg/phpunit/tests/fonts/font-library/wpFontFamily/install.php
Lines 96 to 99 in 22d24f3
Please update the tests to look for the files in the right place. I think we would need to update here, for example:
gutenberg/phpunit/tests/fonts/font-library/wpFontFamily/base.php
Lines 28 to 34 in 22d24f3
There could be an enhancement opportunity there ☝️ by simplifying and avoiding the need to define the $upload_dir in the set_up method.
|
Flaky tests detected in 119f15b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6029896336
|
matiasbenedetto
left a comment
There was a problem hiding this comment.
After the tests work as expected, making a manual test round would be nice, too. For that, you can checkout the frontend branch: #53884 build, and after that, checkout this branch and use the UI to upload a few fonts.
975112e to
fe107a0
Compare
|
There are two related tests erroring or failing, which are passing for me locally. Any idea why these would fail in the CI but not locally? |
There was a problem hiding this comment.
There are two related tests erroring or failing, which are passing for me locally. Any idea why these would fail in the CI but not locally?
I suspect that the destination folder is not being created on the CI machine. I'll take a look at that.
Apart from that, @jffng, could you please add your findings about why we could not use wp_handle_upload() function to move the uploaded files?
The current implementation uses the core function If we want to store the fonts in As far as I can tell, there is no option to override this: https://github.com/WordPress/wordpress-develop/blob/6.3/src/wp-admin/includes/file.php#L776-L789 |
There was a problem hiding this comment.
As far as I can tell, there is no option to override this: https://github.com/WordPress/wordpress-develop/blob/6.3/src/wp-admin/includes/file.php#L776-L789
This function is for that:
gutenberg/lib/experimental/fonts/font-library/class-wp-font-library.php
Lines 112 to 115 in 2c0aebd
It is called by the install() method before writing the files and it's removed just after to avoid changing the normal work of the rest of the codebase:
gutenberg/lib/experimental/fonts/font-library/class-wp-font-family.php
Lines 544 to 547 in 2c0aebd
I just tried something like this, changing these WP_Font_Library methods and it seems to work as expected :
public static function get_fonts_dir() {
return path_join( WP_CONTENT_DIR, 'fonts' );
}public static function set_upload_dir( $defaults ) {
$defaults['basedir'] = WP_CONTENT_DIR;
$defaults['baseurl'] = content_url();
$defaults['path'] = self::get_fonts_dir();
$defaults['url'] = $defaults['baseurl'].'/fonts';
$defaults['subdir'] = 'fonts';
return $defaults;
}I think it would be nice to continue using wp_handle_upload() due to their fine tunning around security and server edge cases.
|
Another way to test manually is running this in your console. It's a POST request to install one font family.
|
|
@matiasbenedetto good suggestion, thank you! Closing this in favor of #54122. |
What
This PR closes #53965.
How
We can't use
wp_handle_uploadbecause this function only works to move files into theuploadsdirectory (or subdirectory). This PR reworks the implementation torenamethe temporary file to its new location in thewp-content/fontsdirectory.To test
wpFontFamilytests pass