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 => 59; |
10 |
use Test::More tests => 62; |
11 |
use MARC::Record; |
11 |
use MARC::Record; |
12 |
|
12 |
|
13 |
use C4::Biblio; |
13 |
use C4::Biblio; |
Lines 282-308
ok(
Link Here
|
282 |
'... unless canreservefromotherbranches is ON (bug 2394)' |
282 |
'... unless canreservefromotherbranches is ON (bug 2394)' |
283 |
); |
283 |
); |
284 |
|
284 |
|
285 |
{ |
285 |
# Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities |
286 |
# Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities |
286 |
$biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
287 |
$biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
287 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
288 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
288 |
my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1); |
289 |
my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1); |
289 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
290 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
290 |
my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2); |
291 |
my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2); |
291 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
292 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
292 |
my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3); |
293 |
my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3); |
293 |
my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber }); |
294 |
my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber }); |
294 |
my $hold3 = Koha::Holds->find( $reserveid3 ); |
295 |
my $hold3 = Koha::Holds->find( $reserveid3 ); |
295 |
is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" ); |
296 |
is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" ); |
296 |
ModReserve({ reserve_id => $reserveid1, rank => 'del' }); |
297 |
ModReserve({ reserve_id => $reserveid1, rank => 'del' }); |
297 |
ModReserve({ reserve_id => $reserveid2, rank => 'del' }); |
298 |
ModReserve({ reserve_id => $reserveid2, rank => 'del' }); |
298 |
is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" ); |
299 |
is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" ); |
299 |
|
300 |
} |
300 |
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); |
301 |
|
301 |
|
302 |
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber); |
302 |
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber); |
|
|
303 |
$hold = Koha::Holds->find( $reserveid3 ); |
304 |
$hold->cancel; |
303 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); |
305 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); |
304 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" ); |
306 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" ); |
305 |
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); |
|
|
306 |
|
307 |
|
307 |
$hold = Koha::Hold->new( |
308 |
$hold = Koha::Hold->new( |
308 |
{ |
309 |
{ |
Lines 330-352
AddReserve(
Link Here
|
330 |
'', |
331 |
'', |
331 |
1, |
332 |
1, |
332 |
); |
333 |
); |
|
|
334 |
my ($bibnum2, $title2, $bibitemnum2) = create_helper_biblio('CANNOT'); |
335 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum2); |
333 |
is( |
336 |
is( |
334 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves', |
337 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status}, 'tooManyReserves', |
335 |
"cannot request item if policy that matches on item-level item type forbids it" |
338 |
"cannot request item if policy that matches on item-level item type forbids it" |
336 |
); |
339 |
); |
337 |
ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber); |
340 |
ModItem({ itype => 'CAN' }, $item_bibnum2, $itemnumber2); |
338 |
ok( |
341 |
ok( |
339 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK', |
342 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status} eq 'OK', |
340 |
"can request item if policy that matches on item type allows it" |
343 |
"can request item if policy that matches on item type allows it" |
341 |
); |
344 |
); |
342 |
|
345 |
|
343 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
346 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
344 |
ModItem({ itype => undef }, $item_bibnum, $itemnumber); |
347 |
ModItem({ itype => undef }, $item_bibnum, $itemnumber2); |
345 |
ok( |
348 |
is( |
346 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves', |
349 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status}, 'tooManyReserves', |
347 |
"cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" |
350 |
"cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" |
348 |
); |
351 |
); |
349 |
|
352 |
|
|
|
353 |
is(CanBookBeReserved($borrowernumbers[0], $biblio->biblionumber)->{status}, 'OK'); |
354 |
|
355 |
C4::Context->set_preference('maxreserves', 1); |
356 |
is(CanBookBeReserved($borrowernumbers[0], $biblio->biblionumber)->{status}, 'tooManyReserves'); |
357 |
|
358 |
C4::Context->set_preference('maxreserves', 0); |
359 |
t::lib::Mocks::mock_preference('IndependentBranches', 1); |
360 |
t::lib::Mocks::mock_preference('canreservefromotherbranches', 0); |
361 |
ok(CanBookBeReserved($borrowernumbers[0], $foreign_biblio->biblionumber)->{status} eq 'none_available'); |
362 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
363 |
t::lib::Mocks::mock_preference('canreservefromotherbranches', 1); |
350 |
|
364 |
|
351 |
# Test branch item rules |
365 |
# Test branch item rules |
352 |
|
366 |
|
Lines 416-427
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
Link Here
|
416 |
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, ); |
430 |
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, ); |
417 |
|
431 |
|
418 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
432 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
419 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
433 |
'tooManyHoldsForThisRecord', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
420 |
|
434 |
|
421 |
#results should be the same for both ReservesControlBranch settings |
435 |
#results should be the same for both ReservesControlBranch settings |
422 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); |
436 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); |
423 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
437 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
424 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
438 |
'tooManyHoldsForThisRecord', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
425 |
#reset for further tests |
439 |
#reset for further tests |
426 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); |
440 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); |
427 |
|
441 |
|
Lines 675-677
subtest 'CanItemBeReserved / holds_per_day tests' => sub {
Link Here
|
675 |
|
689 |
|
676 |
$schema->storage->txn_rollback; |
690 |
$schema->storage->txn_rollback; |
677 |
}; |
691 |
}; |
|
|
692 |
|
693 |
# Helper method to set up a Biblio. |
694 |
sub create_helper_biblio { |
695 |
my $itemtype = shift; |
696 |
my $bib = MARC::Record->new(); |
697 |
my $title = 'Silence in the library'; |
698 |
if (C4::Context->preference('marcflavour') eq 'UNIMARC') { |
699 |
$bib->append_fields( |
700 |
MARC::Field->new('700', ' ', '0', a => 'Moffat, Steven'), |
701 |
MARC::Field->new('200', ' ', ' ', a => $title), |
702 |
MARC::Field->new('099', ' ', ' ', t => $itemtype), |
703 |
); |
704 |
} else { |
705 |
$bib->append_fields( |
706 |
MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), |
707 |
MARC::Field->new('245', ' ', ' ', a => $title), |
708 |
MARC::Field->new('942', ' ', ' ', c => $itemtype), |
709 |
); |
710 |
} |
711 |
|
712 |
return AddBiblio($bib, ''); |
713 |
} |