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 => 55; |
21 |
use Test::More tests => 58; |
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 415-421
subtest "GetIssuingCharges tests" => sub {
Link Here
|
415 |
|
415 |
|
416 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
416 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
417 |
subtest "CanBookBeRenewed tests" => sub { |
417 |
subtest "CanBookBeRenewed tests" => sub { |
418 |
plan tests => 95; |
418 |
plan tests => 99; |
419 |
|
419 |
|
420 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
420 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
421 |
# Generate test biblio |
421 |
# Generate test biblio |
Lines 1444-1449
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
1444 |
$item_3->itemcallnumber || '' ), |
1444 |
$item_3->itemcallnumber || '' ), |
1445 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1445 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1446 |
); |
1446 |
); |
|
|
1447 |
|
1448 |
# Recalls |
1449 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
1450 |
Koha::CirculationRules->set_rules({ |
1451 |
categorycode => undef, |
1452 |
branchcode => undef, |
1453 |
itemtype => undef, |
1454 |
rules => { |
1455 |
recalls_allowed => 10, |
1456 |
renewalsallowed => 5, |
1457 |
}, |
1458 |
}); |
1459 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
1460 |
my $recall_biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
1461 |
my $recall_item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1462 |
my $recall_item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1463 |
|
1464 |
AddIssue( $renewing_borrower, $recall_item1->barcode ); |
1465 |
|
1466 |
# item-level and this item: renewal not allowed |
1467 |
my $recall = Koha::Recall->new({ |
1468 |
biblionumber => $recall_item1->biblionumber, |
1469 |
itemnumber => $recall_item1->itemnumber, |
1470 |
borrowernumber => $recall_borrower->borrowernumber, |
1471 |
branchcode => $recall_borrower->branchcode, |
1472 |
item_level_recall => 1, |
1473 |
status => 'R', |
1474 |
})->store; |
1475 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1476 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
1477 |
$recall->set_cancelled; |
1478 |
|
1479 |
# biblio-level requested recall: renewal not allowed |
1480 |
$recall = Koha::Recall->new({ |
1481 |
biblionumber => $recall_item1->biblionumber, |
1482 |
itemnumber => undef, |
1483 |
borrowernumber => $recall_borrower->borrowernumber, |
1484 |
branchcode => $recall_borrower->branchcode, |
1485 |
item_level_recall => 0, |
1486 |
status => 'R', |
1487 |
})->store; |
1488 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1489 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
1490 |
$recall->set_cancelled; |
1491 |
|
1492 |
# item-level and not this item: renewal allowed |
1493 |
$recall = Koha::Recall->new({ |
1494 |
biblionumber => $recall_item2->biblionumber, |
1495 |
itemnumber => $recall_item2->itemnumber, |
1496 |
borrowernumber => $recall_borrower->borrowernumber, |
1497 |
branchcode => $recall_borrower->branchcode, |
1498 |
item_level_recall => 1, |
1499 |
status => 'R', |
1500 |
})->store; |
1501 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1502 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
1503 |
$recall->set_cancelled; |
1504 |
|
1505 |
# biblio-level waiting recall: renewal allowed |
1506 |
$recall = Koha::Recall->new({ |
1507 |
biblionumber => $recall_item1->biblionumber, |
1508 |
itemnumber => undef, |
1509 |
borrowernumber => $recall_borrower->borrowernumber, |
1510 |
branchcode => $recall_borrower->branchcode, |
1511 |
item_level_recall => 0, |
1512 |
status => 'R', |
1513 |
})->store; |
1514 |
$recall->set_waiting({ item => $recall_item1 }); |
1515 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1516 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
1517 |
$recall->set_cancelled; |
1447 |
}; |
1518 |
}; |
1448 |
|
1519 |
|
1449 |
subtest "GetUpcomingDueIssues" => sub { |
1520 |
subtest "GetUpcomingDueIssues" => sub { |
Lines 1924-1929
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1924 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1995 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1925 |
}; |
1996 |
}; |
1926 |
|
1997 |
|
|
|
1998 |
subtest 'AddIssue | recalls' => sub { |
1999 |
plan tests => 3; |
2000 |
|
2001 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
2002 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
2003 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
2004 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
2005 |
my $item = $builder->build_sample_item; |
2006 |
Koha::CirculationRules->set_rules({ |
2007 |
branchcode => undef, |
2008 |
itemtype => undef, |
2009 |
categorycode => undef, |
2010 |
rules => { |
2011 |
recalls_allowed => 10, |
2012 |
}, |
2013 |
}); |
2014 |
|
2015 |
# checking out item that they have recalled |
2016 |
my $recall1 = Koha::Recall->new({ |
2017 |
borrowernumber => $patron1->borrowernumber, |
2018 |
biblionumber => $item->biblionumber, |
2019 |
itemnumber => $item->itemnumber, |
2020 |
item_level_recall => 1, |
2021 |
branchcode => $patron1->branchcode, |
2022 |
status => 'R', |
2023 |
})->store; |
2024 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->recall_id } ); |
2025 |
$recall1 = Koha::Recalls->find( $recall1->recall_id ); |
2026 |
is( $recall1->finished, 1, 'Recall was fulfilled when patron checked out item' ); |
2027 |
AddReturn( $item->barcode, $item->homebranch ); |
2028 |
|
2029 |
# this item is has a recall request. cancel recall |
2030 |
my $recall2 = Koha::Recall->new({ |
2031 |
borrowernumber => $patron2->borrowernumber, |
2032 |
biblionumber => $item->biblionumber, |
2033 |
itemnumber => $item->itemnumber, |
2034 |
item_level_recall => 1, |
2035 |
branchcode => $patron2->branchcode, |
2036 |
status => 'R', |
2037 |
})->store; |
2038 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->recall_id, cancel_recall => 'cancel' } ); |
2039 |
$recall2 = Koha::Recalls->find( $recall2->recall_id ); |
2040 |
is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' ); |
2041 |
AddReturn( $item->barcode, $item->homebranch ); |
2042 |
|
2043 |
# this item is waiting to fulfill a recall. revert recall |
2044 |
my $recall3 = Koha::Recall->new({ |
2045 |
borrowernumber => $patron2->borrowernumber, |
2046 |
biblionumber => $item->biblionumber, |
2047 |
itemnumber => $item->itemnumber, |
2048 |
item_level_recall => 1, |
2049 |
branchcode => $patron2->branchcode, |
2050 |
status => 'R', |
2051 |
})->store; |
2052 |
$recall3->set_waiting; |
2053 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->recall_id, cancel_recall => 'revert' } ); |
2054 |
$recall3 = Koha::Recalls->find( $recall3->recall_id ); |
2055 |
is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' ); |
2056 |
AddReturn( $item->barcode, $item->homebranch ); |
2057 |
}; |
2058 |
|
2059 |
|
1927 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
2060 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1928 |
plan tests => 8; |
2061 |
plan tests => 8; |
1929 |
|
2062 |
|
Lines 3845-3850
subtest 'CanBookBeIssued | notforloan' => sub {
Link Here
|
3845 |
# TODO test with AllowNotForLoanOverride = 1 |
3978 |
# TODO test with AllowNotForLoanOverride = 1 |
3846 |
}; |
3979 |
}; |
3847 |
|
3980 |
|
|
|
3981 |
subtest 'CanBookBeIssued | recalls' => sub { |
3982 |
plan tests => 3; |
3983 |
|
3984 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3985 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3986 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3987 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3988 |
my $item = $builder->build_sample_item; |
3989 |
Koha::CirculationRules->set_rules({ |
3990 |
branchcode => undef, |
3991 |
itemtype => undef, |
3992 |
categorycode => undef, |
3993 |
rules => { |
3994 |
recalls_allowed => 10, |
3995 |
}, |
3996 |
}); |
3997 |
|
3998 |
# item-level recall |
3999 |
my $recall = Koha::Recall->new({ |
4000 |
borrowernumber => $patron1->borrowernumber, |
4001 |
biblionumber => $item->biblionumber, |
4002 |
itemnumber => $item->itemnumber, |
4003 |
item_level_recall => 1, |
4004 |
branchcode => $patron1->branchcode, |
4005 |
status => 'R', |
4006 |
})->store; |
4007 |
|
4008 |
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
4009 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed an item-level recall on this item" ); |
4010 |
|
4011 |
$recall->set_cancelled; |
4012 |
|
4013 |
# biblio-level recall |
4014 |
$recall = Koha::Recall->new({ |
4015 |
borrowernumber => $patron1->borrowernumber, |
4016 |
biblionumber => $item->biblionumber, |
4017 |
itemnumber => undef, |
4018 |
item_level_recall => 0, |
4019 |
branchcode => $patron1->branchcode, |
4020 |
status => 'R', |
4021 |
})->store; |
4022 |
|
4023 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
4024 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed a biblio-level recall and this item is eligible to fill it" ); |
4025 |
|
4026 |
$recall->set_cancelled; |
4027 |
|
4028 |
# biblio-level recall |
4029 |
$recall = Koha::Recall->new({ |
4030 |
borrowernumber => $patron1->borrowernumber, |
4031 |
biblionumber => $item->biblionumber, |
4032 |
itemnumber => undef, |
4033 |
item_level_recall => 0, |
4034 |
branchcode => $patron1->branchcode, |
4035 |
status => 'R', |
4036 |
})->store; |
4037 |
$recall->set_waiting({ item => $item, expirationdate => dt_from_string() }); |
4038 |
|
4039 |
my ( undef, undef, undef, $messages ) = CanBookBeIssued( $patron1, $item->barcode, undef, undef, undef, undef ); |
4040 |
is( $messages->{RECALLED}, $recall->recall_id, "This book can be issued by this patron and they have placed a recall" ); |
4041 |
|
4042 |
$recall->set_cancelled; |
4043 |
}; |
4044 |
|
3848 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
4045 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3849 |
plan tests => 1; |
4046 |
plan tests => 1; |
3850 |
|
4047 |
|
Lines 3860-3865
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
3860 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
4057 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3861 |
}; |
4058 |
}; |
3862 |
|
4059 |
|
|
|
4060 |
subtest 'AddReturn | recalls' => sub { |
4061 |
plan tests => 3; |
4062 |
|
4063 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
4064 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
4065 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
4066 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
4067 |
my $item1 = $builder->build_sample_item; |
4068 |
Koha::CirculationRules->set_rules({ |
4069 |
branchcode => undef, |
4070 |
itemtype => undef, |
4071 |
categorycode => undef, |
4072 |
rules => { |
4073 |
recalls_allowed => 10, |
4074 |
}, |
4075 |
}); |
4076 |
|
4077 |
# this item can fill a recall with pickup at this branch |
4078 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
4079 |
my $recall1 = Koha::Recall->new({ |
4080 |
borrowernumber => $patron2->borrowernumber, |
4081 |
biblionumber => $item1->biblionumber, |
4082 |
itemnumber => $item1->itemnumber, |
4083 |
item_level_recall => 1, |
4084 |
branchcode => $item1->homebranch, |
4085 |
status => 'R', |
4086 |
})->store; |
4087 |
my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
4088 |
is( $messages->{RecallFound}->recall_id, $recall1->recall_id, "Recall found" ); |
4089 |
$recall1->set_cancelled; |
4090 |
|
4091 |
# this item can fill a recall but needs transfer |
4092 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
4093 |
$recall1 = Koha::Recall->new({ |
4094 |
borrowernumber => $patron2->borrowernumber, |
4095 |
biblionumber => $item1->biblionumber, |
4096 |
itemnumber => $item1->itemnumber, |
4097 |
item_level_recall => 1, |
4098 |
branchcode => $patron2->branchcode, |
4099 |
status => 'R', |
4100 |
})->store; |
4101 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
4102 |
is( $messages->{RecallNeedsTransfer}, $item1->homebranch, "Recall requiring transfer found" ); |
4103 |
$recall1->set_cancelled; |
4104 |
|
4105 |
# this item is already in transit, do not ask to transfer |
4106 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
4107 |
$recall1 = Koha::Recall->new({ |
4108 |
borrowernumber => $patron2->borrowernumber, |
4109 |
biblionumber => $item1->biblionumber, |
4110 |
itemnumber => $item1->itemnumber, |
4111 |
item_level_recall => 1, |
4112 |
branchcode => $patron2->branchcode, |
4113 |
status => 'R', |
4114 |
})->store; |
4115 |
$recall1->start_transfer; |
4116 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $patron2->branchcode ); |
4117 |
is( $messages->{TransferredRecall}->recall_id, $recall1->recall_id, "In transit recall found" ); |
4118 |
$recall1->set_cancelled; |
4119 |
}; |
3863 |
|
4120 |
|
3864 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
4121 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3865 |
|
4122 |
|