From 88c877ab2d09382c34d20813595c2e112e08136f Mon Sep 17 00:00:00 2001 From: Kenza Zaki Date: Mon, 1 Jul 2013 10:48:03 +0200 Subject: [PATCH] Bug 10499: VirtualShelves.t - wrap tests in a database transaction Before this patch, the queries in VirtualShelves.t were committed in the database and have to be removed at the end. This patch wraps tests in a database transaction. Test plan: prove t/db_dependent/VirtualShelves.t VirtualShelves.t .. ok All tests successful. Files=1, Tests=72, 1 wallclock secs ( 0.06 usr 0.00 sys + 0.72 cusr 0.06 csys = 0.84 CPU) Result: PASS Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer All tests pass. Signed-off-by: Galen Charlton (cherry picked from commit d2a756128853e9d3a1e0b99f47a04c9e0f31de75) Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/VirtualShelves.t | 35 +++++++++++---------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/t/db_dependent/VirtualShelves.t b/t/db_dependent/VirtualShelves.t index 563eeca8bb..9f3f1b04c0 100755 --- a/t/db_dependent/VirtualShelves.t +++ b/t/db_dependent/VirtualShelves.t @@ -5,14 +5,18 @@ # Larger modifications by Jonathan Druart and Marcel de Rooy use Modern::Perl; -use Test::More tests => 81; +use Test::More tests => 71; use MARC::Record; use C4::Biblio qw( AddBiblio DelBiblio ); use C4::Context; -# Getting some borrowers from database. + my $dbh = C4::Context->dbh; +$dbh->{RaiseError} = 1; +$dbh->{AutoCommit} = 0; + +# Getting some borrowers from database. my $query = q{SELECT borrowernumber FROM borrowers LIMIT 10}; my $borr_ref=$dbh->selectall_arrayref($query); if(@$borr_ref==0) { #no borrowers? should not occur of course @@ -46,7 +50,7 @@ use_ok('C4::VirtualShelves'); # creating shelves (could be <10 when names are not unique) my @shelves; -for(my $i=0; $i<10;$i++) { +for my $i(0..9){ my $name= randomname(); my $catg= int(rand(2))+1; my $ShelfNumber= AddShelf( @@ -73,7 +77,7 @@ for(my $i=0; $i<10;$i++) { } # try to create shelves with duplicate names -for(my $i=0;$i<10;$i++){ +for my $i(0..9){ if($shelves[$i]->{number}<0) { ok(1, 'skip duplicate test for earlier name clash'); next; @@ -108,7 +112,7 @@ for(my $i=0;$i<10;$i++){ # usage : $biblist = GetShelfContents($shelfnumber); my %used = (); -for(my $i=0; $i<10;$i++){ +for my $i(0..9){ my $bib = $biblionumbers[int(rand(9))]; my $shelfnumber = $shelves[int(rand(9))]->{number}; if($shelfnumber<0) { @@ -145,7 +149,7 @@ for(my $i=0; $i<10;$i++){ # usage : ModShelf($shelfnumber, $shelfname, $owner, $category ) # usage : (shelfnumber,shelfname,owner,category) = GetShelf($shelfnumber); -for(my $i=0; $i<10;$i++){ +for my $i(0..9){ my $rand = int(rand(9)); my $numA = $shelves[$rand]->{number}; if($numA<0) { @@ -173,23 +177,6 @@ for(my $i=0; $i<10;$i++){ } } -#-----------------------TEST DelShelf & DelFromShelf functions------------------------# -# usage : ($status) = &DelShelf($shelfnumber); - -for(my $i=0; $i<10;$i++){ - my $shelfnumber = $shelves[$i]->{number}; - if($shelfnumber<0) { - ok(1, 'Skip DelShelf for shelf -1'); - next; - } - my $status = DelShelf($shelfnumber); - ok(1 == $status, "deleted shelf $shelfnumber and its contents"); -} - -#----------------------- CLEANUP ----------------------------------------------# - -DelBiblio($_) for @biblionumbers; - #----------------------- SOME SUBS --------------------------------------------# sub randomname { @@ -199,3 +186,5 @@ sub randomname { } return $rv; } + +$dbh->rollback; -- 2.39.5