Changeset 30715
- Timestamp:
- 12/02/2014 10:55:30 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/site.php
r30404 r30715 984 984 985 985 /** 986 * @ticket 18119 987 */ 988 function test_upload_is_user_over_quota() { 989 $default_space_allowed = 100; 990 $echo = false; 991 992 $this->assertFalse( upload_is_user_over_quota( $echo ) ); 986 * Tests to handle the possibilities provided for in `get_space_allowed()`, 987 * which is used when checking for upload quota limits. Originally part of 988 * ticket #18119. 989 */ 990 function test_get_space_allowed_default() { 991 $this->assertEquals( 100, get_space_allowed() ); 992 } 993 994 /** 995 * When an individual site's option is defined, it is used over the option 996 * defined at the network level. 997 */ 998 function test_get_space_allowed_from_blog_option() { 999 update_option( 'blog_upload_space', 123 ); 1000 update_site_option( 'blog_upload_space', 200 ); 1001 $this->assertEquals( 123, get_space_allowed() ); 1002 } 1003 1004 /** 1005 * If an individual site's option is not available, the default network 1006 * level option is used as a fallback. 1007 */ 1008 function test_get_space_allowed_from_network_option() { 1009 update_option( 'blog_upload_space', false ); 1010 update_site_option( 'blog_upload_space', 200 ); 1011 $this->assertEquals( 200, get_space_allowed() ); 1012 } 1013 1014 /** 1015 * If neither the site or network options are available, 100 is used as 1016 * a hard coded fallback. 1017 */ 1018 function test_get_space_allowed_no_option_fallback() { 1019 update_option( 'blog_upload_space', false ); 1020 update_site_option( 'blog_upload_space', false ); 1021 $this->assertEquals( 100, get_space_allowed() ); 1022 } 1023 1024 function test_get_space_allowed_negative_blog_option() { 1025 update_option( 'blog_upload_space', -1 ); 1026 update_site_option( 'blog_upload_space', 200 ); 1027 $this->assertEquals( -1, get_space_allowed() ); 1028 } 1029 1030 function test_get_space_allowed_negative_site_option() { 1031 update_option( 'blog_upload_space', false ); 1032 update_site_option( 'blog_upload_space', -1 ); 1033 $this->assertEquals( -1, get_space_allowed() ); 1034 } 1035 1036 /** 1037 * Provide a hardcoded amount for space used when testing upload quota, 1038 * allowed space, and available space. 1039 * 1040 * @return int 1041 */ 1042 function _filter_space_used() { 1043 return 300; 1044 } 1045 1046 function test_upload_is_user_over_quota_default() { 1047 $this->assertFalse( upload_is_user_over_quota( false ) ); 1048 } 1049 1050 function test_upload_is_user_over_quota_check_enabled() { 1051 update_site_option('upload_space_check_disabled', false); 1052 $this->assertFalse( upload_is_user_over_quota( false ) ); 1053 } 1054 1055 /** 1056 * When the upload space check is disabled, using more than the available 1057 * quota is allowed. 1058 */ 1059 function test_upload_is_user_over_check_disabled() { 1060 update_site_option( 'upload_space_check_disabled', true ); 1061 update_site_option( 'blog_upload_space', 100 ); 1062 add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1063 1064 $this->assertFalse( upload_is_user_over_quota( false ) ); 1065 1066 remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1067 } 1068 1069 /** 1070 * If 0 is set for `blog_upload_space`, a fallback of 100 is used. 1071 */ 1072 function test_upload_is_user_over_quota_upload_space_0() { 1073 update_site_option( 'upload_space_check_disabled', false ); 1074 update_site_option( 'blog_upload_space', 0 ); 1075 $this->assertFalse( upload_is_user_over_quota( false ) ); 1076 } 1077 1078 /** 1079 * Filter the space space used as 300 to trigger a true upload quota 1080 * without requiring actual files. 1081 */ 1082 function test_upload_is_user_over_quota_upload_space_0_filter_space_used() { 1083 update_site_option( 'upload_space_check_disabled', false ); 1084 update_site_option( 'blog_upload_space', 0 ); 1085 add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1086 1087 $this->assertTrue( upload_is_user_over_quota( false ) ); 1088 1089 remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1090 } 1091 1092 function test_upload_is_user_over_quota_upload_space_200() { 1093 update_site_option( 'upload_space_check_disabled', false ); 1094 update_site_option( 'blog_upload_space', 200 ); 1095 $this->assertFalse( upload_is_user_over_quota( false ) ); 1096 } 1097 1098 function test_upload_is_user_over_quota_upload_space_200_filter_space_used() { 1099 update_site_option( 'upload_space_check_disabled', false ); 1100 update_site_option( 'blog_upload_space', 200 ); 1101 add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1102 1103 $this->assertTrue( upload_is_user_over_quota( false ) ); 1104 1105 remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1106 } 1107 1108 /** 1109 * If the space used is exactly the same as the available quota, an over 1110 * quota response is not expected. 1111 */ 1112 function test_upload_is_user_over_quota_upload_space_exact() { 1113 update_site_option( 'upload_space_check_disabled', false ); 1114 update_site_option( 'blog_upload_space', 300 ); 1115 add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1116 1117 $this->assertFalse( upload_is_user_over_quota( false ) ); 1118 1119 remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1120 } 1121 1122 function test_upload_is_user_over_quota_upload_space_negative() { 1123 update_site_option( 'upload_space_check_disabled', false ); 1124 update_site_option( 'blog_upload_space', -1 ); 1125 $this->assertTrue( upload_is_user_over_quota( false ) ); 1126 } 1127 1128 function test_is_upload_space_available_default() { 993 1129 $this->assertTrue( is_upload_space_available() ); 994 995 update_site_option('upload_space_check_disabled', true); 996 $this->assertFalse( upload_is_user_over_quota( $echo ) ); 1130 } 1131 1132 function test_is_upload_space_available_check_disabled() { 1133 update_site_option( 'upload_space_check_disabled', true ); 997 1134 $this->assertTrue( is_upload_space_available() ); 998 1135 } 1136 1137 function test_is_upload_space_available_space_used_is_less() { 1138 update_site_option( 'upload_space_check_disabled', false ); 1139 update_site_option( 'blog_upload_space', 350 ); 1140 add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1141 1142 $this->assertTrue( is_upload_space_available() ); 1143 1144 remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1145 } 1146 1147 function test_is_upload_space_available_space_used_is_more() { 1148 update_site_option( 'upload_space_check_disabled', false ); 1149 update_site_option( 'blog_upload_space', 250 ); 1150 add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1151 1152 $this->assertFalse( is_upload_space_available() ); 1153 1154 remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) ); 1155 } 1156 1157 function test_is_upload_space_available_upload_space_0() { 1158 update_site_option( 'upload_space_check_disabled', false ); 999 1159 update_site_option( 'blog_upload_space', 0 ); 1000 $this->assertFalse( upload_is_user_over_quota( $echo ) );1001 $this->assertEquals( $default_space_allowed, get_space_allowed() );1002 1160 $this->assertTrue( is_upload_space_available() ); 1003 1004 update_site_option('upload_space_check_disabled', false); 1005 $this->assertFalse( upload_is_user_over_quota( $echo ) ); 1006 $this->assertTrue( is_upload_space_available() ); 1007 1008 if ( defined( 'BLOGSUPLOADDIR' ) && ! file_exists( BLOGSUPLOADDIR ) ) 1009 $this->markTestSkipped( 'This test is broken when blogs.dir does not exist. '); 1010 1011 /* 1012 This is broken when blogs.dir does not exist, as get_upload_space_available() 1013 simply returns the value of blog_upload_space (converted to bytes), which would 1014 be negative but still not false. When blogs.dir does exist, < 0 is returned as 0. 1015 */ 1016 1161 } 1162 1163 function test_is_upload_space_available_upload_space_negative() { 1164 update_site_option( 'upload_space_check_disabled', false ); 1017 1165 update_site_option( 'blog_upload_space', -1 ); 1018 $this->assertTrue( upload_is_user_over_quota( $echo ) );1019 $this->assertEquals( -1, get_space_allowed() );1020 $this->assertFalse( is_upload_space_available() );1021 1022 update_option( 'blog_upload_space', 0 );1023 $this->assertFalse( upload_is_user_over_quota( $echo ) );1024 $this->assertEquals( $default_space_allowed, get_space_allowed() );1025 $this->assertTrue( is_upload_space_available() );1026 1027 update_option( 'blog_upload_space', -1 );1028 $this->assertTrue( upload_is_user_over_quota( $echo ) );1029 $this->assertEquals( -1, get_space_allowed() );1030 1166 $this->assertFalse( is_upload_space_available() ); 1031 1167 }
Note: See TracChangeset
for help on using the changeset viewer.