Lines 7-13
use t::lib::TestBuilder;
Link Here
|
7 |
|
7 |
|
8 |
use C4::Context; |
8 |
use C4::Context; |
9 |
|
9 |
|
10 |
use Test::More tests => 56; |
10 |
use Test::More tests => 55; |
11 |
use MARC::Record; |
11 |
use MARC::Record; |
12 |
use Koha::Patrons; |
12 |
use Koha::Patrons; |
13 |
use C4::Items; |
13 |
use C4::Items; |
Lines 261-267
t::lib::Mocks::mock_preference('item-level_itypes', 1);
Link Here
|
261 |
# if IndependentBranches is OFF, a $branch_1 patron can reserve an $branch_2 item |
261 |
# if IndependentBranches is OFF, a $branch_1 patron can reserve an $branch_2 item |
262 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
262 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
263 |
ok( |
263 |
ok( |
264 |
CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber) eq 'OK', |
264 |
CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'OK', |
265 |
'$branch_1 patron allowed to reserve $branch_2 item with IndependentBranches OFF (bug 2394)' |
265 |
'$branch_1 patron allowed to reserve $branch_2 item with IndependentBranches OFF (bug 2394)' |
266 |
); |
266 |
); |
267 |
|
267 |
|
Lines 269-282
ok(
Link Here
|
269 |
t::lib::Mocks::mock_preference('IndependentBranches', 1); |
269 |
t::lib::Mocks::mock_preference('IndependentBranches', 1); |
270 |
t::lib::Mocks::mock_preference('canreservefromotherbranches', 0); |
270 |
t::lib::Mocks::mock_preference('canreservefromotherbranches', 0); |
271 |
ok( |
271 |
ok( |
272 |
CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber) eq 'cannotReserveFromOtherBranches', |
272 |
CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'cannotReserveFromOtherBranches', |
273 |
'$branch_1 patron NOT allowed to reserve $branch_2 item with IndependentBranches ON ... (bug 2394)' |
273 |
'$branch_1 patron NOT allowed to reserve $branch_2 item with IndependentBranches ON ... (bug 2394)' |
274 |
); |
274 |
); |
275 |
|
275 |
|
276 |
# ... unless canreservefromotherbranches is ON |
276 |
# ... unless canreservefromotherbranches is ON |
277 |
t::lib::Mocks::mock_preference('canreservefromotherbranches', 1); |
277 |
t::lib::Mocks::mock_preference('canreservefromotherbranches', 1); |
278 |
ok( |
278 |
ok( |
279 |
CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber) eq 'OK', |
279 |
CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'OK', |
280 |
'... unless canreservefromotherbranches is ON (bug 2394)' |
280 |
'... unless canreservefromotherbranches is ON (bug 2394)' |
281 |
); |
281 |
); |
282 |
|
282 |
|
Lines 299-305
ok(
Link Here
|
299 |
|
299 |
|
300 |
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber); |
300 |
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber); |
301 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); |
301 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); |
302 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber), 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" ); |
302 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" ); |
303 |
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); |
303 |
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); |
304 |
|
304 |
|
305 |
$hold = Koha::Hold->new( |
305 |
$hold = Koha::Hold->new( |
Lines 309-321
$hold = Koha::Hold->new(
Link Here
|
309 |
biblionumber => $item_bibnum, |
309 |
biblionumber => $item_bibnum, |
310 |
} |
310 |
} |
311 |
)->store(); |
311 |
)->store(); |
312 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), |
312 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
313 |
'itemAlreadyOnHold', |
313 |
'itemAlreadyOnHold', |
314 |
"Patron cannot place a second item level hold for a given item" ); |
314 |
"Patron cannot place a second item level hold for a given item" ); |
315 |
$hold->delete(); |
315 |
$hold->delete(); |
316 |
|
316 |
|
317 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 ); |
317 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 ); |
318 |
ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber) eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" ); |
318 |
ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" ); |
319 |
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" ); |
319 |
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" ); |
320 |
|
320 |
|
321 |
# Regression test for bug 9532 |
321 |
# Regression test for bug 9532 |
Lines 329-347
AddReserve(
Link Here
|
329 |
1, |
329 |
1, |
330 |
); |
330 |
); |
331 |
is( |
331 |
is( |
332 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber), 'tooManyReserves', |
332 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves', |
333 |
"cannot request item if policy that matches on item-level item type forbids it" |
333 |
"cannot request item if policy that matches on item-level item type forbids it" |
334 |
); |
334 |
); |
335 |
ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber); |
335 |
ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber); |
336 |
ok( |
336 |
ok( |
337 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber) eq 'OK', |
337 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK', |
338 |
"can request item if policy that matches on item type allows it" |
338 |
"can request item if policy that matches on item type allows it" |
339 |
); |
339 |
); |
340 |
|
340 |
|
341 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
341 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
342 |
ModItem({ itype => undef }, $item_bibnum, $itemnumber); |
342 |
ModItem({ itype => undef }, $item_bibnum, $itemnumber); |
343 |
ok( |
343 |
ok( |
344 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber) eq 'tooManyReserves', |
344 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves', |
345 |
"cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" |
345 |
"cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" |
346 |
); |
346 |
); |
347 |
|
347 |
|
Lines 370-387
$dbh->do(q{
Link Here
|
370 |
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT'); |
370 |
($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT'); |
371 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
371 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
372 |
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum); |
372 |
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum); |
373 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber), 'notReservable', |
373 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable', |
374 |
"CanItemBeReserved should return 'notReservable'"); |
374 |
"CanItemBeReserved should return 'notReservable'"); |
375 |
|
375 |
|
376 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
376 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
377 |
{ homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum); |
377 |
{ homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum); |
378 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber), |
378 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, |
379 |
'cannotReserveFromOtherBranches', |
379 |
'cannotReserveFromOtherBranches', |
380 |
"CanItemBeReserved should return 'cannotReserveFromOtherBranches'"); |
380 |
"CanItemBeReserved should return 'cannotReserveFromOtherBranches'"); |
381 |
|
381 |
|
382 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
382 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem( |
383 |
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum); |
383 |
{ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum); |
384 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber), 'OK', |
384 |
is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK', |
385 |
"CanItemBeReserved should return 'OK'"); |
385 |
"CanItemBeReserved should return 'OK'"); |
386 |
|
386 |
|
387 |
# Bug 12632 |
387 |
# Bug 12632 |
Lines 403-414
$dbh->do(
Link Here
|
403 |
{}, |
403 |
{}, |
404 |
'*', '*', 'ONLY1', 1, 99 |
404 |
'*', '*', 'ONLY1', 1, 99 |
405 |
); |
405 |
); |
406 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), |
406 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
407 |
'OK', 'Patron can reserve item with hold limit of 1, no holds placed' ); |
407 |
'OK', 'Patron can reserve item with hold limit of 1, no holds placed' ); |
408 |
|
408 |
|
409 |
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); |
409 |
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); |
410 |
|
410 |
|
411 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), |
411 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
412 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
412 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
413 |
|
413 |
|
414 |
subtest 'Test max_holds per library/patron category' => sub { |
414 |
subtest 'Test max_holds per library/patron category' => sub { |
Lines 438-444
subtest 'Test max_holds per library/patron category' => sub {
Link Here
|
438 |
is( $count, 3, 'Patron now has 3 holds' ); |
438 |
is( $count, 3, 'Patron now has 3 holds' ); |
439 |
|
439 |
|
440 |
my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
440 |
my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
441 |
is( $ret, 'OK', 'Patron can place hold with no borrower circ rules' ); |
441 |
is( $ret->{status}, 'OK', 'Patron can place hold with no borrower circ rules' ); |
442 |
|
442 |
|
443 |
my $rule_all = $schema->resultset('DefaultBorrowerCircRule')->new( |
443 |
my $rule_all = $schema->resultset('DefaultBorrowerCircRule')->new( |
444 |
{ |
444 |
{ |
Lines 456-474
subtest 'Test max_holds per library/patron category' => sub {
Link Here
|
456 |
)->insert(); |
456 |
)->insert(); |
457 |
|
457 |
|
458 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
458 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
459 |
is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' ); |
459 |
is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' ); |
460 |
|
460 |
|
461 |
$rule_branch->delete(); |
461 |
$rule_branch->delete(); |
462 |
|
462 |
|
463 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
463 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
464 |
is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' ); |
464 |
is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' ); |
465 |
|
465 |
|
466 |
$rule_all->delete(); |
466 |
$rule_all->delete(); |
467 |
$rule_branch->max_holds(3); |
467 |
$rule_branch->max_holds(3); |
468 |
$rule_branch->insert(); |
468 |
$rule_branch->insert(); |
469 |
|
469 |
|
470 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
470 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
471 |
is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' ); |
471 |
is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' ); |
472 |
|
472 |
|
473 |
$rule_branch->max_holds(5); |
473 |
$rule_branch->max_holds(5); |
474 |
$rule_branch->update(); |
474 |
$rule_branch->update(); |
Lines 476-482
subtest 'Test max_holds per library/patron category' => sub {
Link Here
|
476 |
$rule_all->insert(); |
476 |
$rule_all->insert(); |
477 |
|
477 |
|
478 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
478 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
479 |
is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' ); |
479 |
is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' ); |
480 |
}; |
480 |
}; |
481 |
|
481 |
|
482 |
# Helper method to set up a Biblio. |
482 |
# Helper method to set up a Biblio. |