|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 91; |
20 |
use Test::More tests => 92; |
| 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 |
use Koha::Subscriptions; |
40 |
use Koha::Subscriptions; |
| 40 |
|
41 |
|
| 41 |
my $schema = Koha::Database->schema; |
42 |
my $schema = Koha::Database->schema; |
|
Lines 1306-1311
subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub {
Link Here
|
| 1306 |
is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' ); |
1307 |
is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' ); |
| 1307 |
}; |
1308 |
}; |
| 1308 |
|
1309 |
|
|
|
1310 |
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { |
| 1311 |
plan tests => 8; |
| 1312 |
|
| 1313 |
my $library = $builder->build( { source => 'Branch' } ); |
| 1314 |
my $patron = $builder->build( { source => 'Borrower' } ); |
| 1315 |
|
| 1316 |
# Add 2 items |
| 1317 |
my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } ); |
| 1318 |
my $item_1 = $builder->build( |
| 1319 |
{ |
| 1320 |
source => 'Item', |
| 1321 |
value => { |
| 1322 |
homebranch => $library->{branchcode}, |
| 1323 |
holdingbranch => $library->{branchcode}, |
| 1324 |
notforloan => 0, |
| 1325 |
itemlost => 0, |
| 1326 |
withdrawn => 0, |
| 1327 |
biblionumber => $biblioitem_1->{biblionumber} |
| 1328 |
} |
| 1329 |
} |
| 1330 |
); |
| 1331 |
my $biblioitem_2 = $builder->build( { source => 'Biblioitem' } ); |
| 1332 |
my $item_2 = $builder->build( |
| 1333 |
{ |
| 1334 |
source => 'Item', |
| 1335 |
value => { |
| 1336 |
homebranch => $library->{branchcode}, |
| 1337 |
holdingbranch => $library->{branchcode}, |
| 1338 |
notforloan => 0, |
| 1339 |
itemlost => 0, |
| 1340 |
withdrawn => 0, |
| 1341 |
biblionumber => $biblioitem_2->{biblionumber} |
| 1342 |
} |
| 1343 |
} |
| 1344 |
); |
| 1345 |
|
| 1346 |
# And the issuing rule |
| 1347 |
Koha::IssuingRules->search->delete; |
| 1348 |
my $rule = Koha::IssuingRule->new( |
| 1349 |
{ |
| 1350 |
categorycode => '*', |
| 1351 |
itemtype => '*', |
| 1352 |
branchcode => '*', |
| 1353 |
maxissueqty => 99, |
| 1354 |
issuelength => 1, |
| 1355 |
firstremind => 1, # 1 day of grace |
| 1356 |
finedays => 2, # 2 days of fine per day of overdue |
| 1357 |
lengthunit => 'days', |
| 1358 |
} |
| 1359 |
); |
| 1360 |
$rule->store(); |
| 1361 |
|
| 1362 |
# Patron cannot issue item_1, he has overdues |
| 1363 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
| 1364 |
my $ten_days_ago = dt_from_string->subtract( days => 10 ); |
| 1365 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
| 1366 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
| 1367 |
; # Add another overdue |
| 1368 |
|
| 1369 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); |
| 1370 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
| 1371 |
undef, undef, dt_from_string ); |
| 1372 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
| 1373 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1374 |
is( scalar(@$debarments), 1 ); |
| 1375 |
|
| 1376 |
# FIXME Is it right? I'd have expected 5 * 2 - 1 instead |
| 1377 |
# Same for the others |
| 1378 |
my $expected_expiration = output_pref( |
| 1379 |
{ |
| 1380 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ), |
| 1381 |
dateformat => 'sql', |
| 1382 |
dateonly => 1 |
| 1383 |
} |
| 1384 |
); |
| 1385 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
| 1386 |
|
| 1387 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, |
| 1388 |
undef, undef, dt_from_string ); |
| 1389 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
| 1390 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1391 |
is( scalar(@$debarments), 1 ); |
| 1392 |
$expected_expiration = output_pref( |
| 1393 |
{ |
| 1394 |
dt => dt_from_string->add( days => ( 10 - 1 ) * 2 ), |
| 1395 |
dateformat => 'sql', |
| 1396 |
dateonly => 1 |
| 1397 |
} |
| 1398 |
); |
| 1399 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
| 1400 |
|
| 1401 |
Koha::Patron::Debarments::DelUniqueDebarment( |
| 1402 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1403 |
|
| 1404 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' ); |
| 1405 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
| 1406 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
| 1407 |
; # Add another overdue |
| 1408 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
| 1409 |
undef, undef, dt_from_string ); |
| 1410 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
| 1411 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1412 |
is( scalar(@$debarments), 1 ); |
| 1413 |
$expected_expiration = output_pref( |
| 1414 |
{ |
| 1415 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ), |
| 1416 |
dateformat => 'sql', |
| 1417 |
dateonly => 1 |
| 1418 |
} |
| 1419 |
); |
| 1420 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
| 1421 |
|
| 1422 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, |
| 1423 |
undef, undef, dt_from_string ); |
| 1424 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
| 1425 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
| 1426 |
is( scalar(@$debarments), 1 ); |
| 1427 |
$expected_expiration = output_pref( |
| 1428 |
{ |
| 1429 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), |
| 1430 |
dateformat => 'sql', |
| 1431 |
dateonly => 1 |
| 1432 |
} |
| 1433 |
); |
| 1434 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
| 1435 |
}; |
| 1436 |
|
| 1309 |
sub set_userenv { |
1437 |
sub set_userenv { |
| 1310 |
my ( $library ) = @_; |
1438 |
my ( $library ) = @_; |
| 1311 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
1439 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
| 1312 |
- |
|
|