From 674d29a6586e70b443323846b0fdfb4e8209c67c Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 10 Jun 2013 14:51:55 +0200 Subject: [PATCH] Bug 10441: Testing AddShare in VirtualShelves.t Content-Type: text/plain; charset=utf-8 Builds upon 10386 and 9032. Adds a unit test for routine AddShare. Test plan: Run the test. All passed? --- t/db_dependent/VirtualShelves.t | 27 ++++++++++++++++++++++++++- 1 files changed, 26 insertions(+), 1 deletions(-) diff --git a/t/db_dependent/VirtualShelves.t b/t/db_dependent/VirtualShelves.t index 563eeca..5675b90 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 => 81; +use Test::More tests => 83; use MARC::Record; use C4::Biblio qw( AddBiblio DelBiblio ); @@ -173,6 +173,31 @@ for(my $i=0; $i<10;$i++){ } } +#----------------------- TEST AddShare ----------------------------------------# + +#first count the number of shares in the table; keep in mind that AddShare may +#delete some expired records while housekeeping +my $sql_sharecount="select count(*) from virtualshelfshares where DATEDIFF(sharedate, NOW())>0"; +my $cnt1=$dbh->selectrow_array($sql_sharecount); + +#try to add a share without shelfnumber: should fail +AddShare(0, 'abcdefghij'); +my $cnt2=$dbh->selectrow_array($sql_sharecount); +ok($cnt1 == $cnt2, "Did not add an invalid share record"); + +#add another share: should be okay +#AddShare assumes that you tested if category==private (so we could actually +#be doing something illegal here :) +my $n=$shelves[0]->{number}; +if($n<0) { + ok(1, 'Skip AddShare for shelf -1'); +} +else { + AddShare($n, 'abcdefghij'); + my $cnt3=$dbh->selectrow_array($sql_sharecount); + ok(1+$cnt2 == $cnt3, "Added one new share record with invitekey"); +} + #-----------------------TEST DelShelf & DelFromShelf functions------------------------# # usage : ($status) = &DelShelf($shelfnumber); -- 1.7.7.6