Bug 2505 - Add commented use warnings where missing in *.t
[koha.git] / t / db_dependent / VirtualShelves.t
blobf4110faa8ea6217b5a6843f8add49033d95adf09
1 #!/usr/bin/perl
4 # This file is a test script for C4::VirtualShelves.pm
5 # Author : Antoine Farnault, antoine@koha-fr.org
8 use Test;
9 use strict;
10 #use warnings; FIXME - Bug 2505
11 use C4::Context;
13 # Making 30 tests.
14 BEGIN { plan tests => 112 }
16 # Getting some borrowers from database.
17 my $dbh = C4::Context->dbh;
18 my $query = qq/
19 SELECT borrowernumber
20 FROM borrowers
21 LIMIT 10
23 my $sth = $dbh->prepare($query);
24 $sth->execute;
25 my @borrowers;
26 while(my $borrower = $sth->fetchrow){
27 push @borrowers, $borrower;
30 # Getting some itemnumber from database
31 my $query = qq/
32 SELECT itemnumber
33 FROM items
34 LIMIT 10
36 my $sth = $dbh->prepare($query);
37 $sth->execute;
38 my @items;
39 while(my $item = $sth->fetchrow){
40 push @items, $item;
43 # Getting some biblionumbers from database
44 my $query = qq/
45 SELECT biblionumber
46 FROM biblio
47 LIMIT 10
49 my $sth = $dbh->prepare($query);
50 $sth->execute;
51 my @biblionumbers;
52 while(my $biblionumber = $sth->fetchrow){
53 push @biblionumbers, $biblionumber;
56 # ---
57 my $delete_virtualshelf = qq/
58 DELETE FROM virtualshelves WHERE 1
60 my $delete_virtualshelfcontent =qq/
61 DELETE FROM virtualshelfcontents WHERE 1
64 my $sth = $dbh->prepare($delete_virtualshelf);
65 $sth->execute;
66 my $sth = $dbh->prepare($delete_virtualshelfcontent);
67 $sth->execute;
68 # ---
70 #----------------------------------------------------------------------#
72 # TESTS START HERE
74 #----------------------------------------------------------------------#
76 use C4::VirtualShelves;
77 my $version = C4::VirtualShelves->VERSION;
78 print "\n----------Testing C4::VirtualShelves version ".$version."--------\n";
80 ok($version); # First test: the module is loaded & the version is readable.
83 #-----------------------TEST AddShelf function------------------------#
84 # usage : $shelfnumber = &AddShelf( $shelfname, $owner, $category);
86 # creating 10 good shelves.
87 my @shelves;
88 for(my $i=0; $i<10;$i++){
89 my $ShelfNumber = AddShelf("Shelf_".$i,$borrowers[$i] || '',int(rand(3))+1);
90 die "test Not ok, remove some shelves before" if ($ShelfNumber == -1);
91 ok($ShelfNumber); # Shelf creation successful;
92 push @shelves, $ShelfNumber if ok($ShelfNumber);
95 ok(10,scalar @shelves); # 10 shelves in @shelves;
97 # try to create some shelf which already exists.
98 for(my $i=0;$i<10;$i++){
99 my $badNumShelf = AddShelf("Shelf_".$i,$borrowers[$i] || '','');
100 ok(-1,$badNumShelf); # AddShelf returns -1 if name already exist.
103 #-----------TEST AddToShelf & &AddToShelfFromBiblio & GetShelfContents & DelFromShelf functions--------------#
104 # usage : &AddToShelf($itemnumber, $shelfnumber);
105 # usage : $itemlist = &GetShelfContents($shelfnumber);
106 # usage : $itemlist = GetShelfContents($shelfnumber);
108 for(my $i=0; $i<10;$i++){
109 my $item = $items[int(rand(9))];
110 my $shelfnumber = $shelves[int(rand(9))];
112 my ($itemlistBefore,$countbefore) = GetShelfContents($shelfnumber);
113 AddToShelf($item,$shelfnumber);
114 my ($itemlistAfter,$countafter) = GetShelfContents($shelfnumber);
115 ok($countbefore,$countafter - 1); # the item has been successfuly added.
118 # same thing with AddToShelfFromBiblio
119 my $biblionumber = $biblionumbers[int(rand(10))];
120 &AddToShelfFromBiblio($biblionumber, $shelfnumber);
121 my ($AfterAgain,$countagain) = GetShelfContents($shelfnumber);
122 ok($countafter, $countagain -1);
125 #-----------------------TEST ModShelf & GetShelf functions------------------------#
126 # usage : ModShelf($shelfnumber, $shelfname, $owner, $category )
127 # usage : (shelfnumber,shelfname,owner,category) = GetShelf($shelfnumber);
129 for(my $i=0; $i<10;$i++){
130 my $rand = int(rand(9));
131 my $numA = $shelves[$rand];
132 my $shelf = { shelfname => "NewName_".$rand,
133 owner => $borrowers[$rand],
134 category => int(rand(3))+1 };
136 ModShelf($numA,$shelf);
137 my ($numB,$nameB,$ownerB,$categoryB) = GetShelf($numA);
139 ok($numA,$numB);
140 ok($shelf->{shelfname},$nameB);
141 ok($shelf->{owner},$ownerB);
142 ok($shelf->{category},$categoryB);
145 #-----------------------TEST DelShelf & DelFromShelf functions------------------------#
146 # usage : ($status) = &DelShelf($shelfnumber);
147 # usage : &DelFromShelf( $itemnumber, $shelfnumber);
149 for(my $i=0; $i<10;$i++){
150 my $shelfnumber = $shelves[$i];
151 my $status = DelShelf($shelfnumber);
152 if($status){
153 my ($items,$count) = GetShelfContents($shelfnumber);
154 ok($status,$count);
155 foreach (@$items){ # delete all the item in this shelf
156 DelFromShelf($_{'itemnumber'},$shelfnumber);
158 ok(DelShelf($shelfnumber));