4 # This file is a test script for C4::VirtualShelves.pm
5 # Author : Antoine Farnault, antoine@koha-fr.org
13 BEGIN { plan tests
=> 30 }
15 # Getting some borrowers from database.
16 my $dbh = C4
::Context
->dbh;
22 my $sth = $dbh->prepare($query);
25 while(my $borrower = $sth->fetchrow){
26 push @borrowers, $borrower;
29 # Getting some itemnumber from database
35 my $sth = $dbh->prepare($query);
38 while(my $item = $sth->fetchrow){
42 # Getting some biblionumbers from database
48 my $sth = $dbh->prepare($query);
51 while(my $biblionumber = $sth->fetchrow){
52 push @biblionumbers, $biblionumber;
56 my $delete_virtualshelf = qq/
57 DELETE FROM virtualshelf WHERE
1
59 my $delete_virtualshelfcontent =qq/
60 DELETE FROM shelfcontents WHERE
1
63 my $sth = $dbh->prepare($delete_virtualshelf);
65 my $sth = $dbh->prepare($delete_virtualshelfcontent);
69 #----------------------------------------------------------------------#
73 #----------------------------------------------------------------------#
75 use C4
::VirtualShelves
;
76 my $version = C4
::VirtualShelves
->VERSION;
77 print "\n----------Testing C4::VirtualShelves version ".$version."--------\n";
79 ok
($version); # First test: the module is loaded & the version is readable.
82 #-----------------------TEST AddShelf function------------------------#
83 # usage : $shelfnumber = &AddShelf( $shelfname, $owner, $category);
85 # creating 10 good shelves.
87 for(my $i=0; $i<10;$i++){
88 my $ShelfNumber = AddShelf
("Shelf_".$i,$borrowers[$i],int(rand(3))+1);
89 die "test Not ok, remove some shelves before" if ($ShelfNumber == -1);
90 ok
($ShelfNumber); # Shelf creation successful;
91 push @shelves, $ShelfNumber if ok
($ShelfNumber);
94 ok
(10,scalar @shelves); # 10 shelves in @shelves;
96 # try to create some shelf which already exists.
97 for(my $i=0;$i<10;$i++){
98 my $badNumShelf = AddShelf
("Shelf_".int(rand(9)),'','');
99 ok
(-1,$badNumShelf); # AddShelf returns -1 if name already exist.
102 #-----------TEST AddToShelf & &AddToShelfFromBiblio & GetShelfContents & DelFromShelf functions--------------#
103 # usage : &AddToShelf($itemnumber, $shelfnumber);
104 # usage : $itemlist = &GetShelfContents($shelfnumber);
105 # usage : $itemlist = GetShelfContents($shelfnumber);
107 for(my $i=0; $i<10;$i++){
108 my $item = $items[int(rand(9))];
109 my $shelfnumber = $shelves[int(rand(9))];
111 my $itemlistBefore = GetShelfContents
($shelfnumber);
112 AddToShelf
($item,$shelfnumber);
113 my $itemlistAfter = GetShelfContents
($shelfnumber);
114 ok
(scalar @
$itemlistBefore,scalar (@
$itemlistAfter - 1)); # the item has been successfuly added.
117 # same thing with AddToShelfFromBiblio
118 my $biblionumber = $biblionumbers[int(rand(10))];
119 &AddToShelfFromBiblio
($biblionumber, $shelfnumber);
120 my $AfterAgain = GetShelfContents
($shelfnumber);
121 ok
(scalar @
$itemlistAfter, scalar (@
$AfterAgain -1));
124 #-----------------------TEST ModShelf & GetShelf functions------------------------#
125 # usage : ModShelf($shelfnumber, $shelfname, $owner, $category )
126 # usage : (shelfnumber,shelfname,owner,category) = GetShelf($shelfnumber);
128 for(my $i=0; $i<10;$i++){
129 my $rand = int(rand(9));
130 my $numA = $shelves[$rand];
131 my $nameA = "NewName_".$rand;
132 my $ownerA = $borrowers[$rand];
133 my $categoryA = int(rand(3))+1;
135 ModShelf
($numA,$nameA,$ownerA,$categoryA);
136 my ($numB,$nameB,$ownerB,$categoryB) = GetShelf
($numA);
141 ok
($categoryA,$categoryB);
144 #-----------------------TEST DelShelf & DelFromShelf functions------------------------#
145 # usage : ($status) = &DelShelf($shelfnumber);
146 # usage : &DelFromShelf( $itemnumber, $shelfnumber);
148 for(my $i=0; $i<10;$i++){
149 my $shelfnumber = $shelves[$i];
150 my $status = DelShelf
($shelfnumber);
152 my $items = GetShelfContents
($shelfnumber);
153 ok
($status,scalar @
$items);
154 foreach (@
$items){ # delete all the item in this shelf
155 DelFromShelf
($_{'itemnumber'},$shelfnumber);
157 ok
(DelShelf
($shelfnumber));