992 | | $this->assertFalse( upload_is_user_over_quota( $echo ) ); |
993 | | $this->assertTrue( is_upload_space_available() ); |
| 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 | } |
995 | | update_site_option('upload_space_check_disabled', true); |
996 | | $this->assertFalse( upload_is_user_over_quota( $echo ) ); |
997 | | $this->assertTrue( is_upload_space_available() ); |
| 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 | } |
| 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 ); |
1000 | | $this->assertFalse( upload_is_user_over_quota( $echo ) ); |
1001 | | $this->assertEquals( $default_space_allowed, get_space_allowed() ); |
| 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() { |
1017 | | update_site_option( 'blog_upload_space', -1 ); |
1018 | | $this->assertTrue( upload_is_user_over_quota( $echo ) ); |
1019 | | $this->assertEquals( -1, get_space_allowed() ); |
| 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 | |
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() ); |
| 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 ); |
| 1159 | update_site_option( 'blog_upload_space', 0 ); |