-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathfontsDir.php
70 lines (60 loc) · 2.05 KB
/
fontsDir.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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.' );
}
}