From 5fb46753d7a5caa8c1a9930e9ca0fea8f406b8b3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 May 2013 16:37:10 +0200 Subject: [PATCH] Bug 10289: UT: Reserves.t needs to create its own data Try before the patch: prove t/db_dependent/Reserves.t And after, it should produce: t/db_dependent/Reserves.t .. 1/4 # # Creating biblio instance for testing. # Creating item instance for testing. # Deleting item testing instance. # Deleting biblio testing instance. # Deleting borrower. t/db_dependent/Reserves.t .. ok All tests successful. Files=1, Tests=4, 1 wallclock secs ( 0.02 usr 0.01 sys + 0.39 cusr 0.02 csys = 0.44 CPU) Result: PASS --- t/db_dependent/Reserves.t | 58 ++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 1e20318..9dc68e3 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -1,25 +1,30 @@ #!/usr/bin/perl -use strict; -use warnings; -use C4::Branch; +use Modern::Perl; use Test::More tests => 4; use MARC::Record; + +use C4::Branch; use C4::Biblio; use C4::Items; +use C4::Members; BEGIN { - use FindBin; - use lib $FindBin::Bin; - use_ok('C4::Reserves'); + use_ok('C4::Reserves'); } # Setup Test------------------------ # Helper biblio. diag("\nCreating biblio instance for testing."); -my ($bibnum, $title, $bibitemnum) = 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), +); +my ($bibnum, $bibitemnum); +($bibnum, $title, $bibitemnum) = AddBiblio($bib, ''); # Helper item for that biblio. diag("Creating item instance for testing."); my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); @@ -28,16 +33,16 @@ my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL' my $testbarcode = '97531'; ModItem({ barcode => $testbarcode }, $bibnum, $itemnumber); -# Get a borrower -my $dbh = C4::Context->dbh; -my $query = qq/SELECT borrowernumber - FROM borrowers - LIMIT 1/; -my $sth = $dbh->prepare($query); -$sth->execute; -my $borrower = $sth->fetchrow_hashref; - -my $borrowernumber = $borrower->{'borrowernumber'}; +# Create a borrower +my %data = ( + cardnumber => 'CARDNUMBER42', + firstname => 'my firstname', + surname => 'my surname', + categorycode => 'S', + branchcode => 'CPL', +); +my $borrowernumber = AddMember(%data); +my $borrower = GetMember( borrowernumber => $borrowernumber ); my $biblionumber = $bibnum; my $barcode = $testbarcode; @@ -56,7 +61,7 @@ my $branch = $branches[0][0]{value}; AddReserve($branch, $borrowernumber, $biblionumber, $constraint, $bibitems, $priority, $resdate, $expdate, $notes, $title, $checkitem, $found); - + my ($status, $reserve, $all_reserves) = CheckReserves($itemnumber, $barcode); ok($status eq "Reserved", "CheckReserves Test 1"); @@ -70,19 +75,14 @@ ok($status eq "Reserved", "CheckReserves Test 3"); # Teardown Test--------------------- # Delete item. diag("Deleting item testing instance."); +my $dbh = C4::Context->dbh; 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, ''); -} +# Delete borrower +diag("Deleting borrower."); +DelMember($borrowernumber); + -- 1.7.10.4