Bug 7534: Validate pickup location in CanBook/ItemBeReserved
[koha.git] / t / db_dependent / Holds.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use t::lib::Mocks;
6 use t::lib::TestBuilder;
7
8 use C4::Context;
9
10 use Test::More tests => 62;
11 use MARC::Record;
12 use Koha::Patrons;
13 use C4::Items;
14 use C4::Biblio;
15 use C4::Reserves;
16 use C4::Calendar;
17
18 use Koha::Database;
19 use Koha::DateUtils qw( dt_from_string output_pref );
20 use Koha::Biblios;
21 use Koha::Holds;
22 use Koha::Items;
23 use Koha::Libraries;
24
25 BEGIN {
26     use FindBin;
27     use lib $FindBin::Bin;
28 }
29
30 my $schema  = Koha::Database->new->schema;
31 $schema->storage->txn_begin;
32
33 my $builder = t::lib::TestBuilder->new();
34 my $dbh     = C4::Context->dbh;
35
36 # Create two random branches
37 my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode };
38 my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode };
39
40 my $category = $builder->build({ source => 'Category' });
41
42 my $borrowers_count = 5;
43
44 $dbh->do('DELETE FROM itemtypes');
45 $dbh->do('DELETE FROM reserves');
46 my $insert_sth = $dbh->prepare('INSERT INTO itemtypes (itemtype) VALUES (?)');
47 $insert_sth->execute('CAN');
48 $insert_sth->execute('CANNOT');
49 $insert_sth->execute('DUMMY');
50 $insert_sth->execute('ONLY1');
51
52 # Setup Test------------------------
53 # Create a biblio instance for testing
54 my ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
55
56 # Create item instance for testing.
57 my ($item_bibnum, $item_bibitemnum, $itemnumber)
58     = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
59
60 # Create some borrowers
61 my @borrowernumbers;
62 foreach (1..$borrowers_count) {
63     my $borrowernumber = Koha::Patron->new({
64         firstname =>  'my firstname',
65         surname => 'my surname ' . $_,
66         categorycode => $category->{categorycode},
67         branchcode => $branch_1,
68     })->store->borrowernumber;
69     push @borrowernumbers, $borrowernumber;
70 }
71
72 my $biblionumber = $bibnum;
73
74 # Create five item level holds
75 foreach my $borrowernumber ( @borrowernumbers ) {
76     AddReserve(
77         $branch_1,
78         $borrowernumber,
79         $biblionumber,
80         my $bibitems = q{},
81         my $priority = C4::Reserves::CalculatePriority( $biblionumber ),
82         my $resdate,
83         my $expdate,
84         my $notes = q{},
85         $title,
86         my $checkitem = $itemnumber,
87         my $found,
88     );
89 }
90
91 my $biblio = Koha::Biblios->find( $biblionumber );
92 my $holds = $biblio->holds;
93 is( $holds->count, $borrowers_count, 'Test GetReserves()' );
94 is( $holds->next->priority, 1, "Reserve 1 has a priority of 1" );
95 is( $holds->next->priority, 2, "Reserve 2 has a priority of 2" );
96 is( $holds->next->priority, 3, "Reserve 3 has a priority of 3" );
97 is( $holds->next->priority, 4, "Reserve 4 has a priority of 4" );
98 is( $holds->next->priority, 5, "Reserve 5 has a priority of 5" );
99
100 my $item = Koha::Items->find( $itemnumber );
101 $holds = $item->current_holds;
102 my $first_hold = $holds->next;
103 my $reservedate = $first_hold->reservedate;
104 my $borrowernumber = $first_hold->borrowernumber;
105 my $branch_1code = $first_hold->branchcode;
106 my $reserve_id = $first_hold->reserve_id;
107 is( $reservedate, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), "holds_placed_today should return a valid reserve date");
108 is( $borrowernumber, $borrowernumbers[0], "holds_placed_today should return a valid borrowernumber");
109 is( $branch_1code, $branch_1, "holds_placed_today should return a valid branchcode");
110 ok($reserve_id, "Test holds_placed_today()");
111
112 my $hold = Koha::Holds->find( $reserve_id );
113 ok( $hold, "Koha::Holds found the hold" );
114 my $hold_biblio = $hold->biblio();
115 ok( $hold_biblio, "Got biblio using biblio() method" );
116 ok( $hold_biblio == $hold->biblio(), "biblio method returns stashed biblio" );
117 my $hold_item = $hold->item();
118 ok( $hold_item, "Got item using item() method" );
119 ok( $hold_item == $hold->item(), "item method returns stashed item" );
120 my $hold_branch = $hold->branch();
121 ok( $hold_branch, "Got branch using branch() method" );
122 ok( $hold_branch == $hold->branch(), "branch method returns stashed branch" );
123 my $hold_found = $hold->found();
124 $hold->set({ found => 'W'})->store();
125 is( Koha::Holds->waiting()->count(), 1, "Koha::Holds->waiting returns waiting holds" );
126 is( Koha::Holds->unfilled()->count(), 4, "Koha::Holds->unfilled returns unfilled holds" );
127
128 my $patron = Koha::Patrons->find( $borrowernumbers[0] );
129 $holds = $patron->holds;
130 is( $holds->next->borrowernumber, $borrowernumbers[0], "Test Koha::Patron->holds");
131
132
133 $holds = $item->current_holds;
134 $first_hold = $holds->next;
135 $borrowernumber = $first_hold->borrowernumber;
136 $branch_1code = $first_hold->branchcode;
137 $reserve_id = $first_hold->reserve_id;
138
139 ModReserve({
140     reserve_id    => $reserve_id,
141     rank          => '4',
142     branchcode    => $branch_1,
143     itemnumber    => $itemnumber,
144     suspend_until => output_pref( { dt => dt_from_string( "2013-01-01", "iso" ), dateonly => 1 } ),
145 });
146
147 $hold = Koha::Holds->find( $reserve_id );
148 ok( $hold->priority eq '4', "Test ModReserve, priority changed correctly" );
149 ok( $hold->suspend, "Test ModReserve, suspend hold" );
150 is( $hold->suspend_until, '2013-01-01 00:00:00', "Test ModReserve, suspend until date" );
151
152 ModReserve({ # call without reserve_id
153     rank          => '3',
154     biblionumber  => $item_bibnum,
155     itemnumber    => $itemnumber,
156     borrowernumber => $borrowernumber,
157 });
158 $hold = Koha::Holds->find( $reserve_id );
159 ok( $hold->priority eq '3', "Test ModReserve, priority changed correctly" );
160
161 ToggleSuspend( $reserve_id );
162 $hold = Koha::Holds->find( $reserve_id );
163 ok( ! $hold->suspend, "Test ToggleSuspend(), no date" );
164
165 ToggleSuspend( $reserve_id, '2012-01-01' );
166 $hold = Koha::Holds->find( $reserve_id );
167 is( $hold->suspend_until, '2012-01-01 00:00:00', "Test ToggleSuspend(), with date" );
168
169 AutoUnsuspendReserves();
170 $hold = Koha::Holds->find( $reserve_id );
171 ok( ! $hold->suspend, "Test AutoUnsuspendReserves()" );
172
173 SuspendAll(
174     borrowernumber => $borrowernumber,
175     biblionumber   => $biblionumber,
176     suspend => 1,
177     suspend_until => '2012-01-01',
178 );
179 $hold = Koha::Holds->find( $reserve_id );
180 is( $hold->suspend, 1, "Test SuspendAll()" );
181 is( $hold->suspend_until, '2012-01-01 00:00:00', "Test SuspendAll(), with date" );
182
183 SuspendAll(
184     borrowernumber => $borrowernumber,
185     biblionumber   => $biblionumber,
186     suspend => 0,
187 );
188 $hold = Koha::Holds->find( $reserve_id );
189 is( $hold->suspend, 0, "Test resuming with SuspendAll()" );
190 is( $hold->suspend_until, undef, "Test resuming with SuspendAll(), should have no suspend until date" );
191
192 # Add a new hold for the borrower whose hold we canceled earlier, this time at the bib level
193 AddReserve(
194     $branch_1,
195     $borrowernumbers[0],
196     $biblionumber,
197     my $bibitems = q{},
198     my $priority,
199     my $resdate,
200     my $expdate,
201     my $notes = q{},
202     $title,
203     my $checkitem,
204     my $found,
205 );
206 $patron = Koha::Patrons->find( $borrowernumber );
207 $holds = $patron->holds;
208 my $reserveid = Koha::Holds->search({ biblionumber => $bibnum, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
209 ModReserveMinusPriority( $itemnumber, $reserveid );
210 $holds = $patron->holds;
211 is( $holds->next->itemnumber, $itemnumber, "Test ModReserveMinusPriority()" );
212
213 $holds = $biblio->holds;
214 $hold = $holds->next;
215 AlterPriority( 'top', $hold->reserve_id );
216 $hold = Koha::Holds->find( $reserveid );
217 is( $hold->priority, '1', "Test AlterPriority(), move to top" );
218
219 AlterPriority( 'down', $hold->reserve_id );
220 $hold = Koha::Holds->find( $reserveid );
221 is( $hold->priority, '2', "Test AlterPriority(), move down" );
222
223 AlterPriority( 'up', $hold->reserve_id );
224 $hold = Koha::Holds->find( $reserveid );
225 is( $hold->priority, '1', "Test AlterPriority(), move up" );
226
227 AlterPriority( 'bottom', $hold->reserve_id );
228 $hold = Koha::Holds->find( $reserveid );
229 is( $hold->priority, '6', "Test AlterPriority(), move to bottom" );
230
231 # Regression test for bug 2394
232 #
233 # If IndependentBranches is ON and canreservefromotherbranches is OFF,
234 # a patron is not permittedo to request an item whose homebranch (i.e.,
235 # owner of the item) is different from the patron's own library.
236 # However, if canreservefromotherbranches is turned ON, the patron can
237 # create such hold requests.
238 #
239 # Note that canreservefromotherbranches has no effect if
240 # IndependentBranches is OFF.
241
242 my ($foreign_bibnum, $foreign_title, $foreign_bibitemnum) = create_helper_biblio('DUMMY');
243 my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber)
244   = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_bibnum);
245 $dbh->do('DELETE FROM issuingrules');
246 $dbh->do(
247     q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
248       VALUES (?, ?, ?, ?, ?)},
249     {},
250     '*', '*', '*', 25, 99
251 );
252 $dbh->do(
253     q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
254       VALUES (?, ?, ?, ?, ?)},
255     {},
256     '*', '*', 'CANNOT', 0, 99
257 );
258
259 # make sure some basic sysprefs are set
260 t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary');
261 t::lib::Mocks::mock_preference('item-level_itypes', 1);
262
263 # if IndependentBranches is OFF, a $branch_1 patron can reserve an $branch_2 item
264 t::lib::Mocks::mock_preference('IndependentBranches', 0);
265 ok(
266     CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'OK',
267     '$branch_1 patron allowed to reserve $branch_2 item with IndependentBranches OFF (bug 2394)'
268 );
269
270 # if IndependentBranches is OFF, a $branch_1 patron cannot reserve an $branch_2 item
271 t::lib::Mocks::mock_preference('IndependentBranches', 1);
272 t::lib::Mocks::mock_preference('canreservefromotherbranches', 0);
273 ok(
274     CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'cannotReserveFromOtherBranches',
275     '$branch_1 patron NOT allowed to reserve $branch_2 item with IndependentBranches ON ... (bug 2394)'
276 );
277
278 # ... unless canreservefromotherbranches is ON
279 t::lib::Mocks::mock_preference('canreservefromotherbranches', 1);
280 ok(
281     CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'OK',
282     '... unless canreservefromotherbranches is ON (bug 2394)'
283 );
284
285 {
286     # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
287     ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
288     ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
289     my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $bibnum, '', 1);
290     ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
291     my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $bibnum, '', 2);
292     ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
293     my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $bibnum, '', 3);
294     my $hhh = Koha::Holds->search({ biblionumber => $bibnum });
295     my $hold3 = Koha::Holds->find( $reserveid3 );
296     is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
297     ModReserve({ reserve_id => $reserveid1, rank => 'del' });
298     ModReserve({ reserve_id => $reserveid2, rank => 'del' });
299     is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
300 }
301
302 ModItem({ damaged => 1 }, $item_bibnum, $itemnumber);
303 t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
304 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 $hold = Koha::Hold->new(
308     {
309         borrowernumber => $borrowernumbers[0],
310         itemnumber     => $itemnumber,
311         biblionumber   => $item_bibnum,
312     }
313 )->store();
314 is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
315     'itemAlreadyOnHold',
316     "Patron cannot place a second item level hold for a given item" );
317 $hold->delete();
318
319 t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
320 ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" );
321 ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" );
322
323 # Regression test for bug 9532
324 ($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
325 ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum);
326 AddReserve(
327     $branch_1,
328     $borrowernumbers[0],
329     $bibnum,
330     '',
331     1,
332 );
333 is(
334     CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves',
335     "cannot request item if policy that matches on item-level item type forbids it"
336 );
337 ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber);
338 ok(
339     CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK',
340     "can request item if policy that matches on item type allows it"
341 );
342
343 t::lib::Mocks::mock_preference('item-level_itypes', 0);
344 ModItem({ itype => undef }, $item_bibnum, $itemnumber);
345 ok(
346     CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves',
347     "cannot request item if policy that matches on bib-level item type forbids it (bug 9532)"
348 );
349
350
351 # Test branch item rules
352
353 $dbh->do('DELETE FROM issuingrules');
354 $dbh->do(
355     q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed)
356       VALUES (?, ?, ?, ?)},
357     {},
358     '*', '*', '*', 25
359 );
360 $dbh->do('DELETE FROM branch_item_rules');
361 $dbh->do('DELETE FROM default_branch_circ_rules');
362 $dbh->do('DELETE FROM default_branch_item_rules');
363 $dbh->do('DELETE FROM default_circ_rules');
364 $dbh->do(q{
365     INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
366     VALUES (?, ?, ?, ?)
367 }, {}, $branch_1, 'CANNOT', 0, 'homebranch');
368 $dbh->do(q{
369     INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch)
370     VALUES (?, ?, ?, ?)
371 }, {}, $branch_1, 'CAN', 1, 'homebranch');
372 ($bibnum, $title, $bibitemnum) = create_helper_biblio('CANNOT');
373 ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
374     { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum);
375 is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'notReservable',
376     "CanItemBeReserved should return 'notReservable'");
377
378 ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
379     { homebranch => $branch_2, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum);
380 is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status},
381     'cannotReserveFromOtherBranches',
382     "CanItemBeReserved should return 'cannotReserveFromOtherBranches'");
383
384 ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem(
385     { homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $bibnum);
386 is(CanItemBeReserved($borrowernumbers[0], $itemnumber)->{status}, 'OK',
387     "CanItemBeReserved should return 'OK'");
388
389 # Bug 12632
390 t::lib::Mocks::mock_preference( 'item-level_itypes',     1 );
391 t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
392
393 $dbh->do('DELETE FROM reserves');
394 $dbh->do('DELETE FROM issues');
395 $dbh->do('DELETE FROM items');
396 $dbh->do('DELETE FROM biblio');
397
398 ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
399 ( $item_bibnum, $item_bibitemnum, $itemnumber )
400     = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
401
402 $dbh->do(
403     q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
404       VALUES (?, ?, ?, ?, ?)},
405     {},
406     '*', '*', 'ONLY1', 1, 99
407 );
408 is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
409     'OK', 'Patron can reserve item with hold limit of 1, no holds placed' );
410
411 my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
412
413 is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
414     'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
415
416 subtest 'Test max_holds per library/patron category' => sub {
417     plan tests => 6;
418
419     $dbh->do('DELETE FROM reserves');
420     $dbh->do('DELETE FROM issuingrules');
421
422     ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
423     ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
424       AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
425         $bibnum );
426     $dbh->do(
427         q{
428             INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
429             VALUES (?, ?, ?, ?, ?)
430         },
431         {},
432         '*', '*', 'TEST', 99, 99
433     );
434     AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
435     AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
436     AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
437
438     my $count =
439       Koha::Holds->search( { borrowernumber => $borrowernumbers[0] } )->count();
440     is( $count, 3, 'Patron now has 3 holds' );
441
442     my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
443     is( $ret->{status}, 'OK', 'Patron can place hold with no borrower circ rules' );
444
445     my $rule_all = $schema->resultset('DefaultBorrowerCircRule')->new(
446         {
447             categorycode => $category->{categorycode},
448             max_holds    => 3,
449         }
450     )->insert();
451
452     my $rule_branch = $schema->resultset('BranchBorrowerCircRule')->new(
453         {
454             branchcode   => $branch_1,
455             categorycode => $category->{categorycode},
456             max_holds    => 5,
457         }
458     )->insert();
459
460     $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
461     is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' );
462
463     $rule_branch->delete();
464
465     $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
466     is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' );
467
468     $rule_all->delete();
469     $rule_branch->max_holds(3);
470     $rule_branch->insert();
471
472     $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
473     is( $ret->{status}, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' );
474
475     $rule_branch->max_holds(5);
476     $rule_branch->update();
477     $rule_all->max_holds(5);
478     $rule_all->insert();
479
480     $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber );
481     is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
482 };
483
484 subtest 'Pickup location availability tests' => sub {
485     plan tests => 3;
486
487     my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
488     my ( $item_bibnum, $item_bibitemnum, $itemnumber )
489     = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
490     my $item = Koha::Items->find($itemnumber);
491     my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
492     my $library = Koha::Libraries->find($branch_to);
493     my $patron = $builder->build({ source => 'Borrower' })->{ borrowernumber };
494
495     t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
496     t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
497     $library->pickup_location('1')->store;
498     is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
499        'OK', 'Library is a pickup location');
500     $library->pickup_location('0')->store;
501     is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
502        'libraryNotPickupLocation', 'Library is not a pickup location');
503     is(CanItemBeReserved($patron, $item->itemnumber, 'nonexistent'),
504        'libraryNotFound', 'Cannot set unknown library as pickup location');
505 };
506
507 # Helper method to set up a Biblio.
508 sub create_helper_biblio {
509     my $itemtype = shift;
510     my $bib = MARC::Record->new();
511     my $title = 'Silence in the library';
512     $bib->append_fields(
513         MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
514         MARC::Field->new('245', ' ', ' ', a => $title),
515         MARC::Field->new('942', ' ', ' ', c => $itemtype),
516     );
517     return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
518 }