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 1414-1419
subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub {
Link Here
|
1414 |
is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' ); |
1415 |
is( keys(%$error) + keys(%$question) + keys(%$alerts), 0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' ); |
1415 |
}; |
1416 |
}; |
1416 |
|
1417 |
|
|
|
1418 |
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { |
1419 |
plan tests => 8; |
1420 |
|
1421 |
my $library = $builder->build( { source => 'Branch' } ); |
1422 |
my $patron = $builder->build( { source => 'Borrower' } ); |
1423 |
|
1424 |
# Add 2 items |
1425 |
my $biblioitem_1 = $builder->build( { source => 'Biblioitem' } ); |
1426 |
my $item_1 = $builder->build( |
1427 |
{ |
1428 |
source => 'Item', |
1429 |
value => { |
1430 |
homebranch => $library->{branchcode}, |
1431 |
holdingbranch => $library->{branchcode}, |
1432 |
notforloan => 0, |
1433 |
itemlost => 0, |
1434 |
withdrawn => 0, |
1435 |
biblionumber => $biblioitem_1->{biblionumber} |
1436 |
} |
1437 |
} |
1438 |
); |
1439 |
my $biblioitem_2 = $builder->build( { source => 'Biblioitem' } ); |
1440 |
my $item_2 = $builder->build( |
1441 |
{ |
1442 |
source => 'Item', |
1443 |
value => { |
1444 |
homebranch => $library->{branchcode}, |
1445 |
holdingbranch => $library->{branchcode}, |
1446 |
notforloan => 0, |
1447 |
itemlost => 0, |
1448 |
withdrawn => 0, |
1449 |
biblionumber => $biblioitem_2->{biblionumber} |
1450 |
} |
1451 |
} |
1452 |
); |
1453 |
|
1454 |
# And the issuing rule |
1455 |
Koha::IssuingRules->search->delete; |
1456 |
my $rule = Koha::IssuingRule->new( |
1457 |
{ |
1458 |
categorycode => '*', |
1459 |
itemtype => '*', |
1460 |
branchcode => '*', |
1461 |
maxissueqty => 99, |
1462 |
issuelength => 1, |
1463 |
firstremind => 1, # 1 day of grace |
1464 |
finedays => 2, # 2 days of fine per day of overdue |
1465 |
lengthunit => 'days', |
1466 |
} |
1467 |
); |
1468 |
$rule->store(); |
1469 |
|
1470 |
# Patron cannot issue item_1, he has overdues |
1471 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
1472 |
my $ten_days_ago = dt_from_string->subtract( days => 10 ); |
1473 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1474 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
1475 |
; # Add another overdue |
1476 |
|
1477 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); |
1478 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
1479 |
undef, undef, dt_from_string ); |
1480 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
1481 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1482 |
is( scalar(@$debarments), 1 ); |
1483 |
|
1484 |
# FIXME Is it right? I'd have expected 5 * 2 - 1 instead |
1485 |
# Same for the others |
1486 |
my $expected_expiration = output_pref( |
1487 |
{ |
1488 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ), |
1489 |
dateformat => 'sql', |
1490 |
dateonly => 1 |
1491 |
} |
1492 |
); |
1493 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1494 |
|
1495 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, |
1496 |
undef, undef, dt_from_string ); |
1497 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1498 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1499 |
is( scalar(@$debarments), 1 ); |
1500 |
$expected_expiration = output_pref( |
1501 |
{ |
1502 |
dt => dt_from_string->add( days => ( 10 - 1 ) * 2 ), |
1503 |
dateformat => 'sql', |
1504 |
dateonly => 1 |
1505 |
} |
1506 |
); |
1507 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1508 |
|
1509 |
Koha::Patron::Debarments::DelUniqueDebarment( |
1510 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1511 |
|
1512 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' ); |
1513 |
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue |
1514 |
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) |
1515 |
; # Add another overdue |
1516 |
AddReturn( $item_1->{barcode}, $library->{branchcode}, |
1517 |
undef, undef, dt_from_string ); |
1518 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1519 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1520 |
is( scalar(@$debarments), 1 ); |
1521 |
$expected_expiration = output_pref( |
1522 |
{ |
1523 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 ), |
1524 |
dateformat => 'sql', |
1525 |
dateonly => 1 |
1526 |
} |
1527 |
); |
1528 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1529 |
|
1530 |
AddReturn( $item_2->{barcode}, $library->{branchcode}, |
1531 |
undef, undef, dt_from_string ); |
1532 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
1533 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
1534 |
is( scalar(@$debarments), 1 ); |
1535 |
$expected_expiration = output_pref( |
1536 |
{ |
1537 |
dt => dt_from_string->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), |
1538 |
dateformat => 'sql', |
1539 |
dateonly => 1 |
1540 |
} |
1541 |
); |
1542 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
1543 |
}; |
1544 |
|
1417 |
sub set_userenv { |
1545 |
sub set_userenv { |
1418 |
my ( $library ) = @_; |
1546 |
my ( $library ) = @_; |
1419 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
1547 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
1420 |
- |
|
|