From: Marcel de Rooy <m.de.r...@rijksmuseum.nl>

Builds upon 10386 and 9032.
Adds a unit test for routine AddShare.

This patch also restores the inadvertently deleted DelShelf tests in bug 10499.

Test plan: Run the test. All passed?

Signed-off-by: Srdjan <srd...@catalyst.net.nz>
---
 t/db_dependent/VirtualShelves.t | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/VirtualShelves.t b/t/db_dependent/VirtualShelves.t
index 9f3f1b0..4a20619 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 => 71;
+use Test::More tests => 83;
 use MARC::Record;
 
 use C4::Biblio qw( AddBiblio DelBiblio );
@@ -177,6 +177,43 @@ for my $i(0..9){
     }
 }
 
+#----------------------- 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------------------------#
+
+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");
+}
+
 #----------------------- SOME SUBS 
--------------------------------------------#
 
 sub randomname {
-- 
1.8.1.2
_______________________________________________
Koha-patches mailing list
Koha-patches@lists.koha-community.org
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to