4 # This file is a test script for C4::VirtualShelves.pm
5 # Author : Antoine Farnault, antoine@koha-fr.org
10 #use warnings; FIXME - Bug 2505
14 BEGIN { plan tests
=> 112 }
16 # Getting some borrowers from database.
17 my $dbh = C4
::Context
->dbh;
23 my $sth = $dbh->prepare($query);
26 while(my $borrower = $sth->fetchrow){
27 push @borrowers, $borrower;
30 # Getting some itemnumber from database
36 my $sth = $dbh->prepare($query);
39 while(my $item = $sth->fetchrow){
43 # Getting some biblionumbers from database
49 my $sth = $dbh->prepare($query);
52 while(my $biblionumber = $sth->fetchrow){
53 push @biblionumbers, $biblionumber;
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);
66 my $sth = $dbh->prepare($delete_virtualshelfcontent);
70 #----------------------------------------------------------------------#
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.
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);
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);
153 my ($items,$count) = GetShelfContents
($shelfnumber);
155 foreach (@
$items){ # delete all the item in this shelf
156 DelFromShelf
($_{'itemnumber'},$shelfnumber);
158 ok
(DelShelf
($shelfnumber));