diff --git a/tests/phpunit/tests/fonts/font-library/wpFontsDir.php b/tests/phpunit/tests/fonts/font-library/wpFontsDir.php index a8f79888315bd..0fd66778cd5a8 100644 --- a/tests/phpunit/tests/fonts/font-library/wpFontsDir.php +++ b/tests/phpunit/tests/fonts/font-library/wpFontsDir.php @@ -69,4 +69,39 @@ function set_new_values( $defaults ) { $this->assertSame( static::$dir_defaults, $font_dir, 'The wp_get_font_dir() method should return the default values.' ); } + + public function test_fonts_dir_filters_do_not_trigger_infinite_loop() { + /* + * Naive filtering of uploads directory to return font directory. + * + * This emulates the approach a plugin developer may take to + * add the filter when extending the font library functionality. + */ + add_filter( 'upload_dir', 'wp_get_font_dir' ); + + add_filter( + 'upload_dir', + function ( $upload_dir ) { + static $count = 0; + ++$count; + // It may be hit a couple of times, at five iterations assume an infinite loop. + $this->assertLessThan( 5, $count, 'Filtering uploads directory should not trigger infinite loop.' ); + return $upload_dir; + }, + 5 + ); + + /* + * Filter the font directory to return the uploads directory. + * + * The emulates a moving font files back to the uploads directory due + * to file system structure. + */ + add_filter( 'font_dir', 'wp_get_upload_dir' ); + + wp_get_upload_dir(); + + // This will never be hit if an infinite loop is triggered. + $this->assertTrue( true ); + } }