|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 90; |
20 |
use Test::More tests => 91; |
| 21 |
|
21 |
|
| 22 |
BEGIN { |
22 |
BEGIN { |
| 23 |
require_ok('C4::Circulation'); |
23 |
require_ok('C4::Circulation'); |
|
Lines 36-41
use C4::Reserves;
Link Here
|
| 36 |
use C4::Overdues qw(UpdateFine CalcFine); |
36 |
use C4::Overdues qw(UpdateFine CalcFine); |
| 37 |
use Koha::DateUtils; |
37 |
use Koha::DateUtils; |
| 38 |
use Koha::Database; |
38 |
use Koha::Database; |
|
|
39 |
use Koha::IssuingRules; |
| 39 |
|
40 |
|
| 40 |
my $schema = Koha::Database->schema; |
41 |
my $schema = Koha::Database->schema; |
| 41 |
$schema->storage->txn_begin; |
42 |
$schema->storage->txn_begin; |
|
Lines 1248-1253
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub {
Link Here
|
| 1248 |
is( $error->{USERBLOCKEDNOENDDATE}, '9999-12-31' ); |
1249 |
is( $error->{USERBLOCKEDNOENDDATE}, '9999-12-31' ); |
| 1249 |
}; |
1250 |
}; |
| 1250 |
|
1251 |
|
|
|
1252 |
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { |
| 1253 |
plan tests => 8; |
| 1254 |
|
| 1255 |
my $library = $builder->build( { source => 'Branch' } ); |
| 1256 |
my $patron = $builder->build( { source => 'Borrower' } ); |
| 1257 |
|
| 1258 |
# Add 2 items |
| 1259 |
my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } ); |
| 1260 |
my $item_1 = $builder->build( |
| 1261 |
{ |
| 1262 |
source => 'Item', |
| 1263 |
value => { |
| 1264 |
homebranch => $library->{branchcode}, |
| 1265 |
holdingbranch => $library->{branchcode}, |
| 1266 |
notforloan => 0, |
| 1267 |
itemlost => 0, |
| 1268 |
withdrawn => 0, |
| 1269 |
biblionumber => $biblioitem_1->{biblionumber} |
| 1270 |
} |
| 1271 |
} |
| 1272 |
); |
| 1273 |
my $biblioitem_2 = $builder->build( { source => 'Biblioitem' } ); |
| 1274 |
my $item_2 = $builder->build( |
| 1275 |
{ |
| 1276 |
source => 'Item', |
| 1277 |
value => { |
| 1278 |
homebranch => $library->{branchcode}, |
| 1279 |
holdingbranch => $library->{branchcode}, |
| 1280 |
notforloan => 0, |
| 1281 |
itemlost => 0, |
| 1282 |
withdrawn => 0, |
| 1283 |
biblionumber => $biblioitem_2->{biblionumber} |
| 1284 |
} |
| 1285 |
} |
| 1286 |
); |
| 1287 |
|
| 1288 |
# And the issuing rule |
| 1289 |
Koha::IssuingRules->search->delete; |
| 1290 |
my $rule = Koha::IssuingRule->new( |
| 1291 |
{ |
| 1292 |
categorycode => '*', |
| 1293 |
itemtype => '*', |
| 1294 |
branchcode => '*', |
| 1295 |
maxissueqty => 99, |
| 1296 |
issuelength => 1, |
| 1297 |
firstremind => 1, # 1 day of grace |
| 1298 |
finedays => 2, # 2 days of fine per day of overdue |
| 1299 |
lengthunit => 'days', |
| 1300 |
} |
| 1301 |
); |
| 1302 |
$rule->store(); |
| 1303 |
|
| 1304 |
# Patron cannot issue item_1, he has overdues |
| 1305 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
| 1306 |
my $ten_days_ago = dt_from_string->subtract( days => 10 ); |
| 1307 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
| 1308 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
| 1309 |
; # Add another overdue |
| 1310 |
|
| 1311 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); |
| 1312 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
| 1313 |
undef, undef, dt_from_string ); |
| 1314 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
| 1315 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1316 |
is( scalar(@$debarments), 1 ); |
| 1317 |
|
| 1318 |
# FIXME Is it right? I'd have expected 5 * 2 - 1 instead |
| 1319 |
# Same for the others |
| 1320 |
my $expected_expiration = output_pref( |
| 1321 |
{ |
| 1322 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ), |
| 1323 |
dateformat => 'sql', |
| 1324 |
dateonly => 1 |
| 1325 |
} |
| 1326 |
); |
| 1327 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
| 1328 |
|
| 1329 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, |
| 1330 |
undef, undef, dt_from_string ); |
| 1331 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
| 1332 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1333 |
is( scalar(@$debarments), 1 ); |
| 1334 |
$expected_expiration = output_pref( |
| 1335 |
{ |
| 1336 |
dt => dt_from_string->add( days => ( 10 - 1 ) * 2 ), |
| 1337 |
dateformat => 'sql', |
| 1338 |
dateonly => 1 |
| 1339 |
} |
| 1340 |
); |
| 1341 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
| 1342 |
|
| 1343 |
Koha::Patron::Debarments::DelUniqueDebarment( |
| 1344 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1345 |
|
| 1346 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' ); |
| 1347 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
| 1348 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
| 1349 |
; # Add another overdue |
| 1350 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
| 1351 |
undef, undef, dt_from_string ); |
| 1352 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
| 1353 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1354 |
is( scalar(@$debarments), 1 ); |
| 1355 |
$expected_expiration = output_pref( |
| 1356 |
{ |
| 1357 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ), |
| 1358 |
dateformat => 'sql', |
| 1359 |
dateonly => 1 |
| 1360 |
} |
| 1361 |
); |
| 1362 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
| 1363 |
|
| 1364 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, |
| 1365 |
undef, undef, dt_from_string ); |
| 1366 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
| 1367 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1368 |
is( scalar(@$debarments), 1 ); |
| 1369 |
$expected_expiration = output_pref( |
| 1370 |
{ |
| 1371 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), |
| 1372 |
dateformat => 'sql', |
| 1373 |
dateonly => 1 |
| 1374 |
} |
| 1375 |
); |
| 1376 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
| 1377 |
}; |
| 1378 |
|
| 1379 |
|
| 1251 |
sub set_userenv { |
1380 |
sub set_userenv { |
| 1252 |
my ( $library ) = @_; |
1381 |
my ( $library ) = @_; |
| 1253 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
1382 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
| 1254 |
- |
|
|