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 => 50; |
21 |
use Test::More tests => 53; |
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 1257-1262
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
1257 |
$item_3->itemcallnumber || '' ), |
1257 |
$item_3->itemcallnumber || '' ), |
1258 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1258 |
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber" |
1259 |
); |
1259 |
); |
|
|
1260 |
|
1261 |
# Recalls |
1262 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
1263 |
Koha::CirculationRules->set_rules({ |
1264 |
categorycode => undef, |
1265 |
branchcode => undef, |
1266 |
itemtype => undef, |
1267 |
rules => { |
1268 |
recalls_allowed => 10, |
1269 |
renewalsallowed => 5, |
1270 |
}, |
1271 |
}); |
1272 |
my $recall_borrower = $builder->build_object({ class => 'Koha::Patrons' }); |
1273 |
my $recall_biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
1274 |
my $recall_item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1275 |
my $recall_item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $recall_biblio->biblionumber } }); |
1276 |
|
1277 |
AddIssue( $renewing_borrower, $recall_item1->barcode ); |
1278 |
|
1279 |
# item-level and this item: renewal not allowed |
1280 |
my $recall = Koha::Recall->new({ |
1281 |
biblionumber => $recall_item1->biblionumber, |
1282 |
itemnumber => $recall_item1->itemnumber, |
1283 |
borrowernumber => $recall_borrower->borrowernumber, |
1284 |
branchcode => $recall_borrower->branchcode, |
1285 |
item_level_recall => 1, |
1286 |
status => 'R', |
1287 |
})->store; |
1288 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1289 |
is( $error, 'recalled', 'Cannot renew item that has been recalled' ); |
1290 |
$recall->set_cancelled; |
1291 |
|
1292 |
# biblio-level requested recall: renewal not allowed |
1293 |
$recall = Koha::Recall->new({ |
1294 |
biblionumber => $recall_item1->biblionumber, |
1295 |
itemnumber => undef, |
1296 |
borrowernumber => $recall_borrower->borrowernumber, |
1297 |
branchcode => $recall_borrower->branchcode, |
1298 |
item_level_recall => 0, |
1299 |
status => 'R', |
1300 |
})->store; |
1301 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1302 |
is( $error, 'recalled', 'Cannot renew item if biblio is recalled and has no item allocated' ); |
1303 |
$recall->set_cancelled; |
1304 |
|
1305 |
# item-level and not this item: renewal allowed |
1306 |
$recall = Koha::Recall->new({ |
1307 |
biblionumber => $recall_item2->biblionumber, |
1308 |
itemnumber => $recall_item2->itemnumber, |
1309 |
borrowernumber => $recall_borrower->borrowernumber, |
1310 |
branchcode => $recall_borrower->branchcode, |
1311 |
item_level_recall => 1, |
1312 |
status => 'R', |
1313 |
})->store; |
1314 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1315 |
is( $renewokay, 1, 'Can renew item if item-level recall on biblio is not on this item' ); |
1316 |
$recall->set_cancelled; |
1317 |
|
1318 |
# biblio-level waiting recall: renewal allowed |
1319 |
$recall = Koha::Recall->new({ |
1320 |
biblionumber => $recall_item1->biblionumber, |
1321 |
itemnumber => undef, |
1322 |
borrowernumber => $recall_borrower->borrowernumber, |
1323 |
branchcode => $recall_borrower->branchcode, |
1324 |
item_level_recall => 0, |
1325 |
status => 'R', |
1326 |
})->store; |
1327 |
$recall->set_waiting({ item => $recall_item1 }); |
1328 |
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $recall_item1->itemnumber ); |
1329 |
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' ); |
1330 |
$recall->set_cancelled; |
1260 |
}; |
1331 |
}; |
1261 |
|
1332 |
|
1262 |
subtest "GetUpcomingDueIssues" => sub { |
1333 |
subtest "GetUpcomingDueIssues" => sub { |
Lines 1737-1742
subtest 'AddIssue & AllowReturnToBranch' => sub {
Link Here
|
1737 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1808 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
1738 |
}; |
1809 |
}; |
1739 |
|
1810 |
|
|
|
1811 |
subtest 'AddIssue | recalls' => sub { |
1812 |
plan tests => 3; |
1813 |
|
1814 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
1815 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
1816 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
1817 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
1818 |
my $item = $builder->build_sample_item; |
1819 |
Koha::CirculationRules->set_rules({ |
1820 |
branchcode => undef, |
1821 |
itemtype => undef, |
1822 |
categorycode => undef, |
1823 |
rules => { |
1824 |
recalls_allowed => 10, |
1825 |
}, |
1826 |
}); |
1827 |
|
1828 |
# checking out item that they have recalled |
1829 |
my $recall1 = Koha::Recall->new({ |
1830 |
borrowernumber => $patron1->borrowernumber, |
1831 |
biblionumber => $item->biblionumber, |
1832 |
itemnumber => $item->itemnumber, |
1833 |
item_level_recall => 1, |
1834 |
branchcode => $patron1->branchcode, |
1835 |
status => 'R', |
1836 |
})->store; |
1837 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall1->recall_id } ); |
1838 |
$recall1 = Koha::Recalls->find( $recall1->recall_id ); |
1839 |
is( $recall1->finished, 1, 'Recall was fulfilled when patron checked out item' ); |
1840 |
AddReturn( $item->barcode, $item->homebranch ); |
1841 |
|
1842 |
# this item is has a recall request. cancel recall |
1843 |
my $recall2 = Koha::Recall->new({ |
1844 |
borrowernumber => $patron2->borrowernumber, |
1845 |
biblionumber => $item->biblionumber, |
1846 |
itemnumber => $item->itemnumber, |
1847 |
item_level_recall => 1, |
1848 |
branchcode => $patron2->branchcode, |
1849 |
status => 'R', |
1850 |
})->store; |
1851 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall2->recall_id, cancel_recall => 'cancel' } ); |
1852 |
$recall2 = Koha::Recalls->find( $recall2->recall_id ); |
1853 |
is( $recall2->cancelled, 1, 'Recall was cancelled when patron checked out item' ); |
1854 |
AddReturn( $item->barcode, $item->homebranch ); |
1855 |
|
1856 |
# this item is waiting to fulfill a recall. revert recall |
1857 |
my $recall3 = Koha::Recall->new({ |
1858 |
borrowernumber => $patron2->borrowernumber, |
1859 |
biblionumber => $item->biblionumber, |
1860 |
itemnumber => $item->itemnumber, |
1861 |
item_level_recall => 1, |
1862 |
branchcode => $patron2->branchcode, |
1863 |
status => 'R', |
1864 |
})->store; |
1865 |
$recall3->set_waiting; |
1866 |
AddIssue( $patron1->unblessed, $item->barcode, undef, undef, undef, undef, { recall_id => $recall3->recall_id, cancel_recall => 'revert' } ); |
1867 |
$recall3 = Koha::Recalls->find( $recall3->recall_id ); |
1868 |
is( $recall3->requested, 1, 'Recall was reverted from waiting when patron checked out item' ); |
1869 |
AddReturn( $item->barcode, $item->homebranch ); |
1870 |
}; |
1871 |
|
1872 |
|
1740 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1873 |
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { |
1741 |
plan tests => 8; |
1874 |
plan tests => 8; |
1742 |
|
1875 |
|
Lines 3189-3194
subtest 'CanBookBeIssued | notforloan' => sub {
Link Here
|
3189 |
# TODO test with AllowNotForLoanOverride = 1 |
3322 |
# TODO test with AllowNotForLoanOverride = 1 |
3190 |
}; |
3323 |
}; |
3191 |
|
3324 |
|
|
|
3325 |
subtest 'CanBookBeIssued | recalls' => sub { |
3326 |
plan tests => 3; |
3327 |
|
3328 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3329 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3330 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3331 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3332 |
my $item = $builder->build_sample_item; |
3333 |
Koha::CirculationRules->set_rules({ |
3334 |
branchcode => undef, |
3335 |
itemtype => undef, |
3336 |
categorycode => undef, |
3337 |
rules => { |
3338 |
recalls_allowed => 10, |
3339 |
}, |
3340 |
}); |
3341 |
|
3342 |
# item-level recall |
3343 |
my $recall = Koha::Recall->new({ |
3344 |
borrowernumber => $patron1->borrowernumber, |
3345 |
biblionumber => $item->biblionumber, |
3346 |
itemnumber => $item->itemnumber, |
3347 |
item_level_recall => 1, |
3348 |
branchcode => $patron1->branchcode, |
3349 |
status => 'R', |
3350 |
})->store; |
3351 |
|
3352 |
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3353 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed an item-level recall on this item" ); |
3354 |
|
3355 |
$recall->set_cancelled; |
3356 |
|
3357 |
# biblio-level recall |
3358 |
$recall = Koha::Recall->new({ |
3359 |
borrowernumber => $patron1->borrowernumber, |
3360 |
biblionumber => $item->biblionumber, |
3361 |
itemnumber => undef, |
3362 |
item_level_recall => 0, |
3363 |
branchcode => $patron1->branchcode, |
3364 |
status => 'R', |
3365 |
})->store; |
3366 |
|
3367 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3368 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed a biblio-level recall and this item is eligible to fill it" ); |
3369 |
|
3370 |
$recall->set_cancelled; |
3371 |
|
3372 |
# biblio-level recall |
3373 |
$recall = Koha::Recall->new({ |
3374 |
borrowernumber => $patron1->borrowernumber, |
3375 |
biblionumber => $item->biblionumber, |
3376 |
itemnumber => undef, |
3377 |
item_level_recall => 0, |
3378 |
branchcode => $patron1->branchcode, |
3379 |
status => 'R', |
3380 |
})->store; |
3381 |
$recall->set_waiting({ item => $item, expirationdate => dt_from_string() }); |
3382 |
|
3383 |
my ( undef, undef, undef, $messages ) = CanBookBeIssued( $patron1, $item->barcode, undef, undef, undef, undef ); |
3384 |
is( $messages->{RECALLED}, $recall->recall_id, "This book can be issued by this patron and they have placed a recall" ); |
3385 |
|
3386 |
$recall->set_cancelled; |
3387 |
}; |
3388 |
|
3192 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3389 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3193 |
plan tests => 1; |
3390 |
plan tests => 1; |
3194 |
|
3391 |
|
Lines 3204-3209
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
3204 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3401 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3205 |
}; |
3402 |
}; |
3206 |
|
3403 |
|
|
|
3404 |
subtest 'AddReturn | recalls' => sub { |
3405 |
plan tests => 3; |
3406 |
|
3407 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3408 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3409 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3410 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3411 |
my $item1 = $builder->build_sample_item; |
3412 |
Koha::CirculationRules->set_rules({ |
3413 |
branchcode => undef, |
3414 |
itemtype => undef, |
3415 |
categorycode => undef, |
3416 |
rules => { |
3417 |
recalls_allowed => 10, |
3418 |
}, |
3419 |
}); |
3420 |
|
3421 |
# this item can fill a recall with pickup at this branch |
3422 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3423 |
my $recall1 = Koha::Recall->new({ |
3424 |
borrowernumber => $patron2->borrowernumber, |
3425 |
biblionumber => $item1->biblionumber, |
3426 |
itemnumber => $item1->itemnumber, |
3427 |
item_level_recall => 1, |
3428 |
branchcode => $item1->homebranch, |
3429 |
status => 'R', |
3430 |
})->store; |
3431 |
my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3432 |
is( $messages->{RecallFound}->recall_id, $recall1->recall_id, "Recall found" ); |
3433 |
$recall1->set_cancelled; |
3434 |
|
3435 |
# this item can fill a recall but needs transfer |
3436 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3437 |
$recall1 = Koha::Recall->new({ |
3438 |
borrowernumber => $patron2->borrowernumber, |
3439 |
biblionumber => $item1->biblionumber, |
3440 |
itemnumber => $item1->itemnumber, |
3441 |
item_level_recall => 1, |
3442 |
branchcode => $patron2->branchcode, |
3443 |
status => 'R', |
3444 |
})->store; |
3445 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3446 |
is( $messages->{RecallNeedsTransfer}, $item1->homebranch, "Recall requiring transfer found" ); |
3447 |
$recall1->set_cancelled; |
3448 |
|
3449 |
# this item is already in transit, do not ask to transfer |
3450 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3451 |
$recall1 = Koha::Recall->new({ |
3452 |
borrowernumber => $patron2->borrowernumber, |
3453 |
biblionumber => $item1->biblionumber, |
3454 |
itemnumber => $item1->itemnumber, |
3455 |
item_level_recall => 1, |
3456 |
branchcode => $patron2->branchcode, |
3457 |
status => 'R', |
3458 |
})->store; |
3459 |
$recall1->start_transfer; |
3460 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $patron2->branchcode ); |
3461 |
is( $messages->{TransferredRecall}->recall_id, $recall1->recall_id, "In transit recall found" ); |
3462 |
$recall1->set_cancelled; |
3463 |
}; |
3207 |
|
3464 |
|
3208 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3465 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3209 |
|
3466 |
|