@@ -18,7 +18,10 @@ public function set_up() {
1818 reset_db ();
1919 uopz_unset_return ( FontAwesome_SVG_Styles_Manager::class, 'is_svg_stylesheet_present ' );
2020 uopz_unset_return ( FontAwesome_Release_Provider::class, 'get_svg_styles_resource ' );
21+ uopz_unset_return ( FontAwesome_SVG_Styles_Manager::class, 'is_svg_stylesheet_url_present ' );
22+ uopz_unset_return ( 'WP_Filesystem ' );
2123 uopz_unset_return ( 'wp_remote_get ' );
24+ uopz_unset_return ( 'wp_remote_head ' );
2225 remove_all_filters ( 'font_awesome_disable_block_editor_support ' );
2326
2427 $ this ->setup_metadata_provider_mock ();
@@ -29,7 +32,14 @@ public function set_up() {
2932
3033 update_option (
3134 FontAwesome::OPTIONS_KEY ,
32- FontAwesome::DEFAULT_USER_OPTIONS
35+ array_merge (
36+ FontAwesome::DEFAULT_USER_OPTIONS ,
37+ array (
38+ 'version ' => '6.x ' ,
39+ 'kitToken ' => 'abc123 ' ,
40+ 'apiToken ' => true ,
41+ )
42+ )
3343 );
3444 }
3545
@@ -138,6 +148,60 @@ function () use ( &$wp_remote_get_call_count ) {
138148 $ this ->assertEquals ( 0 , $ wp_remote_get_call_count );
139149 }
140150
151+ public function test_is_svg_stylesheet_present_when_present_with_filesystem_permissions () {
152+ if ( ! function_exists ( 'WP_Filesystem ' ) ) {
153+ require_once ABSPATH . 'wp-admin/includes/file.php ' ;
154+ }
155+
156+ global $ wp_filesystem ;
157+
158+ if ( ! $ wp_filesystem ) {
159+ $ this ->assertTrue ( WP_Filesystem ( false ) );
160+ }
161+
162+ $ this ->assertNotNull ( $ wp_filesystem );
163+
164+ $ filesystem_class = get_class ( $ wp_filesystem );
165+
166+ uopz_set_return (
167+ $ filesystem_class ,
168+ 'exists ' ,
169+ true ,
170+ false
171+ );
172+
173+ // It should not fall back to fetching by URL, but if it does, fail.
174+ uopz_set_return (
175+ FontAwesome_SVG_Styles_Manager::class,
176+ 'is_svg_stylesheet_url_present ' ,
177+ false
178+ );
179+
180+ $ this ->assertTrue ( FontAwesome_SVG_Styles_Manager::is_svg_stylesheet_present ( fa () ) );
181+ }
182+
183+ public function test_is_svg_stylesheet_present_when_present_with_no_filesystem_permissions () {
184+ // Simulate the filesystem being inaccessible.
185+ uopz_set_return (
186+ 'WP_Filesystem ' ,
187+ false ,
188+ false
189+ );
190+
191+ uopz_set_return (
192+ 'wp_remote_head ' ,
193+ array (
194+ 'response ' => array (
195+ 'code ' => 200 ,
196+ ),
197+ )
198+ );
199+
200+ // It should fallback to an HTTP request.
201+ $ this ->assertTrue ( FontAwesome_SVG_Styles_Manager::is_svg_stylesheet_present ( fa () ) );
202+ }
203+
204+
141205 public function setup_metadata_provider_mock () {
142206 ( new Mock_FontAwesome_Metadata_Provider () )->mock (
143207 array (
0 commit comments