Lines 1-8
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
4 |
|
19 |
|
5 |
use Test::More tests => 41; |
20 |
use Test::More tests => 52; |
6 |
use C4::Context; |
21 |
use C4::Context; |
7 |
use C4::Branch; |
22 |
use C4::Branch; |
8 |
use C4::Biblio; |
23 |
use C4::Biblio; |
Lines 48-81
$dbh->do(q|DELETE FROM branchcategories|);
Link Here
|
48 |
my $collections = GetCollections(); |
63 |
my $collections = GetCollections(); |
49 |
my $countcollection = scalar(@$collections); |
64 |
my $countcollection = scalar(@$collections); |
50 |
|
65 |
|
51 |
is( CreateCollection( 'Collection1', 'Description1' ), |
66 |
my ($success,$errorCode,$errorMessage); |
52 |
1, "All parameters have been given - Collection 1 added" ); |
67 |
|
|
|
68 |
($success,$errorCode,$errorMessage) = CreateCollection( 'Collection1', 'Description1' ); |
69 |
is( $success, 1, "All parameters have been given - Collection 1 added" ); |
70 |
ok( !defined $errorCode && !defined $errorMessage, |
71 |
"Collection added, no error code or message"); |
53 |
my $collection_id1 = $dbh->last_insert_id( undef, undef, 'collections', undef ); |
72 |
my $collection_id1 = $dbh->last_insert_id( undef, undef, 'collections', undef ); |
54 |
is( CreateCollection( 'Collection2', 'Description2' ), |
73 |
|
55 |
1, "All parameters have been given - Collection 2 added" ); |
74 |
($success,$errorCode,$errorMessage) = CreateCollection( 'Collection2', 'Description2' ); |
|
|
75 |
is( $success, 1, "All parameters have been given - Collection 2 added" ); |
76 |
ok( !defined $errorCode && !defined $errorMessage, |
77 |
"Collection added, no error code or message"); |
56 |
my $collection_id2 = $dbh->last_insert_id( undef, undef, 'collections', undef ); |
78 |
my $collection_id2 = $dbh->last_insert_id( undef, undef, 'collections', undef ); |
|
|
79 |
|
57 |
$collections = GetCollections(); |
80 |
$collections = GetCollections(); |
58 |
is( |
81 |
is( scalar(@$collections), $countcollection + 2, |
59 |
scalar(@$collections), |
82 |
"Collection1 and Collection2 have been added" ); |
60 |
$countcollection + 2, |
83 |
|
61 |
"Collection1 and Collection2 have been added" |
84 |
($success,$errorCode,$errorMessage) = CreateCollection('Collection3'); |
62 |
); |
85 |
is( $success, 1, "Collections can be created without description" ); |
63 |
my $collection = CreateCollection('Collection'); |
86 |
ok( !defined $errorCode && !defined $errorMessage, |
64 |
is( $collection, 'No Description Given', "The field description is missing" ); |
87 |
"Collection added, no error code or message"); |
65 |
$collection = CreateCollection(); |
88 |
my $collection_id3 = $dbh->last_insert_id( undef, undef, 'collections', undef ); |
66 |
is( |
89 |
|
67 |
$collection, |
90 |
($success,$errorCode,$errorMessage) = CreateCollection(); |
68 |
'No Title Given', |
91 |
is( $success, 0, "Title missing, fails to create collection" ); |
69 |
"The field description and title is missing" |
92 |
is( $errorCode, 1, "Title missing, error code is 1" ); |
70 |
); |
93 |
is( $errorMessage, 'NO_TITLE', "Title missing, error message is NO_TITLE" ); |
|
|
94 |
|
71 |
$collections = GetCollections(); |
95 |
$collections = GetCollections(); |
72 |
is( scalar(@$collections), $countcollection + 2, "No collection added" ); |
96 |
is( scalar(@$collections), $countcollection + 3, "Only one collection added" ); |
73 |
|
97 |
|
74 |
#FIXME, as the id is auto incremented, two similar Collections (same title /same description) can be created |
98 |
#FIXME, as the id is auto incremented, two similar Collections (same title /same description) can be created |
75 |
#$collection1 = CreateCollection('Collection1','Description1'); |
99 |
#$collection1 = CreateCollection('Collection1','Description1'); |
76 |
|
100 |
|
77 |
#Test GetCollections |
101 |
#Test GetCollections |
78 |
$collection = GetCollections(); |
102 |
my $collection = GetCollections(); |
79 |
is_deeply( |
103 |
is_deeply( |
80 |
$collections, |
104 |
$collections, |
81 |
[ |
105 |
[ |
Lines 90-126
is_deeply(
Link Here
|
90 |
colTitle => 'Collection2', |
114 |
colTitle => 'Collection2', |
91 |
colDesc => 'Description2', |
115 |
colDesc => 'Description2', |
92 |
colBranchcode => undef |
116 |
colBranchcode => undef |
|
|
117 |
}, |
118 |
{ |
119 |
colId => $collection_id3, |
120 |
colTitle => 'Collection3', |
121 |
colDesc => '', |
122 |
colBranchcode => undef |
93 |
} |
123 |
} |
|
|
124 |
|
94 |
], |
125 |
], |
95 |
'All Collections' |
126 |
'All Collections' |
96 |
); |
127 |
); |
97 |
|
128 |
|
98 |
#Test UpdateCollection |
129 |
#Test UpdateCollection |
99 |
is( |
130 |
($success,$errorCode,$errorMessage) = |
100 |
UpdateCollection( |
131 |
UpdateCollection( $collection_id2, 'Collection2bis', undef ); |
101 |
$collection_id2, |
132 |
is( $success, 1, "UpdateCollection succeeds without description"); |
102 |
'Collection2 modified', |
|
|
103 |
'Description2 modified' |
104 |
), |
105 |
1, |
106 |
"Collection2 has been modified" |
107 |
); |
108 |
|
133 |
|
109 |
#FIXME : The following test should pass, currently, with a wrong id UpdateCollection returns 1 even if nothing has been modified |
134 |
($success,$errorCode,$errorMessage) = |
110 |
#is(UpdateCollection(-1,'Collection2 modified','Description2 modified'), |
135 |
UpdateCollection( $collection_id2, 'Collection2 modified', 'Description2 modified' ); |
111 |
# 0, |
136 |
is( $success, 1, "Collection2 has been modified" ); |
112 |
# "UpdateCollection with a wrong id"); |
137 |
ok( !defined $errorCode && !defined $errorMessage, |
113 |
is( |
138 |
"Collection2 modified, no error code or message"); |
114 |
UpdateCollection( 'Collection', 'Description' ), |
139 |
|
115 |
'No Description Given', |
140 |
($success,$errorCode,$errorMessage) = |
116 |
"UpdateCollection without description" |
141 |
UpdateCollection( $collection_id2, undef, 'Description' ), |
117 |
); |
142 |
ok( !$success, "UpdateCollection fails without title" ); |
118 |
is( |
143 |
is( $errorCode, 2, "Title missing, error code is 2"); |
119 |
UpdateCollection( 'Description' ), |
144 |
is( $errorMessage, 'NO_TITLE', "Title missing, error message is NO_TITLE"); |
120 |
'No Title Given', |
145 |
|
121 |
"UpdateCollection without title" |
146 |
is( UpdateCollection(), 'NO_ID', "UpdateCollection without params" ); |
122 |
); |
|
|
123 |
is( UpdateCollection(), 'No Id Given', "UpdateCollection without params" ); |
124 |
|
147 |
|
125 |
#Test GetCollection |
148 |
#Test GetCollection |
126 |
my @collection1 = GetCollection($collection_id1); |
149 |
my @collection1 = GetCollection($collection_id1); |
Lines 181-190
is_deeply(
Link Here
|
181 |
], |
204 |
], |
182 |
"Collection1 belongs to the sample branch (SAB)" |
205 |
"Collection1 belongs to the sample branch (SAB)" |
183 |
); |
206 |
); |
184 |
is( TransferCollection, "No Id Given", "TransferCollection without ID" ); |
207 |
is( TransferCollection, "NO_ID", "TransferCollection without ID" ); |
185 |
is( |
208 |
is( |
186 |
TransferCollection($collection_id1), |
209 |
TransferCollection($collection_id1), |
187 |
"No Branchcode Given", |
210 |
'NO_BRANCHCODE', |
188 |
"TransferCollection without branchcode" |
211 |
"TransferCollection without branchcode" |
189 |
); |
212 |
); |
190 |
|
213 |
|
Lines 224-230
is( AddItemToCollection( $collection_id1, $item_id2 ),
Link Here
|
224 |
1, "Sampleitem2 has been added to Collection1" ); |
247 |
1, "Sampleitem2 has been added to Collection1" ); |
225 |
|
248 |
|
226 |
#Test GetItemsInCollection |
249 |
#Test GetItemsInCollection |
227 |
my $itemsincollection1 = GetItemsInCollection($collection_id1); |
250 |
my $itemsincollection1; |
|
|
251 |
($itemsincollection1,$success,$errorCode,$errorMessage) = GetItemsInCollection($collection_id1); |
228 |
is( scalar @$itemsincollection1, 2, "Collection1 has 2 items" ); |
252 |
is( scalar @$itemsincollection1, 2, "Collection1 has 2 items" ); |
229 |
is_deeply( |
253 |
is_deeply( |
230 |
$itemsincollection1, |
254 |
$itemsincollection1, |
Lines 232-247
is_deeply(
Link Here
|
232 |
{ |
256 |
{ |
233 |
title => undef, |
257 |
title => undef, |
234 |
itemcallnumber => 'callnumber1', |
258 |
itemcallnumber => 'callnumber1', |
|
|
259 |
biblionumber => $biblionumber, |
235 |
barcode => 1 |
260 |
barcode => 1 |
236 |
}, |
261 |
}, |
237 |
{ |
262 |
{ |
238 |
title => undef, |
263 |
title => undef, |
239 |
itemcallnumber => 'callnumber2', |
264 |
itemcallnumber => 'callnumber2', |
|
|
265 |
biblionumber => $biblionumber, |
240 |
barcode => 2 |
266 |
barcode => 2 |
241 |
} |
267 |
} |
242 |
], |
268 |
], |
243 |
"Collection1 has Item1 and Item2" |
269 |
"Collection1 has Item1 and Item2" |
244 |
); |
270 |
); |
|
|
271 |
($itemsincollection1,$success,$errorCode,$errorMessage) = GetItemsInCollection(); |
272 |
ok( !$success, "GetItemsInCollection fails without a collection ID" ); |
273 |
is( $errorCode, 1, "Title missing, error code is 2"); |
274 |
is( $errorMessage, 'NO_ID', "Collection ID missing, error message is NO_ID"); |
245 |
|
275 |
|
246 |
#Test RemoveItemFromCollection |
276 |
#Test RemoveItemFromCollection |
247 |
is( RemoveItemFromCollection( $collection_id1, $item_id2 ), |
277 |
is( RemoveItemFromCollection( $collection_id1, $item_id2 ), |
Lines 293-307
is( DeleteCollection($collection_id2), 1, "Collection2 deleted" );
Link Here
|
293 |
is( DeleteCollection($collection_id1), 1, "Collection1 deleted" ); |
323 |
is( DeleteCollection($collection_id1), 1, "Collection1 deleted" ); |
294 |
is( |
324 |
is( |
295 |
DeleteCollection(), |
325 |
DeleteCollection(), |
296 |
'No Collection Id Given', |
326 |
'NO_ID', |
297 |
"DeleteCollection without id" |
327 |
"DeleteCollection without id" |
298 |
); |
328 |
); |
299 |
$collections = GetCollections(); |
329 |
$collections = GetCollections(); |
300 |
is( |
330 |
is( |
301 |
scalar(@$collections), |
331 |
scalar(@$collections), |
302 |
$countcollection + 0, |
332 |
$countcollection + 1, |
303 |
"Two Collections have been deleted" |
333 |
"Two Collections have been deleted" |
304 |
); |
334 |
); |
305 |
|
335 |
|
306 |
#End transaction |
336 |
#End transaction |
307 |
$dbh->rollback; |
337 |
$dbh->rollback; |
308 |
- |
338 |
|
|
|
339 |
1; |