Lines 18-24
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
use utf8; |
19 |
use utf8; |
20 |
|
20 |
|
21 |
use Test::More tests => 57; |
21 |
use Test::More tests => 60; |
22 |
use Test::Exception; |
22 |
use Test::Exception; |
23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
24 |
use Test::Deep qw( cmp_deeply ); |
24 |
use Test::Deep qw( cmp_deeply ); |
Lines 418-424
subtest "GetIssuingCharges tests" => sub {
Link Here
|
418 |
|
418 |
|
419 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
419 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
420 |
subtest "CanBookBeRenewed tests" => sub { |
420 |
subtest "CanBookBeRenewed tests" => sub { |
421 |
plan tests => 93; |
421 |
plan tests => 97; |
422 |
|
422 |
|
423 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
423 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
424 |
# Generate test biblio |
424 |
# Generate test biblio |
Lines 1429-1434
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
1429 |
$item_3->itemcallnumber || '' ), |
1429 |
$item_3->itemcallnumber || '' ), |
1430 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1430 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1431 |
); |
1431 |
); |
|
|
1432 |
|
1433 |
# Recalls |
1434 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
1435 |
Koha::CirculationRules->set_rules({ |
1436 |
categorycode => undef, |
1437 |
branchcode => undef, |
1438 |
itemtype => undef, |
1439 |
rules => { |
1440 |
recalls_allowed => 10, |
1441 |
renewalsallowed => 5, |
1442 |
}, |
1443 |
}); |
1444 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
1445 |
my $recall_biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
1446 |
my $recall_item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1447 |
my $recall_item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1448 |
|
1449 |
AddIssue( $renewing_borrower, $recall_item1->barcode ); |
1450 |
|
1451 |
# item-level and this item: renewal not allowed |
1452 |
my $recall = Koha::Recall->new({ |
1453 |
biblionumber => $recall_item1->biblionumber, |
1454 |
itemnumber => $recall_item1->itemnumber, |
1455 |
borrowernumber => $recall_borrower->borrowernumber, |
1456 |
branchcode => $recall_borrower->branchcode, |
1457 |
item_level_recall => 1, |
1458 |
status => 'R', |
1459 |
})->store; |
1460 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1461 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
1462 |
$recall->set_cancelled; |
1463 |
|
1464 |
# biblio-level requested recall: renewal not allowed |
1465 |
$recall = Koha::Recall->new({ |
1466 |
biblionumber => $recall_item1->biblionumber, |
1467 |
itemnumber => undef, |
1468 |
borrowernumber => $recall_borrower->borrowernumber, |
1469 |
branchcode => $recall_borrower->branchcode, |
1470 |
item_level_recall => 0, |
1471 |
status => 'R', |
1472 |
})->store; |
1473 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1474 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
1475 |
$recall->set_cancelled; |
1476 |
|
1477 |
# item-level and not this item: renewal allowed |
1478 |
$recall = Koha::Recall->new({ |
1479 |
biblionumber => $recall_item2->biblionumber, |
1480 |
itemnumber => $recall_item2->itemnumber, |
1481 |
borrowernumber => $recall_borrower->borrowernumber, |
1482 |
branchcode => $recall_borrower->branchcode, |
1483 |
item_level_recall => 1, |
1484 |
status => 'R', |
1485 |
})->store; |
1486 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1487 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
1488 |
$recall->set_cancelled; |
1489 |
|
1490 |
# biblio-level waiting recall: renewal allowed |
1491 |
$recall = Koha::Recall->new({ |
1492 |
biblionumber => $recall_item1->biblionumber, |
1493 |
itemnumber => undef, |
1494 |
borrowernumber => $recall_borrower->borrowernumber, |
1495 |
branchcode => $recall_borrower->branchcode, |
1496 |
item_level_recall => 0, |
1497 |
status => 'R', |
1498 |
})->store; |
1499 |
$recall->set_waiting({ item => $recall_item1 }); |
1500 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1501 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
1502 |
$recall->set_cancelled; |
1432 |
}; |
1503 |
}; |
1433 |
|
1504 |
|
1434 |
subtest "GetUpcomingDueIssues" => sub { |
1505 |
subtest "GetUpcomingDueIssues" => sub { |
Lines 1909-1914
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1909 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1980 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1910 |
}; |
1981 |
}; |
1911 |
|
1982 |
|
|
|
1983 |
subtest 'AddIssue | recalls' => sub { |
1984 |
plan tests => 3; |
1985 |
|
1986 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
1987 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
1988 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
1989 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
1990 |
my $item = $builder->build_sample_item; |
1991 |
Koha::CirculationRules->set_rules({ |
1992 |
branchcode => undef, |
1993 |
itemtype => undef, |
1994 |
categorycode => undef, |
1995 |
rules => { |
1996 |
recalls_allowed => 10, |
1997 |
}, |
1998 |
}); |
1999 |
|
2000 |
# checking out item that they have recalled |
2001 |
my $recall1 = Koha::Recall->new({ |
2002 |
borrowernumber => $patron1->borrowernumber, |
2003 |
biblionumber => $item->biblionumber, |
2004 |
itemnumber => $item->itemnumber, |
2005 |
item_level_recall => 1, |
2006 |
branchcode => $patron1->branchcode, |
2007 |
status => 'R', |
2008 |
})->store; |
2009 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->recall_id } ); |
2010 |
$recall1 = Koha::Recalls->find( $recall1->recall_id ); |
2011 |
is( $recall1->finished, 1, 'Recall was fulfilled when patron checked out item' ); |
2012 |
AddReturn( $item->barcode, $item->homebranch ); |
2013 |
|
2014 |
# this item is has a recall request. cancel recall |
2015 |
my $recall2 = Koha::Recall->new({ |
2016 |
borrowernumber => $patron2->borrowernumber, |
2017 |
biblionumber => $item->biblionumber, |
2018 |
itemnumber => $item->itemnumber, |
2019 |
item_level_recall => 1, |
2020 |
branchcode => $patron2->branchcode, |
2021 |
status => 'R', |
2022 |
})->store; |
2023 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->recall_id, cancel_recall => 'cancel' } ); |
2024 |
$recall2 = Koha::Recalls->find( $recall2->recall_id ); |
2025 |
is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' ); |
2026 |
AddReturn( $item->barcode, $item->homebranch ); |
2027 |
|
2028 |
# this item is waiting to fulfill a recall. revert recall |
2029 |
my $recall3 = Koha::Recall->new({ |
2030 |
borrowernumber => $patron2->borrowernumber, |
2031 |
biblionumber => $item->biblionumber, |
2032 |
itemnumber => $item->itemnumber, |
2033 |
item_level_recall => 1, |
2034 |
branchcode => $patron2->branchcode, |
2035 |
status => 'R', |
2036 |
})->store; |
2037 |
$recall3->set_waiting; |
2038 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->recall_id, cancel_recall => 'revert' } ); |
2039 |
$recall3 = Koha::Recalls->find( $recall3->recall_id ); |
2040 |
is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' ); |
2041 |
AddReturn( $item->barcode, $item->homebranch ); |
2042 |
}; |
2043 |
|
2044 |
|
1912 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
2045 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1913 |
plan tests => 8; |
2046 |
plan tests => 8; |
1914 |
|
2047 |
|
Lines 3827-3832
subtest 'CanBookBeIssued | notforloan' => sub {
Link Here
|
3827 |
# TODO test with AllowNotForLoanOverride = 1 |
3960 |
# TODO test with AllowNotForLoanOverride = 1 |
3828 |
}; |
3961 |
}; |
3829 |
|
3962 |
|
|
|
3963 |
subtest 'CanBookBeIssued | recalls' => sub { |
3964 |
plan tests => 3; |
3965 |
|
3966 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3967 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3968 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3969 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3970 |
my $item = $builder->build_sample_item; |
3971 |
Koha::CirculationRules->set_rules({ |
3972 |
branchcode => undef, |
3973 |
itemtype => undef, |
3974 |
categorycode => undef, |
3975 |
rules => { |
3976 |
recalls_allowed => 10, |
3977 |
}, |
3978 |
}); |
3979 |
|
3980 |
# item-level recall |
3981 |
my $recall = Koha::Recall->new({ |
3982 |
borrowernumber => $patron1->borrowernumber, |
3983 |
biblionumber => $item->biblionumber, |
3984 |
itemnumber => $item->itemnumber, |
3985 |
item_level_recall => 1, |
3986 |
branchcode => $patron1->branchcode, |
3987 |
status => 'R', |
3988 |
})->store; |
3989 |
|
3990 |
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3991 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed an item-level recall on this item" ); |
3992 |
|
3993 |
$recall->set_cancelled; |
3994 |
|
3995 |
# biblio-level recall |
3996 |
$recall = Koha::Recall->new({ |
3997 |
borrowernumber => $patron1->borrowernumber, |
3998 |
biblionumber => $item->biblionumber, |
3999 |
itemnumber => undef, |
4000 |
item_level_recall => 0, |
4001 |
branchcode => $patron1->branchcode, |
4002 |
status => 'R', |
4003 |
})->store; |
4004 |
|
4005 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
4006 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed a biblio-level recall and this item is eligible to fill it" ); |
4007 |
|
4008 |
$recall->set_cancelled; |
4009 |
|
4010 |
# biblio-level recall |
4011 |
$recall = Koha::Recall->new({ |
4012 |
borrowernumber => $patron1->borrowernumber, |
4013 |
biblionumber => $item->biblionumber, |
4014 |
itemnumber => undef, |
4015 |
item_level_recall => 0, |
4016 |
branchcode => $patron1->branchcode, |
4017 |
status => 'R', |
4018 |
})->store; |
4019 |
$recall->set_waiting({ item => $item, expirationdate => dt_from_string() }); |
4020 |
|
4021 |
my ( undef, undef, undef, $messages ) = CanBookBeIssued( $patron1, $item->barcode, undef, undef, undef, undef ); |
4022 |
is( $messages->{RECALLED}, $recall->recall_id, "This book can be issued by this patron and they have placed a recall" ); |
4023 |
|
4024 |
$recall->set_cancelled; |
4025 |
}; |
4026 |
|
3830 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
4027 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3831 |
plan tests => 1; |
4028 |
plan tests => 1; |
3832 |
|
4029 |
|
Lines 3842-3847
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
3842 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
4039 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3843 |
}; |
4040 |
}; |
3844 |
|
4041 |
|
|
|
4042 |
subtest 'AddReturn | recalls' => sub { |
4043 |
plan tests => 3; |
4044 |
|
4045 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
4046 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
4047 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
4048 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
4049 |
my $item1 = $builder->build_sample_item; |
4050 |
Koha::CirculationRules->set_rules({ |
4051 |
branchcode => undef, |
4052 |
itemtype => undef, |
4053 |
categorycode => undef, |
4054 |
rules => { |
4055 |
recalls_allowed => 10, |
4056 |
}, |
4057 |
}); |
4058 |
|
4059 |
# this item can fill a recall with pickup at this branch |
4060 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
4061 |
my $recall1 = Koha::Recall->new({ |
4062 |
borrowernumber => $patron2->borrowernumber, |
4063 |
biblionumber => $item1->biblionumber, |
4064 |
itemnumber => $item1->itemnumber, |
4065 |
item_level_recall => 1, |
4066 |
branchcode => $item1->homebranch, |
4067 |
status => 'R', |
4068 |
})->store; |
4069 |
my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
4070 |
is( $messages->{RecallFound}->recall_id, $recall1->recall_id, "Recall found" ); |
4071 |
$recall1->set_cancelled; |
4072 |
|
4073 |
# this item can fill a recall but needs transfer |
4074 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
4075 |
$recall1 = Koha::Recall->new({ |
4076 |
borrowernumber => $patron2->borrowernumber, |
4077 |
biblionumber => $item1->biblionumber, |
4078 |
itemnumber => $item1->itemnumber, |
4079 |
item_level_recall => 1, |
4080 |
branchcode => $patron2->branchcode, |
4081 |
status => 'R', |
4082 |
})->store; |
4083 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
4084 |
is( $messages->{RecallNeedsTransfer}, $item1->homebranch, "Recall requiring transfer found" ); |
4085 |
$recall1->set_cancelled; |
4086 |
|
4087 |
# this item is already in transit, do not ask to transfer |
4088 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
4089 |
$recall1 = Koha::Recall->new({ |
4090 |
borrowernumber => $patron2->borrowernumber, |
4091 |
biblionumber => $item1->biblionumber, |
4092 |
itemnumber => $item1->itemnumber, |
4093 |
item_level_recall => 1, |
4094 |
branchcode => $patron2->branchcode, |
4095 |
status => 'R', |
4096 |
})->store; |
4097 |
$recall1->start_transfer; |
4098 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $patron2->branchcode ); |
4099 |
is( $messages->{TransferredRecall}->recall_id, $recall1->recall_id, "In transit recall found" ); |
4100 |
$recall1->set_cancelled; |
4101 |
}; |
3845 |
|
4102 |
|
3846 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
4103 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3847 |
|
4104 |
|