From 3daef8f17f667e59151f897c03395628bc1732bb Mon Sep 17 00:00:00 2001 From: wajasu Date: Wed, 5 Sep 2012 11:35:42 -0500 Subject: [PATCH] Bug 8728 : Adjust Reserves.t test for resdate and expdate and test setup/teardown Signed-off-by: Chris Cormack Works better now, creats biblio records, and cleans up after itself as well. --- t/db_dependent/Reserves.t | 58 ++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index ca4d42e..1e20318 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,23 @@ 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.9.5