Changeset 42343 for trunk/tests/phpunit/tests/multisite/getSpaceAllowed.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/getSpaceAllowed.php
r35244 r42343 3 3 if ( is_multisite() ) : 4 4 5 /**6 * Tests specific to `get_space_allowed()` in multisite.7 *8 * @group multisite9 */10 class Tests_Multisite_Get_Space_Allowed extends WP_UnitTestCase {11 protected $suppress = false;5 /** 6 * Tests specific to `get_space_allowed()` in multisite. 7 * 8 * @group multisite 9 */ 10 class Tests_Multisite_Get_Space_Allowed extends WP_UnitTestCase { 11 protected $suppress = false; 12 12 13 protected static $original_site_blog_upload_space;14 protected static $original_blog_upload_space;13 protected static $original_site_blog_upload_space; 14 protected static $original_blog_upload_space; 15 15 16 public static function setUpBeforeClass() {17 parent::setUpBeforeClass();16 public static function setUpBeforeClass() { 17 parent::setUpBeforeClass(); 18 18 19 self::$original_site_blog_upload_space = get_site_option( 'blog_upload_space' ); 20 self::$original_blog_upload_space = get_option( 'blog_upload_space' ); 19 self::$original_site_blog_upload_space = get_site_option( 'blog_upload_space' ); 20 self::$original_blog_upload_space = get_option( 'blog_upload_space' ); 21 } 22 23 public function setUp() { 24 global $wpdb; 25 parent::setUp(); 26 $this->suppress = $wpdb->suppress_errors(); 27 } 28 29 public function tearDown() { 30 global $wpdb; 31 32 /** 33 * Reset the two `blog_upload_space` options to their original values so 34 * they can be relied on in other test classes. 35 */ 36 update_site_option( 'blog_upload_space', self::$original_site_blog_upload_space ); 37 update_option( 'blog_upload_space', self::$original_blog_upload_space ); 38 39 $wpdb->suppress_errors( $this->suppress ); 40 parent::tearDown(); 41 } 42 43 /** 44 * When no option exists for the site or the network, a fallback of 45 * 100 is expected. 46 */ 47 public function test_get_space_allowed_default() { 48 delete_option( 'blog_upload_space' ); 49 delete_site_option( 'blog_upload_space' ); 50 51 $this->assertEquals( 100, get_space_allowed() ); 52 } 53 54 /** 55 * If an individual site's option is not available, the default network 56 * level option is used as a fallback. 57 */ 58 public function test_get_space_allowed_no_site_option_fallback_to_network_option() { 59 delete_site_option( 'blog_upload_space' ); 60 update_site_option( 'blog_upload_space', 200 ); 61 62 $this->assertEquals( 200, get_space_allowed() ); 63 } 64 65 /** 66 * @dataProvider data_blog_upload_space 67 * 68 * @param mixed $site_option Option to assign to the site's `blog_upload_space`. 69 * @param mixed $network_option Option to assign to the network's `blog_upload_space`. 70 * @param int $expected Expected return value. 71 */ 72 public function test_get_space_allowed( $site_option, $network_option, $expected ) { 73 update_option( 'blog_upload_space', $site_option ); 74 update_site_option( 'blog_upload_space', $network_option ); 75 76 $this->assertEquals( $expected, get_space_allowed() ); 77 } 78 79 public function data_blog_upload_space() { 80 return array( 81 // A valid site option will be preferred over a network option. 82 array( 111, 200, 111 ), 83 array( -1, 200, -1 ), 84 array( 222, 0, 222 ), 85 86 // Non-numeric site options should result in a fallback to the network option. 87 array( '', 333, 333 ), 88 array( false, 444, 444 ), 89 array( 'NAN', 555, 555 ), 90 array( false, -10, -10 ), 91 92 // If neither network or site options are valid, fallback to the default. 93 array( false, false, 100 ), 94 array( 'NAN', 'NAN', 100 ), 95 96 // These effectively disable uploads. 97 array( 0, 666, 0 ), 98 array( false, 0, 0 ), 99 array( 'NAN', 0, 0 ), 100 ); 101 } 102 103 public function test_get_space_allowed_filtered() { 104 update_option( 'blog_upload_space', 777 ); 105 update_site_option( 'blog_upload_space', 888 ); 106 107 add_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) ); 108 $space_allowed = get_space_allowed(); 109 remove_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) ); 110 111 $this->assertEquals( 999, $space_allowed ); 112 } 113 114 public function _filter_space_allowed() { 115 return 999; 116 } 21 117 } 22 118 23 public function setUp() {24 global $wpdb;25 parent::setUp();26 $this->suppress = $wpdb->suppress_errors();27 }28 29 public function tearDown() {30 global $wpdb;31 32 /**33 * Reset the two `blog_upload_space` options to their original values so34 * they can be relied on in other test classes.35 */36 update_site_option( 'blog_upload_space', self::$original_site_blog_upload_space );37 update_option( 'blog_upload_space', self::$original_blog_upload_space );38 39 $wpdb->suppress_errors( $this->suppress );40 parent::tearDown();41 }42 43 /**44 * When no option exists for the site or the network, a fallback of45 * 100 is expected.46 */47 public function test_get_space_allowed_default() {48 delete_option( 'blog_upload_space' );49 delete_site_option( 'blog_upload_space' );50 51 $this->assertEquals( 100, get_space_allowed() );52 }53 54 /**55 * If an individual site's option is not available, the default network56 * level option is used as a fallback.57 */58 public function test_get_space_allowed_no_site_option_fallback_to_network_option() {59 delete_site_option( 'blog_upload_space' );60 update_site_option( 'blog_upload_space', 200 );61 62 $this->assertEquals( 200, get_space_allowed() );63 }64 65 /**66 * @dataProvider data_blog_upload_space67 *68 * @param mixed $site_option Option to assign to the site's `blog_upload_space`.69 * @param mixed $network_option Option to assign to the network's `blog_upload_space`.70 * @param int $expected Expected return value.71 */72 public function test_get_space_allowed( $site_option, $network_option, $expected ) {73 update_option( 'blog_upload_space', $site_option );74 update_site_option( 'blog_upload_space', $network_option );75 76 $this->assertEquals( $expected, get_space_allowed() );77 }78 79 public function data_blog_upload_space() {80 return array(81 // A valid site option will be preferred over a network option.82 array( 111, 200, 111 ),83 array( -1, 200, -1 ),84 array( 222, 0, 222 ),85 86 // Non-numeric site options should result in a fallback to the network option.87 array( '', 333, 333 ),88 array( false, 444, 444 ),89 array( 'NAN', 555, 555 ),90 array( false, -10, -10 ),91 92 // If neither network or site options are valid, fallback to the default.93 array( false, false, 100 ),94 array( 'NAN', 'NAN', 100 ),95 96 // These effectively disable uploads.97 array( 0, 666, 0 ),98 array( false, 0, 0 ),99 array( 'NAN', 0, 0 ),100 );101 }102 103 public function test_get_space_allowed_filtered() {104 update_option( 'blog_upload_space', 777 );105 update_site_option( 'blog_upload_space', 888 );106 107 add_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );108 $space_allowed = get_space_allowed();109 remove_filter( 'get_space_allowed', array( $this, '_filter_space_allowed' ) );110 111 $this->assertEquals( 999, $space_allowed );112 }113 114 public function _filter_space_allowed() {115 return 999;116 }117 }118 119 119 endif;
Note: See TracChangeset
for help on using the changeset viewer.