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 => 48; |
21 |
use Test::More tests => 51; |
22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
23 |
use Test::Deep qw( cmp_deeply ); |
23 |
use Test::Deep qw( cmp_deeply ); |
24 |
|
24 |
|
Lines 273-279
Koha::CirculationRules->set_rules(
Link Here
|
273 |
|
273 |
|
274 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
274 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
275 |
subtest "CanBookBeRenewed tests" => sub { |
275 |
subtest "CanBookBeRenewed tests" => sub { |
276 |
plan tests => 83; |
276 |
plan tests => 87; |
277 |
|
277 |
|
278 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
278 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
279 |
# Generate test biblio |
279 |
# Generate test biblio |
Lines 1256-1261
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
1256 |
$item_3->itemcallnumber || '' ), |
1256 |
$item_3->itemcallnumber || '' ), |
1257 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1257 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1258 |
); |
1258 |
); |
|
|
1259 |
|
1260 |
# Recalls |
1261 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
1262 |
Koha::CirculationRules->set_rules({ |
1263 |
categorycode => undef, |
1264 |
branchcode => undef, |
1265 |
itemtype => undef, |
1266 |
rules => { |
1267 |
recalls_allowed => 10, |
1268 |
renewalsallowed => 5, |
1269 |
}, |
1270 |
}); |
1271 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
1272 |
my $recall_biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
1273 |
my $recall_item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1274 |
my $recall_item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1275 |
|
1276 |
AddIssue( $renewing_borrower, $recall_item1->barcode ); |
1277 |
|
1278 |
# item-level and this item: renewal not allowed |
1279 |
my $recall = Koha::Recall->new({ |
1280 |
biblionumber => $recall_item1->biblionumber, |
1281 |
itemnumber => $recall_item1->itemnumber, |
1282 |
borrowernumber => $recall_borrower->borrowernumber, |
1283 |
branchcode => $recall_borrower->branchcode, |
1284 |
item_level_recall => 1, |
1285 |
status => 'R', |
1286 |
})->store; |
1287 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1288 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
1289 |
$recall->set_cancelled; |
1290 |
|
1291 |
# biblio-level requested recall: renewal not allowed |
1292 |
$recall = Koha::Recall->new({ |
1293 |
biblionumber => $recall_item1->biblionumber, |
1294 |
itemnumber => undef, |
1295 |
borrowernumber => $recall_borrower->borrowernumber, |
1296 |
branchcode => $recall_borrower->branchcode, |
1297 |
item_level_recall => 0, |
1298 |
status => 'R', |
1299 |
})->store; |
1300 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1301 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
1302 |
$recall->set_cancelled; |
1303 |
|
1304 |
# item-level and not this item: renewal allowed |
1305 |
$recall = Koha::Recall->new({ |
1306 |
biblionumber => $recall_item2->biblionumber, |
1307 |
itemnumber => $recall_item2->itemnumber, |
1308 |
borrowernumber => $recall_borrower->borrowernumber, |
1309 |
branchcode => $recall_borrower->branchcode, |
1310 |
item_level_recall => 1, |
1311 |
status => 'R', |
1312 |
})->store; |
1313 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1314 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
1315 |
$recall->set_cancelled; |
1316 |
|
1317 |
# biblio-level waiting recall: renewal allowed |
1318 |
$recall = Koha::Recall->new({ |
1319 |
biblionumber => $recall_item1->biblionumber, |
1320 |
itemnumber => undef, |
1321 |
borrowernumber => $recall_borrower->borrowernumber, |
1322 |
branchcode => $recall_borrower->branchcode, |
1323 |
item_level_recall => 0, |
1324 |
status => 'R', |
1325 |
})->store; |
1326 |
$recall->set_waiting({ item => $recall_item1 }); |
1327 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1328 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
1329 |
$recall->set_cancelled; |
1259 |
}; |
1330 |
}; |
1260 |
|
1331 |
|
1261 |
subtest "GetUpcomingDueIssues" => sub { |
1332 |
subtest "GetUpcomingDueIssues" => sub { |
Lines 1736-1741
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1736 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1807 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1737 |
}; |
1808 |
}; |
1738 |
|
1809 |
|
|
|
1810 |
subtest 'AddIssue | recalls' => sub { |
1811 |
plan tests => 3; |
1812 |
|
1813 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
1814 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
1815 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
1816 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
1817 |
my $item = $builder->build_sample_item; |
1818 |
Koha::CirculationRules->set_rules({ |
1819 |
branchcode => undef, |
1820 |
itemtype => undef, |
1821 |
categorycode => undef, |
1822 |
rules => { |
1823 |
recalls_allowed => 10, |
1824 |
}, |
1825 |
}); |
1826 |
|
1827 |
# checking out item that they have recalled |
1828 |
my $recall1 = Koha::Recall->new({ |
1829 |
borrowernumber => $patron1->borrowernumber, |
1830 |
biblionumber => $item->biblionumber, |
1831 |
itemnumber => $item->itemnumber, |
1832 |
item_level_recall => 1, |
1833 |
branchcode => $patron1->branchcode, |
1834 |
status => 'R', |
1835 |
})->store; |
1836 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->recall_id } ); |
1837 |
$recall1 = Koha::Recalls->find( $recall1->recall_id ); |
1838 |
is( $recall1->finished, 1, 'Recall was fulfilled when patron checked out item' ); |
1839 |
AddReturn( $item->barcode, $item->homebranch ); |
1840 |
|
1841 |
# this item is has a recall request. cancel recall |
1842 |
my $recall2 = Koha::Recall->new({ |
1843 |
borrowernumber => $patron2->borrowernumber, |
1844 |
biblionumber => $item->biblionumber, |
1845 |
itemnumber => $item->itemnumber, |
1846 |
item_level_recall => 1, |
1847 |
branchcode => $patron2->branchcode, |
1848 |
status => 'R', |
1849 |
})->store; |
1850 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->recall_id, cancel_recall => 'cancel' } ); |
1851 |
$recall2 = Koha::Recalls->find( $recall2->recall_id ); |
1852 |
is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' ); |
1853 |
AddReturn( $item->barcode, $item->homebranch ); |
1854 |
|
1855 |
# this item is waiting to fulfill a recall. revert recall |
1856 |
my $recall3 = Koha::Recall->new({ |
1857 |
borrowernumber => $patron2->borrowernumber, |
1858 |
biblionumber => $item->biblionumber, |
1859 |
itemnumber => $item->itemnumber, |
1860 |
item_level_recall => 1, |
1861 |
branchcode => $patron2->branchcode, |
1862 |
status => 'R', |
1863 |
})->store; |
1864 |
$recall3->set_waiting; |
1865 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->recall_id, cancel_recall => 'revert' } ); |
1866 |
$recall3 = Koha::Recalls->find( $recall3->recall_id ); |
1867 |
is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' ); |
1868 |
AddReturn( $item->barcode, $item->homebranch ); |
1869 |
}; |
1870 |
|
1871 |
|
1739 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1872 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1740 |
plan tests => 8; |
1873 |
plan tests => 8; |
1741 |
|
1874 |
|
Lines 3408-3413
subtest 'CanBookBeIssued | notforloan' => sub {
Link Here
|
3408 |
# TODO test with AllowNotForLoanOverride = 1 |
3541 |
# TODO test with AllowNotForLoanOverride = 1 |
3409 |
}; |
3542 |
}; |
3410 |
|
3543 |
|
|
|
3544 |
subtest 'CanBookBeIssued | recalls' => sub { |
3545 |
plan tests => 2; |
3546 |
|
3547 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3548 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3549 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3550 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3551 |
my $item = $builder->build_sample_item; |
3552 |
Koha::CirculationRules->set_rules({ |
3553 |
branchcode => undef, |
3554 |
itemtype => undef, |
3555 |
categorycode => undef, |
3556 |
rules => { |
3557 |
recalls_allowed => 10, |
3558 |
}, |
3559 |
}); |
3560 |
|
3561 |
# item-level recall |
3562 |
my $recall = Koha::Recall->new({ |
3563 |
borrowernumber => $patron1->borrowernumber, |
3564 |
biblionumber => $item->biblionumber, |
3565 |
itemnumber => $item->itemnumber, |
3566 |
item_level_recall => 1, |
3567 |
branchcode => $patron1->branchcode, |
3568 |
status => 'R', |
3569 |
})->store; |
3570 |
|
3571 |
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3572 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed an item-level recall on this item" ); |
3573 |
|
3574 |
$recall->set_cancelled; |
3575 |
|
3576 |
# biblio-level recall |
3577 |
$recall = Koha::Recall->new({ |
3578 |
borrowernumber => $patron1->borrowernumber, |
3579 |
biblionumber => $item->biblionumber, |
3580 |
itemnumber => undef, |
3581 |
item_level_recall => 0, |
3582 |
branchcode => $patron1->branchcode, |
3583 |
status => 'R', |
3584 |
})->store; |
3585 |
|
3586 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3587 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed a biblio-level recall and this item is eligible to fill it" ); |
3588 |
|
3589 |
$recall->set_cancelled; |
3590 |
}; |
3591 |
|
3411 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3592 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3412 |
plan tests => 1; |
3593 |
plan tests => 1; |
3413 |
|
3594 |
|
Lines 3423-3428
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
3423 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3604 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3424 |
}; |
3605 |
}; |
3425 |
|
3606 |
|
|
|
3607 |
subtest 'AddReturn | recalls' => sub { |
3608 |
plan tests => 3; |
3609 |
|
3610 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3611 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3612 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3613 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3614 |
my $item1 = $builder->build_sample_item; |
3615 |
Koha::CirculationRules->set_rules({ |
3616 |
branchcode => undef, |
3617 |
itemtype => undef, |
3618 |
categorycode => undef, |
3619 |
rules => { |
3620 |
recalls_allowed => 10, |
3621 |
}, |
3622 |
}); |
3623 |
|
3624 |
# this item can fill a recall with pickup at this branch |
3625 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3626 |
my $recall1 = Koha::Recall->new({ |
3627 |
borrowernumber => $patron2->borrowernumber, |
3628 |
biblionumber => $item1->biblionumber, |
3629 |
itemnumber => $item1->itemnumber, |
3630 |
item_level_recall => 1, |
3631 |
branchcode => $item1->homebranch, |
3632 |
status => 'R', |
3633 |
})->store; |
3634 |
my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3635 |
is( $messages->{RecallFound}->recall_id, $recall1->recall_id, "Recall found" ); |
3636 |
$recall1->set_cancelled; |
3637 |
|
3638 |
# this item can fill a recall but needs transfer |
3639 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3640 |
$recall1 = Koha::Recall->new({ |
3641 |
borrowernumber => $patron2->borrowernumber, |
3642 |
biblionumber => $item1->biblionumber, |
3643 |
itemnumber => $item1->itemnumber, |
3644 |
item_level_recall => 1, |
3645 |
branchcode => $patron2->branchcode, |
3646 |
status => 'R', |
3647 |
})->store; |
3648 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3649 |
is( $messages->{RecallNeedsTransfer}, $item1->homebranch, "Recall requiring transfer found" ); |
3650 |
$recall1->set_cancelled; |
3651 |
|
3652 |
# this item is already in transit, do not ask to transfer |
3653 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3654 |
$recall1 = Koha::Recall->new({ |
3655 |
borrowernumber => $patron2->borrowernumber, |
3656 |
biblionumber => $item1->biblionumber, |
3657 |
itemnumber => $item1->itemnumber, |
3658 |
item_level_recall => 1, |
3659 |
branchcode => $patron2->branchcode, |
3660 |
status => 'R', |
3661 |
})->store; |
3662 |
$recall1->start_transfer; |
3663 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $patron2->branchcode ); |
3664 |
is( $messages->{TransferredRecall}->recall_id, $recall1->recall_id, "In transit recall found" ); |
3665 |
$recall1->set_cancelled; |
3666 |
}; |
3426 |
|
3667 |
|
3427 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3668 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3428 |
|
3669 |
|