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::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 278-284
Koha::CirculationRules->set_rules(
Link Here
|
278 |
|
278 |
|
279 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
279 |
my ( $reused_itemnumber_1, $reused_itemnumber_2 ); |
280 |
subtest "CanBookBeRenewed tests" => sub { |
280 |
subtest "CanBookBeRenewed tests" => sub { |
281 |
plan tests => 83; |
281 |
plan tests => 87; |
282 |
|
282 |
|
283 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
283 |
C4::Context->set_preference('ItemsDeniedRenewal',''); |
284 |
# Generate test biblio |
284 |
# Generate test biblio |
Lines 1261-1266
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
1261 |
$item_3->itemcallnumber || '' ), |
1261 |
$item_3->itemcallnumber || '' ), |
1262 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1262 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1263 |
); |
1263 |
); |
|
|
1264 |
|
1265 |
# Recalls |
1266 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
1267 |
Koha::CirculationRules->set_rules({ |
1268 |
categorycode => undef, |
1269 |
branchcode => undef, |
1270 |
itemtype => undef, |
1271 |
rules => { |
1272 |
recalls_allowed => 10, |
1273 |
renewalsallowed => 5, |
1274 |
}, |
1275 |
}); |
1276 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
1277 |
my $recall_biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
1278 |
my $recall_item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1279 |
my $recall_item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1280 |
|
1281 |
AddIssue( $renewing_borrower, $recall_item1->barcode ); |
1282 |
|
1283 |
# item-level and this item: renewal not allowed |
1284 |
my $recall = Koha::Recall->new({ |
1285 |
biblionumber => $recall_item1->biblionumber, |
1286 |
itemnumber => $recall_item1->itemnumber, |
1287 |
borrowernumber => $recall_borrower->borrowernumber, |
1288 |
branchcode => $recall_borrower->branchcode, |
1289 |
item_level_recall => 1, |
1290 |
status => 'R', |
1291 |
})->store; |
1292 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1293 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
1294 |
$recall->set_cancelled; |
1295 |
|
1296 |
# biblio-level requested recall: renewal not allowed |
1297 |
$recall = Koha::Recall->new({ |
1298 |
biblionumber => $recall_item1->biblionumber, |
1299 |
itemnumber => undef, |
1300 |
borrowernumber => $recall_borrower->borrowernumber, |
1301 |
branchcode => $recall_borrower->branchcode, |
1302 |
item_level_recall => 0, |
1303 |
status => 'R', |
1304 |
})->store; |
1305 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1306 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
1307 |
$recall->set_cancelled; |
1308 |
|
1309 |
# item-level and not this item: renewal allowed |
1310 |
$recall = Koha::Recall->new({ |
1311 |
biblionumber => $recall_item2->biblionumber, |
1312 |
itemnumber => $recall_item2->itemnumber, |
1313 |
borrowernumber => $recall_borrower->borrowernumber, |
1314 |
branchcode => $recall_borrower->branchcode, |
1315 |
item_level_recall => 1, |
1316 |
status => 'R', |
1317 |
})->store; |
1318 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1319 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
1320 |
$recall->set_cancelled; |
1321 |
|
1322 |
# biblio-level waiting recall: renewal allowed |
1323 |
$recall = Koha::Recall->new({ |
1324 |
biblionumber => $recall_item1->biblionumber, |
1325 |
itemnumber => undef, |
1326 |
borrowernumber => $recall_borrower->borrowernumber, |
1327 |
branchcode => $recall_borrower->branchcode, |
1328 |
item_level_recall => 0, |
1329 |
status => 'R', |
1330 |
})->store; |
1331 |
$recall->set_waiting({ item => $recall_item1 }); |
1332 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1333 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
1334 |
$recall->set_cancelled; |
1264 |
}; |
1335 |
}; |
1265 |
|
1336 |
|
1266 |
subtest "GetUpcomingDueIssues" => sub { |
1337 |
subtest "GetUpcomingDueIssues" => sub { |
Lines 1741-1746
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1741 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1812 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1742 |
}; |
1813 |
}; |
1743 |
|
1814 |
|
|
|
1815 |
subtest 'AddIssue | recalls' => sub { |
1816 |
plan tests => 3; |
1817 |
|
1818 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
1819 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
1820 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
1821 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
1822 |
my $item = $builder->build_sample_item; |
1823 |
Koha::CirculationRules->set_rules({ |
1824 |
branchcode => undef, |
1825 |
itemtype => undef, |
1826 |
categorycode => undef, |
1827 |
rules => { |
1828 |
recalls_allowed => 10, |
1829 |
}, |
1830 |
}); |
1831 |
|
1832 |
# checking out item that they have recalled |
1833 |
my $recall1 = Koha::Recall->new({ |
1834 |
borrowernumber => $patron1->borrowernumber, |
1835 |
biblionumber => $item->biblionumber, |
1836 |
itemnumber => $item->itemnumber, |
1837 |
item_level_recall => 1, |
1838 |
branchcode => $patron1->branchcode, |
1839 |
status => 'R', |
1840 |
})->store; |
1841 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->recall_id } ); |
1842 |
$recall1 = Koha::Recalls->find( $recall1->recall_id ); |
1843 |
is( $recall1->finished, 1, 'Recall was fulfilled when patron checked out item' ); |
1844 |
AddReturn( $item->barcode, $item->homebranch ); |
1845 |
|
1846 |
# this item is has a recall request. cancel recall |
1847 |
my $recall2 = Koha::Recall->new({ |
1848 |
borrowernumber => $patron2->borrowernumber, |
1849 |
biblionumber => $item->biblionumber, |
1850 |
itemnumber => $item->itemnumber, |
1851 |
item_level_recall => 1, |
1852 |
branchcode => $patron2->branchcode, |
1853 |
status => 'R', |
1854 |
})->store; |
1855 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->recall_id, cancel_recall => 'cancel' } ); |
1856 |
$recall2 = Koha::Recalls->find( $recall2->recall_id ); |
1857 |
is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' ); |
1858 |
AddReturn( $item->barcode, $item->homebranch ); |
1859 |
|
1860 |
# this item is waiting to fulfill a recall. revert recall |
1861 |
my $recall3 = Koha::Recall->new({ |
1862 |
borrowernumber => $patron2->borrowernumber, |
1863 |
biblionumber => $item->biblionumber, |
1864 |
itemnumber => $item->itemnumber, |
1865 |
item_level_recall => 1, |
1866 |
branchcode => $patron2->branchcode, |
1867 |
status => 'R', |
1868 |
})->store; |
1869 |
$recall3->set_waiting; |
1870 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->recall_id, cancel_recall => 'revert' } ); |
1871 |
$recall3 = Koha::Recalls->find( $recall3->recall_id ); |
1872 |
is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' ); |
1873 |
AddReturn( $item->barcode, $item->homebranch ); |
1874 |
}; |
1875 |
|
1876 |
|
1744 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1877 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1745 |
plan tests => 8; |
1878 |
plan tests => 8; |
1746 |
|
1879 |
|
Lines 3161-3166
subtest 'CanBookBeIssued | notforloan' => sub {
Link Here
|
3161 |
# TODO test with AllowNotForLoanOverride = 1 |
3294 |
# TODO test with AllowNotForLoanOverride = 1 |
3162 |
}; |
3295 |
}; |
3163 |
|
3296 |
|
|
|
3297 |
subtest 'CanBookBeIssued | recalls' => sub { |
3298 |
plan tests => 2; |
3299 |
|
3300 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3301 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3302 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3303 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3304 |
my $item = $builder->build_sample_item; |
3305 |
Koha::CirculationRules->set_rules({ |
3306 |
branchcode => undef, |
3307 |
itemtype => undef, |
3308 |
categorycode => undef, |
3309 |
rules => { |
3310 |
recalls_allowed => 10, |
3311 |
}, |
3312 |
}); |
3313 |
|
3314 |
# item-level recall |
3315 |
my $recall = Koha::Recall->new({ |
3316 |
borrowernumber => $patron1->borrowernumber, |
3317 |
biblionumber => $item->biblionumber, |
3318 |
itemnumber => $item->itemnumber, |
3319 |
item_level_recall => 1, |
3320 |
branchcode => $patron1->branchcode, |
3321 |
status => 'R', |
3322 |
})->store; |
3323 |
|
3324 |
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3325 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed an item-level recall on this item" ); |
3326 |
|
3327 |
$recall->set_cancelled; |
3328 |
|
3329 |
# biblio-level recall |
3330 |
$recall = Koha::Recall->new({ |
3331 |
borrowernumber => $patron1->borrowernumber, |
3332 |
biblionumber => $item->biblionumber, |
3333 |
itemnumber => undef, |
3334 |
item_level_recall => 0, |
3335 |
branchcode => $patron1->branchcode, |
3336 |
status => 'R', |
3337 |
})->store; |
3338 |
|
3339 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3340 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed a biblio-level recall and this item is eligible to fill it" ); |
3341 |
|
3342 |
$recall->set_cancelled; |
3343 |
}; |
3344 |
|
3164 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3345 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3165 |
plan tests => 1; |
3346 |
plan tests => 1; |
3166 |
|
3347 |
|
Lines 3176-3181
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
3176 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3357 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3177 |
}; |
3358 |
}; |
3178 |
|
3359 |
|
|
|
3360 |
subtest 'AddReturn | recalls' => sub { |
3361 |
plan tests => 3; |
3362 |
|
3363 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3364 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3365 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3366 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3367 |
my $item1 = $builder->build_sample_item; |
3368 |
Koha::CirculationRules->set_rules({ |
3369 |
branchcode => undef, |
3370 |
itemtype => undef, |
3371 |
categorycode => undef, |
3372 |
rules => { |
3373 |
recalls_allowed => 10, |
3374 |
}, |
3375 |
}); |
3376 |
|
3377 |
# this item can fill a recall with pickup at this branch |
3378 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3379 |
my $recall1 = Koha::Recall->new({ |
3380 |
borrowernumber => $patron2->borrowernumber, |
3381 |
biblionumber => $item1->biblionumber, |
3382 |
itemnumber => $item1->itemnumber, |
3383 |
item_level_recall => 1, |
3384 |
branchcode => $item1->homebranch, |
3385 |
status => 'R', |
3386 |
})->store; |
3387 |
my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3388 |
is( $messages->{RecallFound}->recall_id, $recall1->recall_id, "Recall found" ); |
3389 |
$recall1->set_cancelled; |
3390 |
|
3391 |
# this item can fill a recall but needs transfer |
3392 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3393 |
$recall1 = Koha::Recall->new({ |
3394 |
borrowernumber => $patron2->borrowernumber, |
3395 |
biblionumber => $item1->biblionumber, |
3396 |
itemnumber => $item1->itemnumber, |
3397 |
item_level_recall => 1, |
3398 |
branchcode => $patron2->branchcode, |
3399 |
status => 'R', |
3400 |
})->store; |
3401 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3402 |
is( $messages->{RecallNeedsTransfer}, $item1->homebranch, "Recall requiring transfer found" ); |
3403 |
$recall1->set_cancelled; |
3404 |
|
3405 |
# this item is already in transit, do not ask to transfer |
3406 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3407 |
$recall1 = Koha::Recall->new({ |
3408 |
borrowernumber => $patron2->borrowernumber, |
3409 |
biblionumber => $item1->biblionumber, |
3410 |
itemnumber => $item1->itemnumber, |
3411 |
item_level_recall => 1, |
3412 |
branchcode => $patron2->branchcode, |
3413 |
status => 'R', |
3414 |
})->store; |
3415 |
$recall1->start_transfer; |
3416 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $patron2->branchcode ); |
3417 |
is( $messages->{TransferredRecall}->recall_id, $recall1->recall_id, "In transit recall found" ); |
3418 |
$recall1->set_cancelled; |
3419 |
}; |
3179 |
|
3420 |
|
3180 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3421 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3181 |
|
3422 |
|