forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Font Library: filter fonts upload directory (WordPress#57697)
* add global configuration variables for font directory * add multi-site based directory path for fonts * add docblock for get_multi_site_font_sub_dir * Rename function for accuracy. * Use filter instead of constant to determine where fonts are uploaded. * Format php. * simplify the filters code and output the same array as upload_filter does * remove tests no longer used * add a test case for the filter * rename function. Replaces the misleading 'subdir' term by 'dir'. --------- Co-authored-by: madhusudhand <[email protected]> Co-authored-by: Matias Benedetto <[email protected]>
- Loading branch information
1 parent
e93f250
commit 4b1beb4
Showing
5 changed files
with
126 additions
and
74 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
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
70 changes: 70 additions & 0 deletions
70
phpunit/tests/fonts/font-library/wpFontLibrary/fontsDir.php
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,70 @@ | ||
<?php | ||
/** | ||
* Test WP_Font_Library::fonts_dir(). | ||
* | ||
* @package WordPress | ||
* @subpackage Font Library | ||
* | ||
* @group fonts | ||
* @group font-library | ||
* | ||
* @covers WP_Font_Library::fonts_dir | ||
*/ | ||
class Tests_Fonts_WpFontLibrary_FontsDir extends WP_Font_Library_UnitTestCase { | ||
private $dir_defaults; | ||
|
||
public function __construct() { | ||
parent::__construct(); | ||
$this->dir_defaults = array( | ||
'path' => path_join( WP_CONTENT_DIR, 'fonts' ), | ||
'url' => content_url( 'fonts' ), | ||
'subdir' => '', | ||
'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ), | ||
'baseurl' => content_url( 'fonts' ), | ||
'error' => false, | ||
); | ||
} | ||
|
||
public function test_fonts_dir() { | ||
$fonts_dir = WP_Font_Library::fonts_dir(); | ||
$this->assertEquals( $fonts_dir, $this->dir_defaults ); | ||
} | ||
|
||
public function test_fonts_dir_with_filter() { | ||
// Define a callback function to pass to the filter. | ||
function set_new_values( $defaults ) { | ||
$defaults['path'] = '/custom-path/fonts/my-custom-subdir'; | ||
$defaults['url'] = 'http://example.com/custom-path/fonts/my-custom-subdir'; | ||
$defaults['subdir'] = 'my-custom-subdir'; | ||
$defaults['basedir'] = '/custom-path/fonts'; | ||
$defaults['baseurl'] = 'http://example.com/custom-path/fonts'; | ||
$defaults['error'] = false; | ||
return $defaults; | ||
} | ||
|
||
// Add the filter. | ||
add_filter( 'fonts_dir', 'set_new_values' ); | ||
|
||
// Gets the fonts dir. | ||
$fonts_dir = WP_Font_Library::fonts_dir(); | ||
|
||
$expected = array( | ||
'path' => '/custom-path/fonts/my-custom-subdir', | ||
'url' => 'http://example.com/custom-path/fonts/my-custom-subdir', | ||
'subdir' => 'my-custom-subdir', | ||
'basedir' => '/custom-path/fonts', | ||
'baseurl' => 'http://example.com/custom-path/fonts', | ||
'error' => false, | ||
); | ||
|
||
$this->assertEquals( $fonts_dir, $expected, 'The fonts_dir() method should return the expected values.' ); | ||
|
||
// Remove the filter. | ||
remove_filter( 'fonts_dir', 'set_new_values' ); | ||
|
||
// Gets the fonts dir. | ||
$fonts_dir = WP_Font_Library::fonts_dir(); | ||
|
||
$this->assertEquals( $fonts_dir, $this->dir_defaults, 'The fonts_dir() method should return the default values.' ); | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
phpunit/tests/fonts/font-library/wpFontLibrary/getFontsDir.php
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
phpunit/tests/fonts/font-library/wpFontLibrary/setUploadDir.php
This file was deleted.
Oops, something went wrong.