[PATCH] adjust Reserves.t test for resdate and expdate and test setup/teardown

wajasu matted-34813 at mypacks.net
Wed Sep 5 18:35:42 CEST 2012


---
 t/db_dependent/Reserves.t | 59 ++++++++++++++++++++++++++++++++++-------------
 1 file changed, 43 insertions(+), 16 deletions(-)

diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t
index ca4d42e..d3428b3 100755
--- a/t/db_dependent/Reserves.t
+++ b/t/db_dependent/Reserves.t
@@ -5,6 +5,9 @@ use warnings;
 use C4::Branch;
 
 use Test::More tests => 4;
+use MARC::Record;
+use C4::Biblio;
+use C4::Items;
 
 BEGIN {
 	use FindBin;
@@ -12,6 +15,20 @@ BEGIN {
 	use_ok('C4::Reserves');
 }
 
+# Setup Test------------------------
+# Helper biblio.
+diag("\nCreating biblio instance for testing.");
+my ($bibnum, $title, $bibitemnum) = create_helper_biblio();
+
+# Helper item for that biblio.
+diag("Creating item instance for testing.");
+my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
+
+# Modify item; setting barcode.
+my $testbarcode = '97531';
+ModItem({ barcode => $testbarcode }, $bibnum, $itemnumber);
+
+# Get a borrower
 my $dbh = C4::Context->dbh;
 my $query = qq/SELECT borrowernumber
     FROM   borrowers
@@ -20,27 +37,16 @@ my $sth = $dbh->prepare($query);
 $sth->execute;
 my $borrower = $sth->fetchrow_hashref;
 
-$query = qq/SELECT biblionumber, title, itemnumber, barcode
-    FROM biblio
-    LEFT JOIN items USING (biblionumber)
-    WHERE barcode <> ""
-    AND barcode IS NOT NULL
-    LIMIT  1/;
-$sth = $dbh->prepare($query);
-$sth->execute;
-my $biblio = $sth->fetchrow_hashref;
-
-
 my $borrowernumber = $borrower->{'borrowernumber'};
-my $biblionumber   = $biblio->{'biblionumber'};
-my $itemnumber     = $biblio->{'itemnumber'};
-my $barcode        = $biblio->{'barcode'};
+my $biblionumber   = $bibnum;
+my $barcode        = $testbarcode;
 
 my $constraint     = 'a';
 my $bibitems       = '';
 my $priority       = '1';
+my $resdate        = undef;
+my $expdate        = undef;
 my $notes          = '';
-my $title          = $biblio->{'title'};
 my $checkitem      = undef;
 my $found          = undef;
 
@@ -48,7 +54,7 @@ my @branches = GetBranchesLoop();
 my $branch = $branches[0][0]{value};
 
 AddReserve($branch,    $borrowernumber, $biblionumber,
-        $constraint, $bibitems,  $priority,       $notes,
+        $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
         $title,      $checkitem, $found);
         
 my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode);
@@ -60,3 +66,24 @@ ok($status eq "Reserved", "CheckReserves Test 2");
 ($status, $reserve, $all_reserves) = CheckReserves(undef, $barcode);
 ok($status eq "Reserved", "CheckReserves Test 3");
 
+
+# Teardown Test---------------------
+# Delete item.
+diag("Deleting item testing instance.");
+DelItem($dbh, $bibnum, $itemnumber);
+
+# Delete helper Biblio.
+diag("Deleting biblio testing instance.");
+DelBiblio($bibnum);
+
+# Helper method to set up a Biblio.
+sub create_helper_biblio {
+    my $bib = MARC::Record->new();
+    my $title = 'Silence in the library';
+    $bib->append_fields(
+        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
+        MARC::Field->new('245', ' ', ' ', a => $title),
+    );
+    return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
+}
+
-- 
1.7.11.4


------=_Part_2868_5036580.1346863717269--



More information about the Koha-patches mailing list