3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 65;
23 use DateTime::Duration;
37 use_ok('C4::Reserves');
40 # a very minimal mack of userenv for use by the test of DelItemCheck
41 *C4::Context::userenv = sub {
45 my $dbh = C4::Context->dbh;
48 $dbh->{AutoCommit} = 0;
49 $dbh->{RaiseError} = 1;
51 # Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached
52 $dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a'");
54 # Setup Test------------------------
56 # Add branches if not existing
57 foreach my $addbra ('CPL', 'FPL', 'RPL') {
58 $dbh->do("INSERT INTO branches (branchcode,branchname) VALUES (?,?)", undef, ($addbra,"$addbra branch")) unless GetBranchName($addbra);
61 # Add categories if not existing
62 foreach my $addcat ('S', 'PT') {
63 $dbh->do("INSERT INTO categories (categorycode,hidelostitems,category_type) VALUES (?,?,?)",undef,($addcat, 0, $addcat eq 'S'? 'S': 'A')) unless GetBorrowercategory($addcat);
66 # Create a helper biblio
67 my $bib = MARC::Record->new();
68 my $title = 'Silence in the library';
69 if( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
71 MARC::Field->new('600', '', '1', a => 'Moffat, Steven'),
72 MARC::Field->new('200', '', '', a => $title),
77 MARC::Field->new('100', '', '', a => 'Moffat, Steven'),
78 MARC::Field->new('245', '', '', a => $title),
81 my ($bibnum, $bibitemnum);
82 ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
84 # Create a helper item instance for testing
85 my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
87 # Modify item; setting barcode.
88 my $testbarcode = '97531';
89 ModItem({ barcode => $testbarcode }, $bibnum, $itemnumber);
93 firstname => 'my firstname',
94 surname => 'my surname',
98 my $borrowernumber = AddMember(%data);
99 my $borrower = GetMember( borrowernumber => $borrowernumber );
100 my $biblionumber = $bibnum;
101 my $barcode = $testbarcode;
108 my $checkitem = undef;
111 my @branches = GetBranchesLoop();
112 my $branch = $branches[0][0]{value};
114 AddReserve($branch, $borrowernumber, $biblionumber,
115 $bibitems, $priority, $resdate, $expdate, $notes,
116 $title, $checkitem, $found);
118 my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
120 is($status, "Reserved", "CheckReserves Test 1");
122 ok(exists($reserve->{reserve_id}), 'CheckReserves() include reserve_id in its response');
124 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
125 is($status, "Reserved", "CheckReserves Test 2");
127 ($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
128 is($status, "Reserved", "CheckReserves Test 3");
130 my $ReservesControlBranch = C4::Context->preference('ReservesControlBranch');
131 C4::Context->set_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
133 'ItemHomeLib' eq GetReservesControlBranch(
134 { homebranch => 'ItemHomeLib' },
135 { branchcode => 'PatronHomeLib' }
136 ), "GetReservesControlBranch returns item home branch when set to ItemHomeLibrary"
138 C4::Context->set_preference( 'ReservesControlBranch', 'PatronLibrary' );
140 'PatronHomeLib' eq GetReservesControlBranch(
141 { homebranch => 'ItemHomeLib' },
142 { branchcode => 'PatronHomeLib' }
143 ), "GetReservesControlBranch returns patron home branch when set to PatronLibrary"
145 C4::Context->set_preference( 'ReservesControlBranch', $ReservesControlBranch );
148 ### Regression test for bug 10272
151 $requesters{'CPL'} = AddMember(
153 categorycode => 'PT',
154 surname => 'borrower from CPL',
156 $requesters{'FPL'} = AddMember(
158 categorycode => 'PT',
159 surname => 'borrower from FPL',
161 $requesters{'RPL'} = AddMember(
163 categorycode => 'PT',
164 surname => 'borrower from RPL',
167 # Configure rules so that CPL allows only CPL patrons
168 # to request its items, while FPL will allow its items
169 # to fill holds from anywhere.
171 $dbh->do('DELETE FROM issuingrules');
172 $dbh->do('DELETE FROM branch_item_rules');
173 $dbh->do('DELETE FROM branch_borrower_circ_rules');
174 $dbh->do('DELETE FROM default_borrower_circ_rules');
175 $dbh->do('DELETE FROM default_branch_item_rules');
176 $dbh->do('DELETE FROM default_branch_circ_rules');
177 $dbh->do('DELETE FROM default_circ_rules');
179 q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
180 VALUES (?, ?, ?, ?)},
185 # CPL allows only its own patrons to request its items
187 q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
188 VALUES (?, ?, ?, ?)},
190 'CPL', 10, 1, 'homebranch',
193 # ... while FPL allows anybody to request its items
195 q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch)
196 VALUES (?, ?, ?, ?)},
198 'FPL', 10, 2, 'homebranch',
201 # helper biblio for the bug 10272 regression test
202 my $bib2 = MARC::Record->new();
203 $bib2->append_fields(
204 MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
205 MARC::Field->new('245', ' ', ' ', a => $title),
208 # create one item belonging to FPL and one belonging to CPL
209 my ($bibnum2, $bibitemnum2) = AddBiblio($bib, '');
210 my ($itemnum_cpl, $itemnum_fpl);
211 (undef, undef, $itemnum_cpl) = AddItem({
213 holdingbranch => 'CPL',
214 barcode => 'bug10272_CPL'
216 (undef, undef, $itemnum_fpl) = AddItem({
218 holdingbranch => 'FPL',
219 barcode => 'bug10272_FPL'
222 # Ensure that priorities are numbered correcly when a hold is moved to waiting
224 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
225 AddReserve('RPL', $requesters{'RPL'}, $bibnum2,
226 $bibitems, 1, $resdate, $expdate, $notes,
227 $title, $checkitem, $found);
228 AddReserve('FPL', $requesters{'FPL'}, $bibnum2,
229 $bibitems, 2, $resdate, $expdate, $notes,
230 $title, $checkitem, $found);
231 AddReserve('CPL', $requesters{'CPL'}, $bibnum2,
232 $bibitems, 3, $resdate, $expdate, $notes,
233 $title, $checkitem, $found);
234 ModReserveAffect($itemnum_cpl, $requesters{'RPL'}, 0);
236 # Now it should have different priorities.
237 my $title_reserves = GetReservesFromBiblionumber({biblionumber => $bibnum2});
238 # Sort by reserve number in case the database gives us oddly ordered results
239 my @reserves = sort { $a->{reserve_id} <=> $b->{reserve_id} } @$title_reserves;
240 is($reserves[0]{priority}, 0, 'Item is correctly waiting');
241 is($reserves[1]{priority}, 1, 'Item is correctly priority 1');
242 is($reserves[2]{priority}, 2, 'Item is correctly priority 2');
244 @reserves = Koha::Holds->search({ borrowernumber => $requesters{'RPL'} })->waiting();
245 is( @reserves, 1, 'GetWaiting got only the waiting reserve' );
246 is( $reserves[0]->borrowernumber(), $requesters{'RPL'}, 'GetWaiting got the reserve for the correct borrower' );
249 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
250 AddReserve('RPL', $requesters{'RPL'}, $bibnum2,
251 $bibitems, 1, $resdate, $expdate, $notes,
252 $title, $checkitem, $found);
253 AddReserve('FPL', $requesters{'FPL'}, $bibnum2,
254 $bibitems, 2, $resdate, $expdate, $notes,
255 $title, $checkitem, $found);
256 AddReserve('CPL', $requesters{'CPL'}, $bibnum2,
257 $bibitems, 3, $resdate, $expdate, $notes,
258 $title, $checkitem, $found);
260 # Ensure that the item's home library controls hold policy lookup
261 C4::Context->set_preference( 'ReservesControlBranch', 'ItemHomeLibrary' );
264 # Return the CPL item at FPL. The hold that should be triggered is
265 # the one placed by the CPL patron, as the other two patron's hold
266 # requests cannot be filled by that item per policy.
267 (undef, $messages, undef, undef) = AddReturn('bug10272_CPL', 'FPL');
268 is( $messages->{ResFound}->{borrowernumber},
270 'restrictive library\'s items only fill requests by own patrons (bug 10272)');
272 # Return the FPL item at FPL. The hold that should be triggered is
273 # the one placed by the RPL patron, as that patron is first in line
274 # and RPL imposes no restrictions on whose holds its items can fill.
275 (undef, $messages, undef, undef) = AddReturn('bug10272_FPL', 'FPL');
276 is( $messages->{ResFound}->{borrowernumber},
278 'for generous library, its items fill first hold request in line (bug 10272)');
280 my $reserves = GetReservesFromBiblionumber({biblionumber => $biblionumber});
281 isa_ok($reserves, 'ARRAY');
282 is(scalar @$reserves, 1, "Only one reserves for this biblio");
283 my $reserve_id = $reserves->[0]->{reserve_id};
285 $reserve = GetReserve($reserve_id);
286 isa_ok($reserve, 'HASH', "GetReserve return");
287 is($reserve->{biblionumber}, $biblionumber);
289 $reserve = CancelReserve({reserve_id => $reserve_id});
290 isa_ok($reserve, 'HASH', "CancelReserve return");
291 is($reserve->{biblionumber}, $biblionumber);
293 $reserve = GetReserve($reserve_id);
294 is($reserve, undef, "GetReserve returns undef after deletion");
296 $reserve = CancelReserve({reserve_id => $reserve_id});
297 is($reserve, undef, "CancelReserve return undef if reserve does not exist");
300 # Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
301 # Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
302 # Test 9761a: Add a reserve without date, CheckReserve should return it
303 $resdate= undef; #defaults to today in AddReserve
304 $expdate= undef; #no expdate
305 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
306 AddReserve('CPL', $requesters{'CPL'}, $bibnum,
307 $bibitems, 1, $resdate, $expdate, $notes,
308 $title, $checkitem, $found);
309 ($status)=CheckReserves($itemnumber,undef,undef);
310 is( $status, 'Reserved', 'CheckReserves returns reserve without lookahead');
311 ($status)=CheckReserves($itemnumber,undef,7);
312 is( $status, 'Reserved', 'CheckReserves also returns reserve with lookahead');
314 # Test 9761b: Add a reserve with future date, CheckReserve should not return it
315 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
316 C4::Context->set_preference('AllowHoldDateInFuture', 1);
317 $resdate= dt_from_string();
318 $resdate->add_duration(DateTime::Duration->new(days => 4));
319 $resdate=output_pref($resdate);
320 $expdate= undef; #no expdate
321 AddReserve('CPL', $requesters{'CPL'}, $bibnum,
322 $bibitems, 1, $resdate, $expdate, $notes,
323 $title, $checkitem, $found);
324 ($status)=CheckReserves($itemnumber,undef,undef);
325 is( $status, '', 'CheckReserves returns no future reserve without lookahead');
327 # Test 9761c: Add a reserve with future date, CheckReserve should return it if lookahead is high enough
328 ($status)=CheckReserves($itemnumber,undef,3);
329 is( $status, '', 'CheckReserves returns no future reserve with insufficient lookahead');
330 ($status)=CheckReserves($itemnumber,undef,4);
331 is( $status, 'Reserved', 'CheckReserves returns future reserve with sufficient lookahead');
333 # Test 9761d: Check ResFound message of AddReturn for future hold
334 # Note that AddReturn is in Circulation.pm, but this test really pertains to reserves; AddReturn uses the ConfirmFutureHolds pref when calling CheckReserves
335 # In this test we do not need an issued item; it is just a 'checkin'
336 C4::Context->set_preference('ConfirmFutureHolds', 0);
337 (my $doreturn, $messages)= AddReturn('97531','CPL');
338 is($messages->{ResFound}//'', '', 'AddReturn does not care about future reserve when ConfirmFutureHolds is off');
339 C4::Context->set_preference('ConfirmFutureHolds', 3);
340 ($doreturn, $messages)= AddReturn('97531','CPL');
341 is(exists $messages->{ResFound}?1:0, 0, 'AddReturn ignores future reserve beyond ConfirmFutureHolds days');
342 C4::Context->set_preference('ConfirmFutureHolds', 7);
343 ($doreturn, $messages)= AddReturn('97531','CPL');
344 is(exists $messages->{ResFound}?1:0, 1, 'AddReturn considers future reserve within ConfirmFutureHolds days');
346 # End of tests for bug 9761 (ConfirmFutureHolds)
348 # test marking a hold as captured
349 my $hold_notice_count = count_hold_print_messages();
350 ModReserveAffect($itemnumber, $requesters{'CPL'}, 0);
351 my $new_count = count_hold_print_messages();
352 is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');
354 # test that duplicate notices aren't generated
355 ModReserveAffect($itemnumber, $requesters{'CPL'}, 0);
356 $new_count = count_hold_print_messages();
357 is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');
359 # avoiding the not_same_branch error
360 t::lib::Mocks::mock_preference('IndependentBranches', 0);
362 DelItemCheck($dbh, $bibnum, $itemnumber),
364 'item that is captured to fill a hold cannot be deleted',
367 my $letter = ReserveSlip('CPL', $requesters{'CPL'}, $bibnum);
368 ok(defined($letter), 'can successfully generate hold slip (bug 10949)');
370 # Tests for bug 9788: Does GetReservesFromItemnumber return a future wait?
371 # 9788a: GetReservesFromItemnumber does not return future next available hold
372 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
373 C4::Context->set_preference('ConfirmFutureHolds', 2);
374 C4::Context->set_preference('AllowHoldDateInFuture', 1);
375 $resdate= dt_from_string();
376 $resdate->add_duration(DateTime::Duration->new(days => 2));
377 $resdate=output_pref($resdate);
378 AddReserve('CPL', $requesters{'CPL'}, $bibnum,
379 $bibitems, 1, $resdate, $expdate, $notes,
380 $title, $checkitem, $found);
381 my @results= GetReservesFromItemnumber($itemnumber);
382 is(defined $results[3]?1:0, 0, 'GetReservesFromItemnumber does not return a future next available hold');
383 # 9788b: GetReservesFromItemnumber does not return future item level hold
384 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
385 AddReserve('CPL', $requesters{'CPL'}, $bibnum,
386 $bibitems, 1, $resdate, $expdate, $notes,
387 $title, $itemnumber, $found); #item level hold
388 @results= GetReservesFromItemnumber($itemnumber);
389 is(defined $results[3]?1:0, 0, 'GetReservesFromItemnumber does not return a future item level hold');
390 # 9788c: GetReservesFromItemnumber returns future wait (confirmed future hold)
391 ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); #confirm hold
392 @results= GetReservesFromItemnumber($itemnumber);
393 is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)');
394 # End of tests for bug 9788
396 # Tests for CalculatePriority (bug 8918)
397 my $p = C4::Reserves::CalculatePriority($bibnum2);
398 is($p, 4, 'CalculatePriority should now return priority 4');
400 AddReserve('CPL', $requesters{'CPL'}, $bibnum2,
401 $bibitems, $p, $resdate, $expdate, $notes,
402 $title, $checkitem, $found);
403 $p = C4::Reserves::CalculatePriority($bibnum2);
404 is($p, 5, 'CalculatePriority should now return priority 5');
405 #some tests on bibnum
406 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
407 $p = C4::Reserves::CalculatePriority($bibnum);
408 is($p, 1, 'CalculatePriority should now return priority 1');
409 #add a new reserve and confirm it to waiting
410 AddReserve('CPL', $requesters{'CPL'}, $bibnum,
411 $bibitems, $p, $resdate, $expdate, $notes,
412 $title, $itemnumber, $found);
413 $p = C4::Reserves::CalculatePriority($bibnum);
414 is($p, 2, 'CalculatePriority should now return priority 2');
415 ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0);
416 $p = C4::Reserves::CalculatePriority($bibnum);
417 is($p, 1, 'CalculatePriority should now return priority 1');
418 #add another biblio hold, no resdate
419 AddReserve('CPL', $requesters{'CPL'}, $bibnum,
420 $bibitems, $p, $resdate, $expdate, $notes,
421 $title, $checkitem, $found);
422 $p = C4::Reserves::CalculatePriority($bibnum);
423 is($p, 2, 'CalculatePriority should now return priority 2');
424 #add another future hold
425 C4::Context->set_preference('AllowHoldDateInFuture', 1);
426 $resdate= dt_from_string();
427 $resdate->add_duration(DateTime::Duration->new(days => 1));
428 AddReserve('CPL', $requesters{'CPL'}, $bibnum,
429 $bibitems, $p, output_pref($resdate), $expdate, $notes,
430 $title, $checkitem, $found);
431 $p = C4::Reserves::CalculatePriority($bibnum);
432 is($p, 2, 'CalculatePriority should now still return priority 2');
433 #calc priority with future resdate
434 $p = C4::Reserves::CalculatePriority($bibnum, $resdate);
435 is($p, 3, 'CalculatePriority should now return priority 3');
436 # End of tests for bug 8918
438 # Tests for cancel reserves by users from OPAC.
439 $dbh->do('DELETE FROM reserves', undef, ($bibnum));
440 AddReserve('CPL', $requesters{'CPL'}, $item_bibnum,
441 $bibitems, 1, undef, $expdate, $notes,
442 $title, $checkitem, '');
443 my (undef, $canres, undef) = CheckReserves($itemnumber);
445 is( CanReserveBeCanceledFromOpac(), undef,
446 'CanReserveBeCanceledFromOpac should return undef if called without any parameter'
449 CanReserveBeCanceledFromOpac( $canres->{resserve_id} ),
451 'CanReserveBeCanceledFromOpac should return undef if called without the reserve_id'
454 CanReserveBeCanceledFromOpac( undef, $requesters{CPL} ),
456 'CanReserveBeCanceledFromOpac should return undef if called without borrowernumber'
459 my $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'});
460 is($cancancel, 1, 'Can user cancel its own reserve');
462 $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'FPL'});
463 is($cancancel, 0, 'Other user cant cancel reserve');
465 ModReserveAffect($itemnumber, $requesters{'CPL'}, 1);
466 $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'});
467 is($cancancel, 0, 'Reserve in transfer status cant be canceled');
469 $dbh->do('DELETE FROM reserves', undef, ($bibnum));
470 AddReserve('CPL', $requesters{'CPL'}, $item_bibnum,
471 $bibitems, 1, undef, $expdate, $notes,
472 $title, $checkitem, '');
473 (undef, $canres, undef) = CheckReserves($itemnumber);
475 ModReserveAffect($itemnumber, $requesters{'CPL'}, 0);
476 $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{'CPL'});
477 is($cancancel, 0, 'Reserve in waiting status cant be canceled');
479 # End of tests for bug 12876
482 ####### Testing Bug 13113 - Prevent juvenile/children from reserving ageRestricted material >>>
485 C4::Context->set_preference( 'AgeRestrictionMarker', 'FSK|PEGI|Age|K' );
487 #Reserving an not-agerestricted Biblio by a Borrower with no dateofbirth is tested previously.
489 #Set the ageRestriction for the Biblio
490 my $record = GetMarcBiblio( $bibnum );
491 my ( $ageres_tagid, $ageres_subfieldid ) = GetMarcFromKohaField( "biblioitems.agerestriction" );
492 $record->append_fields( MARC::Field->new($ageres_tagid, '', '', $ageres_subfieldid => 'PEGI 16') );
493 C4::Biblio::ModBiblio( $record, $bibnum, '' );
495 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving an ageRestricted Biblio without a borrower dateofbirth succeeds" );
497 #Set the dateofbirth for the Borrower making him "too young".
498 my $now = DateTime->now();
499 C4::Members::SetAge( $borrower, '0015-00-00' );
500 C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
502 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'ageRestricted', "Reserving a 'PEGI 16' Biblio by a 15 year old borrower fails");
504 #Set the dateofbirth for the Borrower making him "too old".
505 C4::Members::SetAge( $borrower, '0030-00-00' );
506 C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
508 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
510 ####### EO Bug 13113 <<<
513 my $item = GetItem($itemnumber);
515 ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
517 my $itype = C4::Reserves::_get_itype($item);
518 my $categorycode = $borrower->{categorycode};
519 my $holdingbranch = $item->{holdingbranch};
520 my $rule = C4::Circulation::GetIssuingRule($categorycode, $itype, $holdingbranch);
523 "UPDATE issuingrules SET onshelfholds = 1 WHERE categorycode = ? AND itemtype= ? and branchcode = ?",
525 $rule->{categorycode}, $rule->{itemtype}, $rule->{branchcode}
527 ok( C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() allowed" );
529 "UPDATE issuingrules SET onshelfholds = 0 WHERE categorycode = ? AND itemtype= ? and branchcode = ?",
531 $rule->{categorycode}, $rule->{itemtype}, $rule->{branchcode}
533 ok( !C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() disallowed" );
535 # Tests for bug 14464
537 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
538 my ( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
539 ok( !$bz14464_fines, 'Bug 14464 - No fines at beginning' );
541 # First, test cancelling a reserve when there's no charge configured.
542 t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0);
544 my $bz14464_reserve = AddReserve(
559 ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
561 CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
563 ( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
564 ok( !$bz14464_fines, 'Bug 14464 - No fines after cancelling reserve with no charge configured' );
566 # Then, test cancelling a reserve when there's no charge desired.
567 t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42);
569 $bz14464_reserve = AddReserve(
584 ok( $bz14464_reserve, 'Bug 14464 - 2nd reserve correctly created' );
586 CancelReserve({ reserve_id => $bz14464_reserve });
588 ( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
589 ok( !$bz14464_fines, 'Bug 14464 - No fines after cancelling reserve with no charge desired' );
591 # Finally, test cancelling a reserve when there's a charge desired and configured.
592 $bz14464_reserve = AddReserve(
607 ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
609 CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
611 ( undef, undef, $bz14464_fines ) = GetMemberIssuesAndFines( $borrowernumber );
612 is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' );
616 sub count_hold_print_messages {
617 my $message_count = $dbh->selectall_arrayref(q{
620 WHERE letter_code = 'HOLD'
621 AND message_transport_type = 'print'
623 return $message_count->[0]->[0];