Networks and Sites: Ensure fileupload_maxk is an int to avoid potential fatal errors.

This changeset fixes a potential fatal error, for example when "Max upload file size" setting is set to an empty value. It also adds unit tests for `upload_size_limit_filter`.

Props mjkhajeh, bhrugesh12, SergeyBiryukov, kebbet, audrasjb, felipeelia.
Fixes #55926.


git-svn-id: https://develop.svn.wordpress.org/trunk@54482 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras
2022-10-11 15:05:29 +00:00
parent e2c6f8c82a
commit 525d6d2a34
3 changed files with 54 additions and 3 deletions
+48
View File
@@ -395,6 +395,54 @@ if ( is_multisite() ) :
$this->assertGreaterThan( 0, $user_count );
}
/**
* Test the default behavior of upload_size_limit_filter.
* If any default option is changed, the function returns the min value between the
* parameter passed and the `fileupload_maxk` site option (1500Kb by default)
*
* @ticket 55926
*/
public function test_upload_size_limit_filter() {
$return = upload_size_limit_filter( 1499 * KB_IN_BYTES );
$this->assertSame( 1499 * KB_IN_BYTES, $return );
$return = upload_size_limit_filter( 1501 * KB_IN_BYTES );
$this->assertSame( 1500 * KB_IN_BYTES, $return );
}
/**
* Test if upload_size_limit_filter behaves as expected when the `fileupload_maxk` is 0 or an empty string.
*
* @ticket 55926
* @dataProvider data_upload_size_limit_filter_empty_fileupload_maxk
*/
public function test_upload_size_limit_filter_empty_fileupload_maxk( $callable_set_fileupload_maxk ) {
add_filter( 'site_option_fileupload_maxk', $callable_set_fileupload_maxk );
$return = upload_size_limit_filter( 1500 );
$this->assertSame( 0, $return );
}
/**
* @ticket 55926
*/
public function data_upload_size_limit_filter_empty_fileupload_maxk() {
return array(
array( '__return_zero' ),
array( '__return_empty_string' ),
);
}
/**
* When upload_space_check is enabled, the space allowed is also considered by `upload_size_limit_filter`.
*
* @ticket 55926
*/
public function test_upload_size_limit_filter_when_upload_space_check_enabled() {
add_filter( 'get_space_allowed', '__return_zero' );
add_filter( 'site_option_upload_space_check_disabled', '__return_false' );
$return = upload_size_limit_filter( 100 );
$this->assertSame( 0, $return );
}
/**
* @ticket 40489
* @dataProvider data_wp_is_large_network