@@ -794,11 +794,13 @@ public function test_wp_maybe_inline_styles_bad_path_at_file_size_check() {
794794 * @expectedIncorrectUsage wp_maybe_inline_styles
795795 */
796796 public function test_wp_maybe_inline_styles_bad_path_with_file_size_provided () {
797+ $ inc_path = '/css/ancient-themes.css ' ; // Does not exist.
798+
797799 // This ensures the initial file size check is bypassed.
798800 add_filter (
799801 'pre_wp_filesize ' ,
800- static function ( $ size , $ path ) {
801- if ( str_contains ( $ path , ' ancient-themes.css ' ) ) {
802+ static function ( $ size , $ path ) use ( $ inc_path ) {
803+ if ( str_contains ( $ path , $ inc_path ) ) {
802804 $ size = 1000 ;
803805 }
804806 return $ size ;
@@ -807,9 +809,8 @@ static function ( $size, $path ) {
807809 2
808810 );
809811
810- $ handle = 'test-handle ' ;
811- $ inc_path = '/css/ancient-themes.css ' ; // Does not exist.
812- $ url = '/ ' . WPINC . $ inc_path ;
812+ $ handle = 'test-handle ' ;
813+ $ url = '/ ' . WPINC . $ inc_path ;
813814 wp_register_style ( $ handle , $ url );
814815 wp_style_add_data ( $ handle , 'path ' , ABSPATH . WPINC . $ inc_path );
815816 wp_enqueue_style ( $ handle );
@@ -819,6 +820,37 @@ static function ( $size, $path ) {
819820 $ this ->assertSame ( $ GLOBALS ['wp_styles ' ]->registered [ $ handle ]->src , $ url );
820821 }
821822
823+ /**
824+ * @ticket 64447
825+ *
826+ * @covers ::wp_maybe_inline_styles
827+ */
828+ public function test_wp_maybe_inline_styles_good_path_with_zero_file_size_provided () {
829+ $ inc_path = '/css/classic-themes.css ' ;
830+
831+ // This simulates the file having a zero size.
832+ add_filter (
833+ 'pre_wp_filesize ' ,
834+ static function ( $ size , $ path ) use ( $ inc_path ) {
835+ if ( str_contains ( $ path , $ inc_path ) ) {
836+ $ size = 0 ;
837+ }
838+ return $ size ;
839+ },
840+ 10 ,
841+ 2
842+ );
843+
844+ $ handle = 'test-handle ' ;
845+ wp_register_style ( $ handle , '/ ' . WPINC . $ inc_path );
846+ wp_style_add_data ( $ handle , 'path ' , ABSPATH . WPINC . $ inc_path );
847+ wp_enqueue_style ( $ handle );
848+
849+ wp_maybe_inline_styles ();
850+
851+ $ this ->assertFalse ( $ GLOBALS ['wp_styles ' ]->registered [ $ handle ]->src );
852+ }
853+
822854 /**
823855 * @ticket 63887
824856 */
0 commit comments