7 use Test::More tests => 4;
14 use lib $FindBin::Bin;
15 use_ok('C4::Reserves');
18 # Setup Test------------------------
20 diag("\nCreating biblio instance for testing.");
21 my ($bibnum, $title, $bibitemnum) = create_helper_biblio();
23 # Helper item for that biblio.
24 diag("Creating item instance for testing.");
25 my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
27 # Modify item; setting barcode.
28 my $testbarcode = '97531';
29 ModItem({ barcode => $testbarcode }, $bibnum, $itemnumber);
32 my $dbh = C4::Context->dbh;
33 my $query = qq/SELECT borrowernumber
36 my $sth = $dbh->prepare($query);
38 my $borrower = $sth->fetchrow_hashref;
40 my $borrowernumber = $borrower->{'borrowernumber'};
41 my $biblionumber = $bibnum;
42 my $barcode = $testbarcode;
50 my $checkitem = undef;
53 my @branches = GetBranchesLoop();
54 my $branch = $branches[0][0]{value};
56 AddReserve($branch, $borrowernumber, $biblionumber,
57 $constraint, $bibitems, $priority, $resdate, $expdate, $notes,
58 $title, $checkitem, $found);
60 my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
61 ok($status eq "Reserved", "CheckReserves Test 1");
63 ($status, $reserve, $all_reserves) = CheckReserves($itemnumber);
64 ok($status eq "Reserved", "CheckReserves Test 2");
66 ($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
67 ok($status eq "Reserved", "CheckReserves Test 3");
70 # Teardown Test---------------------
72 diag("Deleting item testing instance.");
73 DelItem($dbh, $bibnum, $itemnumber);
75 # Delete helper Biblio.
76 diag("Deleting biblio testing instance.");
79 # Helper method to set up a Biblio.
80 sub create_helper_biblio {
81 my $bib = MARC::Record->new();
82 my $title = 'Silence in the library';
84 MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
85 MARC::Field->new('245', ' ', ' ', a => $title),
87 return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');