diff --git a/tests/phpunit/tests/multisite/getSpaceAllowed.php b/tests/phpunit/tests/multisite/getSpaceAllowed.php new file mode 100644 index 0000000000..c2393c0cf5 --- /dev/null +++ b/tests/phpunit/tests/multisite/getSpaceAllowed.php @@ -0,0 +1,119 @@ +suppress = $wpdb->suppress_errors(); + } + + public function tearDown() { + global $wpdb; + + /** + * Reset the two `blog_upload_space` options to their original values so + * they can be relied on in other test classes. + */ + update_site_option( 'blog_upload_space', self::$original_site_blog_upload_space ); + update_option( 'blog_upload_space', self::$original_blog_upload_space ); + + $wpdb->suppress_errors( $this->suppress ); + parent::tearDown(); + } + + /** + * When no option exists for the site or the network, a fallback of + * 100 is expected. + */ + public function test_get_space_allowed_default() { + delete_option( 'blog_upload_space' ); + delete_site_option( 'blog_upload_space' ); + + $this->assertEquals( 100, get_space_allowed() ); + } + + /** + * If an individual site's option is not available, the default network + * level option is used as a fallback. + */ + public function test_get_space_allowed_no_site_option_fallback_to_network_option() { + delete_site_option( 'blog_upload_space' ); + update_site_option( 'blog_upload_space', 200 ); + + $this->assertEquals( 200, get_space_allowed() ); + } + + /** + * @dataProvider data_blog_upload_space + * + * @param mixed $site_option Option to assign to the site's `blog_upload_space`. + * @param mixed $network_option Option to assign to the network's `blog_upload_space`. + * @param int $expected Expected return value. + */ + public function test_get_space_allowed( $site_option, $network_option, $expected ) { + update_option( 'blog_upload_space', $site_option ); + update_site_option( 'blog_upload_space', $network_option ); + + $this->assertEquals( $expected, get_space_allowed() ); + } + + public function data_blog_upload_space() { + return array( + // A valid site option will be preferred over a network option. + array( 111, 200, 111 ), + array( -1, 200, -1 ), + array( 222, 0, 222 ), + + // Non-numeric site options should result in a fallback to the network option. + array( '', 333, 333 ), + array( false, 444, 444 ), + array( 'NAN', 555, 555 ), + array( false, -10, -10 ), + + // If neither network or site options are valid, fallback to the default. + array( false, false, 100 ), + + // These are likely unexpected. + array( 0, 666, 100 ), + array( false, 0, 100 ), + array( 'NAN', 0, 100 ), + ); + } + + public function test_get_space_allowed_filtered() { + update_option( 'blog_upload_space', 777 ); + update_site_option( 'blog_upload_space', 888 ); + + add_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) ); + $space_allowed = get_space_allowed(); + remove_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) ); + + $this->assertEquals( 999, $space_allowed ); + } + + public function _filter_space_allowed() { + return 999; + } +} + +endif; \ No newline at end of file diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index 9e01fd771d..46f5f92813 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -905,57 +905,6 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $this->assertEquals( '', $info['error'] ); } - /** - * Tests to handle the possibilities provided for in `get_space_allowed()`, - * which is used when checking for upload quota limits. Originally part of - * ticket #18119. - */ - function test_get_space_allowed_default() { - $this->assertEquals( 100, self::$space_allowed ); - } - - /** - * When an individual site's option is defined, it is used over the option - * defined at the network level. - */ - function test_get_space_allowed_from_blog_option() { - update_option( 'blog_upload_space', 123 ); - update_site_option( 'blog_upload_space', 200 ); - $this->assertEquals( 123, get_space_allowed() ); - } - - /** - * If an individual site's option is not available, the default network - * level option is used as a fallback. - */ - function test_get_space_allowed_from_network_option() { - update_option( 'blog_upload_space', false ); - update_site_option( 'blog_upload_space', 200 ); - $this->assertEquals( 200, get_space_allowed() ); - } - - /** - * If neither the site or network options are available, 100 is used as - * a hard coded fallback. - */ - function test_get_space_allowed_no_option_fallback() { - update_option( 'blog_upload_space', false ); - update_site_option( 'blog_upload_space', false ); - $this->assertEquals( 100, get_space_allowed() ); - } - - function test_get_space_allowed_negative_blog_option() { - update_option( 'blog_upload_space', -1 ); - update_site_option( 'blog_upload_space', 200 ); - $this->assertEquals( -1, get_space_allowed() ); - } - - function test_get_space_allowed_negative_site_option() { - update_option( 'blog_upload_space', false ); - update_site_option( 'blog_upload_space', -1 ); - $this->assertEquals( -1, get_space_allowed() ); - } - /** * Provide a hardcoded amount for space used when testing upload quota, * allowed space, and available space.