|
Lines 3-9
Link Here
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
| 4 |
use File::Temp qw/tempdir/; |
4 |
use File::Temp qw/tempdir/; |
| 5 |
use Test::CGI::Multipart; |
5 |
use Test::CGI::Multipart; |
| 6 |
use Test::More tests => 21; |
6 |
use Test::More tests => 22; |
| 7 |
use Test::Warn; |
7 |
use Test::Warn; |
| 8 |
|
8 |
|
| 9 |
use t::lib::Mocks; |
9 |
use t::lib::Mocks; |
|
Lines 79-84
is( @{$a->[0]->{dirs}} == 2, 1, 'Finddir returns subdirectories' );
Link Here
|
| 79 |
subtest 'Tests for MaxUploadSize' => sub { |
79 |
subtest 'Tests for MaxUploadSize' => sub { |
| 80 |
test_max(); |
80 |
test_max(); |
| 81 |
}; |
81 |
}; |
|
|
82 |
subtest 'Tests for CheckQuota' => sub { |
| 83 |
test_quota(); |
| 84 |
}; |
| 82 |
|
85 |
|
| 83 |
#end of game |
86 |
#end of game |
| 84 |
$dbh->rollback; |
87 |
$dbh->rollback; |
|
Lines 110-112
sub test_max {
Link Here
|
| 110 |
is( $max, 500, 'MaxUploadSize is still equal to default for user 2' ); |
113 |
is( $max, 500, 'MaxUploadSize is still equal to default for user 2' ); |
| 111 |
done_testing(4); |
114 |
done_testing(4); |
| 112 |
} |
115 |
} |
| 113 |
- |
116 |
|
|
|
117 |
sub test_quota { |
| 118 |
$dbh->do("DELETE FROM upload_settings"); |
| 119 |
$dbh->do("DELETE FROM uploaded_files"); |
| 120 |
is( C4::UploadedFiles::CheckQuota(1), 1, 'Trivial quota check' ); |
| 121 |
|
| 122 |
my @bor = $dbh->selectrow_array( |
| 123 |
'SELECT borrowernumber FROM borrowers LIMIT 1' ); |
| 124 |
if( !@bor ) { |
| 125 |
done_testing(1); |
| 126 |
return; |
| 127 |
} |
| 128 |
|
| 129 |
# We now load some item rules: general 2 in 3 days and two rules |
| 130 |
# for specific borrower (2 per day, 3 in 2 days) |
| 131 |
$dbh->do("INSERT INTO upload_settings |
| 132 |
( borrowernumber, type, count1, count2 ) |
| 133 |
VALUES (?, ?, ?, ?)", undef, ( undef, 'itemquota', 2, 3 )); |
| 134 |
$dbh->do("INSERT INTO upload_settings |
| 135 |
( borrowernumber, type, count1, count2 ) |
| 136 |
VALUES (?, ?, ?, ?)", undef, ( $bor[0], 'itemquota', 2, 1 )); |
| 137 |
$dbh->do("INSERT INTO upload_settings |
| 138 |
( borrowernumber, type, count1, count2 ) |
| 139 |
VALUES (?, ?, ?, ?)", undef, ( $bor[0], 'itemquota', 3, 2 )); |
| 140 |
|
| 141 |
# check item quota |
| 142 |
is( C4::UploadedFiles::CheckQuota($bor[0]), 1, 'Nothing uploaded so far' ); |
| 143 |
my $ins1= qq|INSERT INTO uploaded_files ( id, owner, filesize, dtcreated ) VALUES (?, ?, ?, NOW() + INTERVAL ? HOUR)|; |
| 144 |
$dbh->do( $ins1, undef, ( 'aa1', $bor[0], 1000, -25) ); |
| 145 |
is( C4::UploadedFiles::CheckQuota($bor[0]), 1, 'One uploaded' ); |
| 146 |
$dbh->do( $ins1, undef, ( 'aa2', $bor[0], 1000, -25) ); |
| 147 |
is( C4::UploadedFiles::CheckQuota($bor[0]), 1, 'Two uploaded' ); |
| 148 |
$dbh->do( $ins1, undef, ( 'aa3', $bor[0], 1000, 0) ); |
| 149 |
is( C4::UploadedFiles::CheckQuota($bor[0]), undef, 'Max items reached' ); |
| 150 |
|
| 151 |
# Now delete the last upload and add a size rule (5000 per 2 days) |
| 152 |
# Gradually update the size of the second uploaded file |
| 153 |
$dbh->do("DELETE FROM uploaded_files WHERE id=?", undef, ('aa3') ); |
| 154 |
$dbh->do("INSERT INTO upload_settings |
| 155 |
( borrowernumber, type, count1, count2 ) |
| 156 |
VALUES (?, ?, ?, ?)", undef, ( $bor[0], 'spacequota', 5000, 2 )); |
| 157 |
is( C4::UploadedFiles::CheckQuota($bor[0]), 1, 'Size 2000' ); |
| 158 |
$dbh->do("UPDATE uploaded_files SET filesize=? WHERE id=?", undef, (3000, 'aa2') ); |
| 159 |
is( C4::UploadedFiles::CheckQuota($bor[0]), 1, 'Size 4000' ); |
| 160 |
$dbh->do("UPDATE uploaded_files SET filesize=? WHERE id=?", undef, (4000, 'aa2') ); |
| 161 |
is( C4::UploadedFiles::CheckQuota($bor[0]), undef, 'Size 5000 reached' ); |
| 162 |
|
| 163 |
done_testing(8); |
| 164 |
} |