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 => 49; |
21 |
use Test::More tests => 52; |
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 3157-3162
subtest 'CanBookBeIssued | notforloan' => sub {
Link Here
|
3157 |
# TODO test with AllowNotForLoanOverride = 1 |
3290 |
# TODO test with AllowNotForLoanOverride = 1 |
3158 |
}; |
3291 |
}; |
3159 |
|
3292 |
|
|
|
3293 |
subtest 'CanBookBeIssued | recalls' => sub { |
3294 |
plan tests => 3; |
3295 |
|
3296 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3297 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3298 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3299 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3300 |
my $item = $builder->build_sample_item; |
3301 |
Koha::CirculationRules->set_rules({ |
3302 |
branchcode => undef, |
3303 |
itemtype => undef, |
3304 |
categorycode => undef, |
3305 |
rules => { |
3306 |
recalls_allowed => 10, |
3307 |
}, |
3308 |
}); |
3309 |
|
3310 |
# item-level recall |
3311 |
my $recall = Koha::Recall->new({ |
3312 |
borrowernumber => $patron1->borrowernumber, |
3313 |
biblionumber => $item->biblionumber, |
3314 |
itemnumber => $item->itemnumber, |
3315 |
item_level_recall => 1, |
3316 |
branchcode => $patron1->branchcode, |
3317 |
status => 'R', |
3318 |
})->store; |
3319 |
|
3320 |
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3321 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed an item-level recall on this item" ); |
3322 |
|
3323 |
$recall->set_cancelled; |
3324 |
|
3325 |
# biblio-level recall |
3326 |
$recall = Koha::Recall->new({ |
3327 |
borrowernumber => $patron1->borrowernumber, |
3328 |
biblionumber => $item->biblionumber, |
3329 |
itemnumber => undef, |
3330 |
item_level_recall => 0, |
3331 |
branchcode => $patron1->branchcode, |
3332 |
status => 'R', |
3333 |
})->store; |
3334 |
|
3335 |
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron2, $item->barcode, undef, undef, undef, undef ); |
3336 |
is( $needsconfirmation->{RECALLED}->recall_id, $recall->recall_id, "Another patron has placed a biblio-level recall and this item is eligible to fill it" ); |
3337 |
|
3338 |
$recall->set_cancelled; |
3339 |
|
3340 |
# biblio-level recall |
3341 |
$recall = Koha::Recall->new({ |
3342 |
borrowernumber => $patron1->borrowernumber, |
3343 |
biblionumber => $item->biblionumber, |
3344 |
itemnumber => undef, |
3345 |
item_level_recall => 0, |
3346 |
branchcode => $patron1->branchcode, |
3347 |
status => 'R', |
3348 |
})->store; |
3349 |
$recall->set_waiting({ item => $item, expirationdate => dt_from_string() }); |
3350 |
|
3351 |
my ( undef, undef, undef, $messages ) = CanBookBeIssued( $patron1, $item->barcode, undef, undef, undef, undef ); |
3352 |
is( $messages->{RECALLED}, $recall->recall_id, "This book can be issued by this patron and they have placed a recall" ); |
3353 |
|
3354 |
$recall->set_cancelled; |
3355 |
}; |
3356 |
|
3160 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3357 |
subtest 'AddReturn should clear items.onloan for unissued items' => sub { |
3161 |
plan tests => 1; |
3358 |
plan tests => 1; |
3162 |
|
3359 |
|
Lines 3172-3177
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
Link Here
|
3172 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3369 |
is( $item->onloan, undef, 'AddReturn did clear items.onloan' ); |
3173 |
}; |
3370 |
}; |
3174 |
|
3371 |
|
|
|
3372 |
subtest 'AddReturn | recalls' => sub { |
3373 |
plan tests => 3; |
3374 |
|
3375 |
t::lib::Mocks::mock_preference("UseRecalls", 1); |
3376 |
t::lib::Mocks::mock_preference("item-level_itypes", 1); |
3377 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
3378 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
3379 |
my $item1 = $builder->build_sample_item; |
3380 |
Koha::CirculationRules->set_rules({ |
3381 |
branchcode => undef, |
3382 |
itemtype => undef, |
3383 |
categorycode => undef, |
3384 |
rules => { |
3385 |
recalls_allowed => 10, |
3386 |
}, |
3387 |
}); |
3388 |
|
3389 |
# this item can fill a recall with pickup at this branch |
3390 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3391 |
my $recall1 = Koha::Recall->new({ |
3392 |
borrowernumber => $patron2->borrowernumber, |
3393 |
biblionumber => $item1->biblionumber, |
3394 |
itemnumber => $item1->itemnumber, |
3395 |
item_level_recall => 1, |
3396 |
branchcode => $item1->homebranch, |
3397 |
status => 'R', |
3398 |
})->store; |
3399 |
my ( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3400 |
is( $messages->{RecallFound}->recall_id, $recall1->recall_id, "Recall found" ); |
3401 |
$recall1->set_cancelled; |
3402 |
|
3403 |
# this item can fill a recall but needs transfer |
3404 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3405 |
$recall1 = Koha::Recall->new({ |
3406 |
borrowernumber => $patron2->borrowernumber, |
3407 |
biblionumber => $item1->biblionumber, |
3408 |
itemnumber => $item1->itemnumber, |
3409 |
item_level_recall => 1, |
3410 |
branchcode => $patron2->branchcode, |
3411 |
status => 'R', |
3412 |
})->store; |
3413 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $item1->homebranch ); |
3414 |
is( $messages->{RecallNeedsTransfer}, $item1->homebranch, "Recall requiring transfer found" ); |
3415 |
$recall1->set_cancelled; |
3416 |
|
3417 |
# this item is already in transit, do not ask to transfer |
3418 |
AddIssue( $patron1->unblessed, $item1->barcode ); |
3419 |
$recall1 = Koha::Recall->new({ |
3420 |
borrowernumber => $patron2->borrowernumber, |
3421 |
biblionumber => $item1->biblionumber, |
3422 |
itemnumber => $item1->itemnumber, |
3423 |
item_level_recall => 1, |
3424 |
branchcode => $patron2->branchcode, |
3425 |
status => 'R', |
3426 |
})->store; |
3427 |
$recall1->start_transfer; |
3428 |
( $doreturn, $messages, $iteminfo, $borrowerinfo ) = AddReturn( $item1->barcode, $patron2->branchcode ); |
3429 |
is( $messages->{TransferredRecall}->recall_id, $recall1->recall_id, "In transit recall found" ); |
3430 |
$recall1->set_cancelled; |
3431 |
}; |
3175 |
|
3432 |
|
3176 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3433 |
subtest 'AddRenewal and AddIssuingCharge tests' => sub { |
3177 |
|
3434 |
|