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 => 47; |
21 |
use Test::More tests => 50; |
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 277-283
Koha::CirculationRules->set_rules(
Link Here
|
277 |
|
277 |
|
278 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
278 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
279 |
subtest "CanBookBeRenewed tests" => sub { |
279 |
subtest "CanBookBeRenewed tests" => sub { |
280 |
plan tests => 83; |
280 |
plan tests => 87; |
281 |
|
281 |
|
282 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
282 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
283 |
# Generate test biblio |
283 |
# Generate test biblio |
Lines 1260-1265
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
1260 |
$item_3->itemcallnumber || '' ), |
1260 |
$item_3->itemcallnumber || '' ), |
1261 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1261 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1262 |
); |
1262 |
); |
|
|
1263 |
|
1264 |
# Recalls |
1265 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
1266 |
Koha::CirculationRules->set_rules({ |
1267 |
categorycode => undef, |
1268 |
branchcode => undef, |
1269 |
itemtype => undef, |
1270 |
rules => { |
1271 |
recalls_allowed => 10, |
1272 |
renewalsallowed => 5, |
1273 |
}, |
1274 |
}); |
1275 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
1276 |
my $recall_biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
1277 |
my $recall_item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1278 |
my $recall_item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1279 |
|
1280 |
AddIssue( $renewing_borrower, $recall_item1->barcode ); |
1281 |
|
1282 |
# item-level and this item: renewal not allowed |
1283 |
my $recall = Koha::Recall->new({ |
1284 |
biblionumber => $recall_item1->biblionumber, |
1285 |
itemnumber => $recall_item1->itemnumber, |
1286 |
borrowernumber => $recall_borrower->borrowernumber, |
1287 |
branchcode => $recall_borrower->branchcode, |
1288 |
item_level_recall => 1, |
1289 |
status => 'R', |
1290 |
})->store; |
1291 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1292 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
1293 |
$recall->set_cancelled; |
1294 |
|
1295 |
# biblio-level requested recall: renewal not allowed |
1296 |
$recall = Koha::Recall->new({ |
1297 |
biblionumber => $recall_item1->biblionumber, |
1298 |
itemnumber => undef, |
1299 |
borrowernumber => $recall_borrower->borrowernumber, |
1300 |
branchcode => $recall_borrower->branchcode, |
1301 |
item_level_recall => 0, |
1302 |
status => 'R', |
1303 |
})->store; |
1304 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1305 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
1306 |
$recall->set_cancelled; |
1307 |
|
1308 |
# item-level and not this item: renewal allowed |
1309 |
$recall = Koha::Recall->new({ |
1310 |
biblionumber => $recall_item2->biblionumber, |
1311 |
itemnumber => $recall_item2->itemnumber, |
1312 |
borrowernumber => $recall_borrower->borrowernumber, |
1313 |
branchcode => $recall_borrower->branchcode, |
1314 |
item_level_recall => 1, |
1315 |
status => 'R', |
1316 |
})->store; |
1317 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1318 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
1319 |
$recall->set_cancelled; |
1320 |
|
1321 |
# biblio-level waiting recall: renewal allowed |
1322 |
$recall = Koha::Recall->new({ |
1323 |
biblionumber => $recall_item1->biblionumber, |
1324 |
itemnumber => undef, |
1325 |
borrowernumber => $recall_borrower->borrowernumber, |
1326 |
branchcode => $recall_borrower->branchcode, |
1327 |
item_level_recall => 0, |
1328 |
status => 'R', |
1329 |
})->store; |
1330 |
$recall->set_waiting({ item => $recall_item1 }); |
1331 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1332 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
1333 |
$recall->set_cancelled; |
1263 |
}; |
1334 |
}; |
1264 |
|
1335 |
|
1265 |
subtest "GetUpcomingDueIssues" => sub { |
1336 |
subtest "GetUpcomingDueIssues" => sub { |
Lines 1740-1745
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1740 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1811 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1741 |
}; |
1812 |
}; |
1742 |
|
1813 |
|
|
|
1814 |
subtest 'AddIssue | recalls' => sub { |
1815 |
plan tests => 3; |
1816 |
|
1817 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
1818 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
1819 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
1820 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
1821 |
my $item = $builder->build_sample_item; |
1822 |
Koha::CirculationRules->set_rules({ |
1823 |
branchcode => undef, |
1824 |
itemtype => undef, |
1825 |
categorycode => undef, |
1826 |
rules => { |
1827 |
recalls_allowed => 10, |
1828 |
}, |
1829 |
}); |
1830 |
|
1831 |
# checking out item that they have recalled |
1832 |
my $recall1 = Koha::Recall->new({ |
1833 |
borrowernumber => $patron1->borrowernumber, |
1834 |
biblionumber => $item->biblionumber, |
1835 |
itemnumber => $item->itemnumber, |
1836 |
item_level_recall => 1, |
1837 |
branchcode => $patron1->branchcode, |
1838 |
status => 'R', |
1839 |
})->store; |
1840 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->recall_id } ); |
1841 |
$recall1 = Koha::Recalls->find( $recall1->recall_id ); |
1842 |
is( $recall1->finished, 1, 'Recall was fulfilled when patron checked out item' ); |
1843 |
AddReturn( $item->barcode, $item->homebranch ); |
1844 |
|
1845 |
# this item is has a recall request. cancel recall |
1846 |
my $recall2 = Koha::Recall->new({ |
1847 |
borrowernumber => $patron2->borrowernumber, |
1848 |
biblionumber => $item->biblionumber, |
1849 |
itemnumber => $item->itemnumber, |
1850 |
item_level_recall => 1, |
1851 |
branchcode => $patron2->branchcode, |
1852 |
status => 'R', |
1853 |
})->store; |
1854 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->recall_id, cancel_recall => 'cancel' } ); |
1855 |
$recall2 = Koha::Recalls->find( $recall2->recall_id ); |
1856 |
is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' ); |
1857 |
AddReturn( $item->barcode, $item->homebranch ); |
1858 |
|
1859 |
# this item is waiting to fulfill a recall. revert recall |
1860 |
my $recall3 = Koha::Recall->new({ |
1861 |
borrowernumber => $patron2->borrowernumber, |
1862 |
biblionumber => $item->biblionumber, |
1863 |
itemnumber => $item->itemnumber, |
1864 |
item_level_recall => 1, |
1865 |
branchcode => $patron2->branchcode, |
1866 |
status => 'R', |
1867 |
})->store; |
1868 |
$recall3->set_waiting; |
1869 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->recall_id, cancel_recall => 'revert' } ); |
1870 |
$recall3 = Koha::Recalls->find( $recall3->recall_id ); |
1871 |
is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' ); |
1872 |
AddReturn( $item->barcode, $item->homebranch ); |
1873 |
}; |
1874 |
|
1875 |
|
1743 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1876 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1744 |
plan tests => 8; |
1877 |
plan tests => 8; |
1745 |
|
1878 |
|
Lines 3587-3592
subtest 'CanBookBeIssued | notforloan' => sub {
Link Here
|
3587 |
# TODO test with AllowNotForLoanOverride = 1 |
3720 |
# TODO test with AllowNotForLoanOverride = 1 |
3588 |
}; |
3721 |
}; |
3589 |
|
3722 |
|
|
|
3723 |
subtest 'CanBookBeIssued | recalls' => sub { |
3724 |
plan tests => 2; |
3725 |
|
3726 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3727 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3728 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3729 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3730 |
my $item = $builder->build_sample_item; |
3731 |
Koha::CirculationRules->set_rules({ |
3732 |
branchcode => undef, |
3733 |
itemtype => undef, |
3734 |
categorycode => undef, |
3735 |
rules => { |
3736 |
recalls_allowed => 10, |
3737 |
}, |
3738 |
}); |
3739 |
|
3740 |
# item-level recall |
3741 |
my $recall = Koha::Recall->new({ |
3742 |
borrowernumber => $patron1->borrowernumber, |
3743 |
biblionumber => $item->biblionumber, |
3744 |
itemnumber => $item->itemnumber, |
3745 |
item_level_recall => 1, |
3746 |
branchcode => $patron1->branchcode, |
3747 |
status => 'R', |
3748 |
})->store; |
3749 |
|
3750 |
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3751 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed an item-level recall on this item" ); |
3752 |
|
3753 |
$recall->set_cancelled; |
3754 |
|
3755 |
# biblio-level recall |
3756 |
$recall = Koha::Recall->new({ |
3757 |
borrowernumber => $patron1->borrowernumber, |
3758 |
biblionumber => $item->biblionumber, |
3759 |
itemnumber => undef, |
3760 |
item_level_recall => 0, |
3761 |
branchcode => $patron1->branchcode, |
3762 |
status => 'R', |
3763 |
})->store; |
3764 |
|
3765 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3766 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed a biblio-level recall and this item is eligible to fill it" ); |
3767 |
|
3768 |
$recall->set_cancelled; |
3769 |
}; |
3770 |
|
3590 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3771 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3591 |
plan tests => 1; |
3772 |
plan tests => 1; |
3592 |
|
3773 |
|
Lines 3602-3607
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
3602 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3783 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3603 |
}; |
3784 |
}; |
3604 |
|
3785 |
|
|
|
3786 |
subtest 'AddReturn | recalls' => sub { |
3787 |
plan tests => 3; |
3788 |
|
3789 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3790 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3791 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3792 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3793 |
my $item1 = $builder->build_sample_item; |
3794 |
Koha::CirculationRules->set_rules({ |
3795 |
branchcode => undef, |
3796 |
itemtype => undef, |
3797 |
categorycode => undef, |
3798 |
rules => { |
3799 |
recalls_allowed => 10, |
3800 |
}, |
3801 |
}); |
3802 |
|
3803 |
# this item can fill a recall with pickup at this branch |
3804 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3805 |
my $recall1 = Koha::Recall->new({ |
3806 |
borrowernumber => $patron2->borrowernumber, |
3807 |
biblionumber => $item1->biblionumber, |
3808 |
itemnumber => $item1->itemnumber, |
3809 |
item_level_recall => 1, |
3810 |
branchcode => $item1->homebranch, |
3811 |
status => 'R', |
3812 |
})->store; |
3813 |
my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3814 |
is( $messages->{RecallFound}->recall_id, $recall1->recall_id, "Recall found" ); |
3815 |
$recall1->set_cancelled; |
3816 |
|
3817 |
# this item can fill a recall but needs transfer |
3818 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3819 |
$recall1 = Koha::Recall->new({ |
3820 |
borrowernumber => $patron2->borrowernumber, |
3821 |
biblionumber => $item1->biblionumber, |
3822 |
itemnumber => $item1->itemnumber, |
3823 |
item_level_recall => 1, |
3824 |
branchcode => $patron2->branchcode, |
3825 |
status => 'R', |
3826 |
})->store; |
3827 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3828 |
is( $messages->{RecallNeedsTransfer}, $item1->homebranch, "Recall requiring transfer found" ); |
3829 |
$recall1->set_cancelled; |
3830 |
|
3831 |
# this item is already in transit, do not ask to transfer |
3832 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3833 |
$recall1 = Koha::Recall->new({ |
3834 |
borrowernumber => $patron2->borrowernumber, |
3835 |
biblionumber => $item1->biblionumber, |
3836 |
itemnumber => $item1->itemnumber, |
3837 |
item_level_recall => 1, |
3838 |
branchcode => $patron2->branchcode, |
3839 |
status => 'R', |
3840 |
})->store; |
3841 |
$recall1->start_transfer; |
3842 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $patron2->branchcode ); |
3843 |
is( $messages->{TransferredRecall}->recall_id, $recall1->recall_id, "In transit recall found" ); |
3844 |
$recall1->set_cancelled; |
3845 |
}; |
3605 |
|
3846 |
|
3606 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3847 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3607 |
|
3848 |
|