Skip to content

Commit

Permalink
Test naive filtering of uploads directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwilsoncc committed Mar 4, 2024
1 parent 238383d commit c6844b3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/phpunit/tests/fonts/font-library/wpFontsDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

0 comments on commit c6844b3

Please sign in to comment.