forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Font Library: Add upload font test (WordPress#60221)
* Add upload font test * Use Exo 2 woff as test font * Test uploading multiple fonts * Update test/e2e/specs/site-editor/font-library.spec.js Co-authored-by: Dave Smith <getdavemail@gmail.com> * Update test/e2e/specs/site-editor/font-library.spec.js Co-authored-by: Dave Smith <getdavemail@gmail.com> * Add test for CSS rules * Rename multiple fonts test case * Add e2e plugin to delete fonts and the fonts directory * Use delete fonts plugin in e2e tests and check for all uploaded font variations * Fix coding standards * Remove timeouts * Remove step to go back to the Library tab * Remove isVisible check, covered with click action * Remove visible check for another element that is clicked * Modify e2e fonts plugin to use a random directory and cleanup on plugin activation and deactivation * Fix lint * Move font management tests into separate describe block --------- Co-authored-by: Dave Smith <getdavemail@gmail.com> Co-authored-by: Grant Kinney <hi@grant.mk> Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
- Loading branch information
1 parent
3395a6d
commit a57a7de
Showing
4 changed files
with
174 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test Delete Installed Fonts | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-delete-installed-fonts | ||
*/ | ||
|
||
/** | ||
* Saves a randomly generated temporary font directory to use for e2e tests. | ||
*/ | ||
function gutenberg_e2e_set_temp_font_dir() { | ||
update_option( 'gutenberg_e2e_font_dir', '/e2e_fonts_' . wp_generate_uuid4() ); | ||
} | ||
register_activation_hook( __FILE__, 'gutenberg_e2e_set_temp_font_dir' ); | ||
|
||
/** | ||
* Uses the randomly generated font directory for the duration of the font tests. | ||
*/ | ||
function gutenberg_filter_e2e_font_dir( $font_dir ) { | ||
$subdir = get_option( 'gutenberg_e2e_font_dir' ); | ||
|
||
$font_dir['path'] .= $subdir; | ||
$font_dir['url'] .= $subdir; | ||
$font_dir['basedir'] .= $subdir; | ||
$font_dir['baseurl'] .= $subdir; | ||
|
||
return $font_dir; | ||
} | ||
add_filter( 'font_dir', 'gutenberg_filter_e2e_font_dir' ); | ||
|
||
/** | ||
* Deletes all user installed fonts, associated font files, the fonts directory, and user global styles typography | ||
* setings for the current theme so that we can test uploading/installing fonts in a clean environment. | ||
*/ | ||
function gutenberg_delete_installed_fonts() { | ||
$font_family_ids = new WP_Query( | ||
array( | ||
'post_type' => 'wp_font_family', | ||
'posts_per_page' => -1, | ||
'fields' => 'ids', | ||
) | ||
); | ||
|
||
// Delete all font families, their child font faces, and associated font files. | ||
foreach ( $font_family_ids->posts as $font_family_id ) { | ||
wp_delete_post( $font_family_id, true ); | ||
} | ||
|
||
// Delete the font directory, which should now be empty. | ||
$font_path = wp_get_font_dir()['path']; | ||
|
||
if ( is_dir( $font_path ) ) { | ||
rmdir( $font_path ); | ||
} | ||
|
||
// Delete any installed fonts from global styles. | ||
$global_styles_post_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); | ||
$request = new WP_REST_Request( 'POST', '/wp/v2/global-styles/' . $global_styles_post_id ); | ||
$request->set_body_params( array( 'settings' => array( 'typography' => array( 'fontFamilies' => array() ) ) ) ); | ||
|
||
rest_do_request( $request ); | ||
} | ||
|
||
// Clean up fonts on plugin activation and deactivation. | ||
register_activation_hook( __FILE__, 'gutenberg_delete_installed_fonts' ); | ||
register_deactivation_hook( __FILE__, 'gutenberg_delete_installed_fonts' ); |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters