From e370043eee90fb705668d0e46c912b65e494d15f Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 9 Jul 2013 14:13:38 +0000 Subject: [PATCH] Bug 9394: (follow-up) modernize test cases - wrap in a transaction - create the patron records needed for the test To test: [1] Run prove -v t/db_dependent/Holds.t [2] Verify that all tests have passed. [3] Verify that the additional patron records created by the test no longer exist in the database. Signed-off-by: Galen Charlton --- t/db_dependent/Holds.t | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index c7a95fd..0f70872 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -8,6 +8,7 @@ use Test::More tests => 19; use MARC::Record; use C4::Biblio; use C4::Items; +use C4::Members; BEGIN { use FindBin; @@ -15,6 +16,12 @@ BEGIN { use_ok('C4::Reserves'); } +my $dbh = C4::Context->dbh; + +# Start transaction +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + my $borrowers_count = 5; # Setup Test------------------------ @@ -26,14 +33,16 @@ my ($bibnum, $title, $bibitemnum) = create_helper_biblio(); diag("Creating item instance for testing."); my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); -# Get a borrower -my $dbh = C4::Context->dbh; -my $query = "SELECT borrowernumber FROM borrowers LIMIT $borrowers_count"; -my $sth = $dbh->prepare($query); -$sth->execute; +# Create some borrowers my @borrowernumbers; -while ( my $row = $sth->fetchrow_hashref ) { - push( @borrowernumbers, $row->{'borrowernumber'} ); +foreach (1..$borrowers_count) { + my $borrowernumber = AddMember( + firstname => 'my firstname', + surname => 'my surname ' . $_, + categorycode => 'S', + branchcode => 'CPL', + ); + push @borrowernumbers, $borrowernumber; } my $biblionumber = $bibnum; @@ -155,18 +164,6 @@ AlterPriority( 'bottom', $reserve->{'reserve_id'} ); $reserve = GetReserve( $reserve->{'reserve_id'} ); ok( $reserve->{'priority'} eq '5', "Test AlterPriority(), move to bottom" ); -# Delete the reserves -diag("Deleting holds."); -$dbh->do("DELETE FROM reserves WHERE biblionumber = ?", undef, ( $biblionumber ) ); - -# 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(); -- 1.7.10.4