From b36cd9528fe9fd37746ce33ea5b9ef96a57d3d0c Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 1 Aug 2013 08:55:20 +0200 Subject: [PATCH] Bug 10389: Add unit tests for AcceptShare and IsSharedList Content-Type: text/plain; charset=utf-8 The first patch of bug 10389 adds two new routines to VirtualShelves.pm. This patch adds unit tests for them. Test plan: Run unit test t/db_dependent/VirtualShelves.t. Do all 95 tests pass? Signed-off-by: Marcel de Rooy --- t/db_dependent/VirtualShelves.t | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-) diff --git a/t/db_dependent/VirtualShelves.t b/t/db_dependent/VirtualShelves.t index c2865b2..27bfd34 100755 --- a/t/db_dependent/VirtualShelves.t +++ b/t/db_dependent/VirtualShelves.t @@ -5,7 +5,7 @@ # Larger modifications by Jonathan Druart and Marcel de Rooy use Modern::Perl; -use Test::More tests => 83; +use Test::More tests => 95; use MARC::Record; use C4::Biblio qw( AddBiblio DelBiblio ); @@ -202,6 +202,33 @@ else { is(1+$cnt2, $cnt3, "Added one new share record with invitekey"); } +#----------------------- TEST AcceptShare -------------------------------------# + +# test accepting a wrong key +my $testkey= 'keyisgone9'; +my $acctest="delete from virtualshelfshares where invitekey=?"; +$dbh->do($acctest,undef,($testkey)); #just be sure it does not exist +$acctest="select shelfnumber from virtualshelves"; +my ($accshelf)= $dbh->selectrow_array($acctest); +is(AcceptShare($accshelf,$testkey,$borrowers[0]),undef,'Did not accept invalid key'); + +# test accepting a good key +if( AddShare($accshelf,$testkey) && $borrowers[0] ) { + is(AcceptShare($accshelf, $testkey, $borrowers[0]),1,'Accepted share'); +} +else { #cannot accept if addshared failed somehow + ok(1, 'Skipped second AcceptShare test'); +} + +#----------------------- TEST IsSharedList ------------------------------------# + +for my $i (0..9) { + my $sql="select count(*) from virtualshelfshares where shelfnumber=? and borrowernumber is not null"; + my $sh=$shelves[$i]->{number}; + my ($n)=$dbh->selectrow_array($sql,undef,($sh)); + is(IsSharedList($sh),$n? 1: '', "Checked IsSharedList for shelf $sh"); +} + #----------------TEST DelShelf & DelFromShelf functions------------------------# for my $i (0..9){ -- 1.7.7.6