Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 77; |
20 |
use Test::More tests => 69; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 32-38
use C4::Items;
Link Here
|
32 |
use C4::Biblio qw( GetMarcFromKohaField ModBiblio ); |
32 |
use C4::Biblio qw( GetMarcFromKohaField ModBiblio ); |
33 |
use C4::HoldsQueue; |
33 |
use C4::HoldsQueue; |
34 |
use C4::Members; |
34 |
use C4::Members; |
35 |
use C4::Reserves qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds ); |
35 |
use C4::Reserves qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds ); |
36 |
use Koha::ActionLogs; |
36 |
use Koha::ActionLogs; |
37 |
use Koha::Biblios; |
37 |
use Koha::Biblios; |
38 |
use Koha::Caches; |
38 |
use Koha::Caches; |
Lines 136-159
$requesters{$branch_1} = Koha::Patron->new({
Link Here
|
136 |
branchcode => $branch_1, |
136 |
branchcode => $branch_1, |
137 |
categorycode => $category_2, |
137 |
categorycode => $category_2, |
138 |
surname => "borrower from $branch_1", |
138 |
surname => "borrower from $branch_1", |
139 |
})->store->borrowernumber; |
139 |
})->store; |
140 |
for my $i ( 2 .. 5 ) { |
140 |
for my $i ( 2 .. 5 ) { |
141 |
$requesters{"CPL$i"} = Koha::Patron->new({ |
141 |
$requesters{"CPL$i"} = Koha::Patron->new({ |
142 |
branchcode => $branch_1, |
142 |
branchcode => $branch_1, |
143 |
categorycode => $category_2, |
143 |
categorycode => $category_2, |
144 |
surname => "borrower $i from $branch_1", |
144 |
surname => "borrower $i from $branch_1", |
145 |
})->store->borrowernumber; |
145 |
})->store; |
146 |
} |
146 |
} |
147 |
$requesters{$branch_2} = Koha::Patron->new({ |
147 |
$requesters{$branch_2} = Koha::Patron->new({ |
148 |
branchcode => $branch_2, |
148 |
branchcode => $branch_2, |
149 |
categorycode => $category_2, |
149 |
categorycode => $category_2, |
150 |
surname => "borrower from $branch_2", |
150 |
surname => "borrower from $branch_2", |
151 |
})->store->borrowernumber; |
151 |
})->store; |
152 |
$requesters{$branch_3} = Koha::Patron->new({ |
152 |
$requesters{$branch_3} = Koha::Patron->new({ |
153 |
branchcode => $branch_3, |
153 |
branchcode => $branch_3, |
154 |
categorycode => $category_2, |
154 |
categorycode => $category_2, |
155 |
surname => "borrower from $branch_3", |
155 |
surname => "borrower from $branch_3", |
156 |
})->store->borrowernumber; |
156 |
})->store; |
157 |
|
157 |
|
158 |
# Configure rules so that $branch_1 allows only $branch_1 patrons |
158 |
# Configure rules so that $branch_1 allows only $branch_1 patrons |
159 |
# to request its items, while $branch_2 will allow its items |
159 |
# to request its items, while $branch_2 will allow its items |
Lines 222-228
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
Link Here
|
222 |
AddReserve( |
222 |
AddReserve( |
223 |
{ |
223 |
{ |
224 |
branchcode => $branch_3, |
224 |
branchcode => $branch_3, |
225 |
borrowernumber => $requesters{$branch_3}, |
225 |
borrowernumber => $requesters{$branch_3}->borrowernumber, |
226 |
biblionumber => $bibnum2, |
226 |
biblionumber => $bibnum2, |
227 |
priority => 1, |
227 |
priority => 1, |
228 |
} |
228 |
} |
Lines 230-236
AddReserve(
Link Here
|
230 |
AddReserve( |
230 |
AddReserve( |
231 |
{ |
231 |
{ |
232 |
branchcode => $branch_2, |
232 |
branchcode => $branch_2, |
233 |
borrowernumber => $requesters{$branch_2}, |
233 |
borrowernumber => $requesters{$branch_2}->borrowernumber, |
234 |
biblionumber => $bibnum2, |
234 |
biblionumber => $bibnum2, |
235 |
priority => 2, |
235 |
priority => 2, |
236 |
} |
236 |
} |
Lines 238-249
AddReserve(
Link Here
|
238 |
AddReserve( |
238 |
AddReserve( |
239 |
{ |
239 |
{ |
240 |
branchcode => $branch_1, |
240 |
branchcode => $branch_1, |
241 |
borrowernumber => $requesters{$branch_1}, |
241 |
borrowernumber => $requesters{$branch_1}->borrowernumber, |
242 |
biblionumber => $bibnum2, |
242 |
biblionumber => $bibnum2, |
243 |
priority => 3, |
243 |
priority => 3, |
244 |
} |
244 |
} |
245 |
); |
245 |
); |
246 |
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0); |
246 |
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}->borrowernumber, 0); |
247 |
|
247 |
|
248 |
# Now it should have different priorities. |
248 |
# Now it should have different priorities. |
249 |
my $biblio = Koha::Biblios->find( $bibnum2 ); |
249 |
my $biblio = Koha::Biblios->find( $bibnum2 ); |
Lines 252-267
is($holds->next->priority, 0, 'Item is correctly waiting');
Link Here
|
252 |
is($holds->next->priority, 1, 'Item is correctly priority 1'); |
252 |
is($holds->next->priority, 1, 'Item is correctly priority 1'); |
253 |
is($holds->next->priority, 2, 'Item is correctly priority 2'); |
253 |
is($holds->next->priority, 2, 'Item is correctly priority 2'); |
254 |
|
254 |
|
255 |
my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting->as_list; |
255 |
my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3}->borrowernumber })->waiting->as_list; |
256 |
is( @reserves, 1, 'GetWaiting got only the waiting reserve' ); |
256 |
is( @reserves, 1, 'GetWaiting got only the waiting reserve' ); |
257 |
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the reserve for the correct borrower' ); |
257 |
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}->borrowernumber, 'GetWaiting got the reserve for the correct borrower' ); |
258 |
|
258 |
|
259 |
|
259 |
|
260 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); |
260 |
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); |
261 |
AddReserve( |
261 |
AddReserve( |
262 |
{ |
262 |
{ |
263 |
branchcode => $branch_3, |
263 |
branchcode => $branch_3, |
264 |
borrowernumber => $requesters{$branch_3}, |
264 |
borrowernumber => $requesters{$branch_3}->borrowernumber, |
265 |
biblionumber => $bibnum2, |
265 |
biblionumber => $bibnum2, |
266 |
priority => 1, |
266 |
priority => 1, |
267 |
} |
267 |
} |
Lines 269-275
AddReserve(
Link Here
|
269 |
AddReserve( |
269 |
AddReserve( |
270 |
{ |
270 |
{ |
271 |
branchcode => $branch_2, |
271 |
branchcode => $branch_2, |
272 |
borrowernumber => $requesters{$branch_2}, |
272 |
borrowernumber => $requesters{$branch_2}->borrowernumber, |
273 |
biblionumber => $bibnum2, |
273 |
biblionumber => $bibnum2, |
274 |
priority => 2, |
274 |
priority => 2, |
275 |
} |
275 |
} |
Lines 278-284
AddReserve(
Link Here
|
278 |
AddReserve( |
278 |
AddReserve( |
279 |
{ |
279 |
{ |
280 |
branchcode => $branch_1, |
280 |
branchcode => $branch_1, |
281 |
borrowernumber => $requesters{$branch_1}, |
281 |
borrowernumber => $requesters{$branch_1}->borrowernumber, |
282 |
biblionumber => $bibnum2, |
282 |
biblionumber => $bibnum2, |
283 |
priority => 3, |
283 |
priority => 3, |
284 |
} |
284 |
} |
Lines 293-299
my $messages;
Link Here
|
293 |
# requests cannot be filled by that item per policy. |
293 |
# requests cannot be filled by that item per policy. |
294 |
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2); |
294 |
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2); |
295 |
is( $messages->{ResFound}->{borrowernumber}, |
295 |
is( $messages->{ResFound}->{borrowernumber}, |
296 |
$requesters{$branch_1}, |
296 |
$requesters{$branch_1}->borrowernumber, |
297 |
'restrictive library\'s items only fill requests by own patrons (bug 10272)'); |
297 |
'restrictive library\'s items only fill requests by own patrons (bug 10272)'); |
298 |
|
298 |
|
299 |
# Return the FPL item at FPL. The hold that should be triggered is |
299 |
# Return the FPL item at FPL. The hold that should be triggered is |
Lines 305-311
t::lib::Mocks::mock_preference( 'LocalHoldsPriority', '' );
Link Here
|
305 |
|
305 |
|
306 |
(undef, $messages, undef, undef) = AddReturn('bug10272_FPL', $branch_2); |
306 |
(undef, $messages, undef, undef) = AddReturn('bug10272_FPL', $branch_2); |
307 |
is( $messages->{ResFound}->{borrowernumber}, |
307 |
is( $messages->{ResFound}->{borrowernumber}, |
308 |
$requesters{$branch_3}, |
308 |
$requesters{$branch_3}->borrowernumber, |
309 |
'for generous library, its items fill first hold request in line (bug 10272)'); |
309 |
'for generous library, its items fill first hold request in line (bug 10272)'); |
310 |
|
310 |
|
311 |
$biblio = Koha::Biblios->find( $biblionumber ); |
311 |
$biblio = Koha::Biblios->find( $biblionumber ); |
Lines 320-326
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
Link Here
|
320 |
AddReserve( |
320 |
AddReserve( |
321 |
{ |
321 |
{ |
322 |
branchcode => $branch_1, |
322 |
branchcode => $branch_1, |
323 |
borrowernumber => $requesters{$branch_1}, |
323 |
borrowernumber => $requesters{$branch_1}->borrowernumber, |
324 |
biblionumber => $bibnum, |
324 |
biblionumber => $bibnum, |
325 |
priority => 1, |
325 |
priority => 1, |
326 |
} |
326 |
} |
Lines 338-344
$resdate->add_duration(DateTime::Duration->new(days => 4));
Link Here
|
338 |
my $reserve_id = AddReserve( |
338 |
my $reserve_id = AddReserve( |
339 |
{ |
339 |
{ |
340 |
branchcode => $branch_1, |
340 |
branchcode => $branch_1, |
341 |
borrowernumber => $requesters{$branch_1}, |
341 |
borrowernumber => $requesters{$branch_1}->borrowernumber, |
342 |
biblionumber => $bibnum, |
342 |
biblionumber => $bibnum, |
343 |
priority => 1, |
343 |
priority => 1, |
344 |
reservation_date => $resdate, |
344 |
reservation_date => $resdate, |
Lines 372-378
my $now_holder = $builder->build_object({ class => 'Koha::Patrons', value => {
Link Here
|
372 |
my $now_reserve_id = AddReserve( |
372 |
my $now_reserve_id = AddReserve( |
373 |
{ |
373 |
{ |
374 |
branchcode => $branch_1, |
374 |
branchcode => $branch_1, |
375 |
borrowernumber => $requesters{$branch_1}, |
375 |
borrowernumber => $requesters{$branch_1}->borrowernumber, |
376 |
biblionumber => $bibnum, |
376 |
biblionumber => $bibnum, |
377 |
priority => 2, |
377 |
priority => 2, |
378 |
reservation_date => dt_from_string(), |
378 |
reservation_date => dt_from_string(), |
Lines 391-402
ModReserve({ reserve_id => $now_reserve_id, rank => 'del', cancellation_reason =
Link Here
|
391 |
|
391 |
|
392 |
# test marking a hold as captured |
392 |
# test marking a hold as captured |
393 |
my $hold_notice_count = count_hold_print_messages(); |
393 |
my $hold_notice_count = count_hold_print_messages(); |
394 |
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0); |
394 |
ModReserveAffect($item->itemnumber, $requesters{$branch_1}->borrowernumber, 0); |
395 |
my $new_count = count_hold_print_messages(); |
395 |
my $new_count = count_hold_print_messages(); |
396 |
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting'); |
396 |
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting'); |
397 |
|
397 |
|
398 |
# test that duplicate notices aren't generated |
398 |
# test that duplicate notices aren't generated |
399 |
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0); |
399 |
ModReserveAffect($item->itemnumber, $requesters{$branch_1}->borrowernumber, 0); |
400 |
$new_count = count_hold_print_messages(); |
400 |
$new_count = count_hold_print_messages(); |
401 |
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)'); |
401 |
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)'); |
402 |
|
402 |
|
Lines 422-428
$resdate->add_duration(DateTime::Duration->new(days => 2));
Link Here
|
422 |
AddReserve( |
422 |
AddReserve( |
423 |
{ |
423 |
{ |
424 |
branchcode => $branch_1, |
424 |
branchcode => $branch_1, |
425 |
borrowernumber => $requesters{$branch_1}, |
425 |
borrowernumber => $requesters{$branch_1}->borrowernumber, |
426 |
biblionumber => $bibnum, |
426 |
biblionumber => $bibnum, |
427 |
priority => 1, |
427 |
priority => 1, |
428 |
reservation_date => $resdate, |
428 |
reservation_date => $resdate, |
Lines 438-444
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
Link Here
|
438 |
AddReserve( |
438 |
AddReserve( |
439 |
{ |
439 |
{ |
440 |
branchcode => $branch_1, |
440 |
branchcode => $branch_1, |
441 |
borrowernumber => $requesters{$branch_1}, |
441 |
borrowernumber => $requesters{$branch_1}->borrowernumber, |
442 |
biblionumber => $bibnum, |
442 |
biblionumber => $bibnum, |
443 |
priority => 1, |
443 |
priority => 1, |
444 |
reservation_date => $resdate, |
444 |
reservation_date => $resdate, |
Lines 448-454
AddReserve(
Link Here
|
448 |
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); |
448 |
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); |
449 |
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' ); |
449 |
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' ); |
450 |
# 9788c: current_holds returns future wait (confirmed future hold) |
450 |
# 9788c: current_holds returns future wait (confirmed future hold) |
451 |
ModReserveAffect( $item->itemnumber, $requesters{$branch_1} , 0); #confirm hold |
451 |
ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 0); #confirm hold |
452 |
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); |
452 |
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } ); |
453 |
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' ); |
453 |
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' ); |
454 |
# End of tests for bug 9788 |
454 |
# End of tests for bug 9788 |
Lines 460-466
is($p, 4, 'CalculatePriority should now return priority 4');
Link Here
|
460 |
AddReserve( |
460 |
AddReserve( |
461 |
{ |
461 |
{ |
462 |
branchcode => $branch_1, |
462 |
branchcode => $branch_1, |
463 |
borrowernumber => $requesters{'CPL2'}, |
463 |
borrowernumber => $requesters{'CPL2'}->borrowernumber, |
464 |
biblionumber => $bibnum2, |
464 |
biblionumber => $bibnum2, |
465 |
priority => $p, |
465 |
priority => $p, |
466 |
} |
466 |
} |
Lines 475-481
is($p, 1, 'CalculatePriority should now return priority 1');
Link Here
|
475 |
AddReserve( |
475 |
AddReserve( |
476 |
{ |
476 |
{ |
477 |
branchcode => $branch_1, |
477 |
branchcode => $branch_1, |
478 |
borrowernumber => $requesters{$branch_1}, |
478 |
borrowernumber => $requesters{$branch_1}->borrowernumber, |
479 |
biblionumber => $bibnum, |
479 |
biblionumber => $bibnum, |
480 |
priority => $p, |
480 |
priority => $p, |
481 |
itemnumber => $item->itemnumber, |
481 |
itemnumber => $item->itemnumber, |
Lines 483-496
AddReserve(
Link Here
|
483 |
); |
483 |
); |
484 |
$p = C4::Reserves::CalculatePriority($bibnum); |
484 |
$p = C4::Reserves::CalculatePriority($bibnum); |
485 |
is($p, 2, 'CalculatePriority should now return priority 2'); |
485 |
is($p, 2, 'CalculatePriority should now return priority 2'); |
486 |
ModReserveAffect( $item->itemnumber, $requesters{$branch_1} , 0); |
486 |
ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 0); |
487 |
$p = C4::Reserves::CalculatePriority($bibnum); |
487 |
$p = C4::Reserves::CalculatePriority($bibnum); |
488 |
is($p, 1, 'CalculatePriority should now return priority 1'); |
488 |
is($p, 1, 'CalculatePriority should now return priority 1'); |
489 |
#add another biblio hold, no resdate |
489 |
#add another biblio hold, no resdate |
490 |
AddReserve( |
490 |
AddReserve( |
491 |
{ |
491 |
{ |
492 |
branchcode => $branch_1, |
492 |
branchcode => $branch_1, |
493 |
borrowernumber => $requesters{'CPL2'}, |
493 |
borrowernumber => $requesters{'CPL2'}->borrowernumber, |
494 |
biblionumber => $bibnum, |
494 |
biblionumber => $bibnum, |
495 |
priority => $p, |
495 |
priority => $p, |
496 |
} |
496 |
} |
Lines 504-510
$resdate->add_duration(DateTime::Duration->new(days => 1));
Link Here
|
504 |
AddReserve( |
504 |
AddReserve( |
505 |
{ |
505 |
{ |
506 |
branchcode => $branch_1, |
506 |
branchcode => $branch_1, |
507 |
borrowernumber => $requesters{'CPL2'}, |
507 |
borrowernumber => $requesters{'CPL2'}->borrowernumber, |
508 |
biblionumber => $bibnum, |
508 |
biblionumber => $bibnum, |
509 |
priority => $p, |
509 |
priority => $p, |
510 |
reservation_date => $resdate, |
510 |
reservation_date => $resdate, |
Lines 556-617
is( $r1[0]->priority, 3, 'priority for hold in future should be correct');
Link Here
|
556 |
is( $r2[0]->priority, 4, 'priority for hold not in future should be correct'); |
556 |
is( $r2[0]->priority, 4, 'priority for hold not in future should be correct'); |
557 |
# end of tests for bug 12630 |
557 |
# end of tests for bug 12630 |
558 |
|
558 |
|
559 |
# Tests for cancel reserves by users from OPAC. |
|
|
560 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
561 |
AddReserve( |
562 |
{ |
563 |
branchcode => $branch_1, |
564 |
borrowernumber => $requesters{$branch_1}, |
565 |
biblionumber => $bibnum, |
566 |
priority => 1, |
567 |
} |
568 |
); |
569 |
my (undef, $canres, undef) = CheckReserves( $item ); |
570 |
|
571 |
is( CanReserveBeCanceledFromOpac(), undef, |
572 |
'CanReserveBeCanceledFromOpac should return undef if called without any parameter' |
573 |
); |
574 |
is( |
575 |
CanReserveBeCanceledFromOpac( $canres->{resserve_id} ), |
576 |
undef, |
577 |
'CanReserveBeCanceledFromOpac should return undef if called without the reserve_id' |
578 |
); |
579 |
is( |
580 |
CanReserveBeCanceledFromOpac( undef, $requesters{CPL} ), |
581 |
undef, |
582 |
'CanReserveBeCanceledFromOpac should return undef if called without borrowernumber' |
583 |
); |
584 |
|
585 |
my $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); |
586 |
is($cancancel, 1, 'Can user cancel its own reserve'); |
587 |
|
588 |
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2}); |
589 |
is($cancancel, 0, 'Other user cant cancel reserve'); |
590 |
|
591 |
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 1); |
592 |
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); |
593 |
is($cancancel, 0, 'Reserve in transfer status cant be canceled'); |
594 |
|
595 |
$dbh->do('DELETE FROM reserves', undef, ($bibnum)); |
596 |
is( CanReserveBeCanceledFromOpac($canres->{resserve_id}, $requesters{$branch_1}), undef, |
597 |
'Cannot cancel a deleted hold' ); |
598 |
|
599 |
AddReserve( |
600 |
{ |
601 |
branchcode => $branch_1, |
602 |
borrowernumber => $requesters{$branch_1}, |
603 |
biblionumber => $bibnum, |
604 |
priority => 1, |
605 |
} |
606 |
); |
607 |
(undef, $canres, undef) = CheckReserves( $item ); |
608 |
|
609 |
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0); |
610 |
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1}); |
611 |
is($cancancel, 0, 'Reserve in waiting status cant be canceled'); |
612 |
|
613 |
# End of tests for bug 12876 |
614 |
|
615 |
#### |
559 |
#### |
616 |
####### Testing Bug 13113 - Prevent juvenile/children from reserving ageRestricted material >>> |
560 |
####### Testing Bug 13113 - Prevent juvenile/children from reserving ageRestricted material >>> |
617 |
#### |
561 |
#### |
618 |
- |
|
|