9 use Test::More tests => 9;
12 use_ok('C4::Circulation');
24 my $dbh = C4::Context->dbh;
25 $dbh->{RaiseError} = 1;
26 $dbh->{AutoCommit} = 0;
28 $dbh->do(q|DELETE FROM issues|);
29 $dbh->do(q|DELETE FROM items|);
30 $dbh->do(q|DELETE FROM borrowers|);
31 $dbh->do(q|DELETE FROM branches|);
32 $dbh->do(q|DELETE FROM categories|);
33 $dbh->do(q|DELETE FROM issuingrules|);
37 #Add branch and category
40 branchname => 'Sample Branch',
41 branchaddress1 => 'sample adr1',
42 branchaddress2 => 'sample adr2',
43 branchaddress3 => 'sample adr3',
44 branchzip => 'sample zip',
45 branchcity => 'sample city',
46 branchstate => 'sample state',
47 branchcountry => 'sample country',
48 branchphone => 'sample phone',
49 branchfax => 'sample fax',
50 branchemail => 'sample email',
51 branchurl => 'sample url',
52 branchip => 'sample ip',
53 branchprinter => undef,
54 opac_info => 'sample opac',
58 branchname => 'Sample Branch2',
59 branchaddress1 => 'sample adr1_2',
60 branchaddress2 => 'sample adr2_2',
61 branchaddress3 => 'sample adr3_2',
62 branchzip => 'sample zip2',
63 branchcity => 'sample city2',
64 branchstate => 'sample state2',
65 branchcountry => 'sample country2',
66 branchphone => 'sample phone2',
67 branchfax => 'sample fax2',
68 branchemail => 'sample email2',
69 branchurl => 'sample url2',
70 branchip => 'sample ip2',
71 branchprinter => undef,
72 opac_info => 'sample opac2',
74 Koha::Library->new($samplebranch1)->store;
75 Koha::Library->new($samplebranch2)->store;
78 categorycode => 'CAT1',
79 description => 'Description1',
80 enrolmentperiod => 'Null',
81 enrolmentperioddate => 'Null',
82 dateofbirthrequired => 'Null',
85 enrolmentfee => 'Null',
86 overduenoticerequired => 'Null',
90 category_type => 'Null'
93 "INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,dateofbirthrequired ,finetype,bulk,enrolmentfee,overduenoticerequired,issuelimit ,reservefee ,hidelostitems ,category_type) VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
96 $samplecat->{categorycode}, $samplecat->{description},
97 $samplecat->{enrolmentperiod}, $samplecat->{enrolmentperioddate},
98 $samplecat->{dateofbirthrequired}, $samplecat->{finetype},
99 $samplecat->{bulk}, $samplecat->{enrolmentfee},
100 $samplecat->{overduenoticerequired}, $samplecat->{issuelimit},
101 $samplecat->{reservefee}, $samplecat->{hidelostitems},
102 $samplecat->{category_type}
108 my $sampleissuingrule1 = {
109 reservecharge => '0.000000',
110 chargename => 'Null',
114 maxonsiteissueqty => 4,
116 lengthunit => 'Null',
118 norenewalbefore => 6,
122 chargeperiod_charge_at => 0,
123 rentaldiscount => '2.000000',
124 reservesallowed => 0,
125 hardduedate => '2013-01-01',
126 branchcode => $samplebranch1->{branchcode},
128 hardduedatecompare => 5,
129 overduefinescap => '0.000000',
130 renewalsallowed => 0,
133 categorycode => $samplecat->{categorycode},
134 maxsuspensiondays => 0,
136 opacitemholds => 'N',
137 cap_fine_to_replacement_price => 0,
139 my $sampleissuingrule2 = {
140 branchcode => $samplebranch2->{branchcode},
141 categorycode => $samplecat->{categorycode},
144 maxonsiteissueqty => 1,
145 renewalsallowed => 'Null',
147 norenewalbefore => 7,
149 reservesallowed => 'Null',
151 lengthunit => 'Null',
153 hardduedatecompare => 'Null',
156 firstremind => 'Null',
157 chargeperiod => 'Null',
158 chargeperiod_charge_at => 0,
159 rentaldiscount => 2.00,
160 overduefinescap => 'Null',
161 accountsent => 'Null',
162 reservecharge => 'Null',
163 chargename => 'Null',
164 restrictedtype => 'Null',
165 maxsuspensiondays => 0,
167 opacitemholds => 'Y',
168 cap_fine_to_replacement_price => 0,
170 my $sampleissuingrule3 = {
171 branchcode => $samplebranch1->{branchcode},
172 categorycode => $samplecat->{categorycode},
175 maxonsiteissueqty => 2,
176 renewalsallowed => 'Null',
178 norenewalbefore => 8,
180 reservesallowed => 'Null',
182 lengthunit => 'Null',
184 hardduedatecompare => 'Null',
187 firstremind => 'Null',
188 chargeperiod => 'Null',
189 chargeperiod_charge_at => 0,
190 rentaldiscount => 3.00,
191 overduefinescap => 'Null',
192 accountsent => 'Null',
193 reservecharge => 'Null',
194 chargename => 'Null',
195 restrictedtype => 'Null',
196 maxsuspensiondays => 0,
198 opacitemholds => 'F',
199 cap_fine_to_replacement_price => 0,
202 $query = 'INSERT INTO issuingrules (
221 chargeperiod_charge_at,
231 cap_fine_to_replacement_price
232 ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
233 my $sth = $dbh->prepare($query);
235 $sampleissuingrule1->{branchcode},
236 $sampleissuingrule1->{categorycode},
237 $sampleissuingrule1->{itemtype},
238 $sampleissuingrule1->{maxissueqty},
239 $sampleissuingrule1->{maxonsiteissueqty},
240 $sampleissuingrule1->{renewalsallowed},
241 $sampleissuingrule1->{renewalperiod},
242 $sampleissuingrule1->{norenewalbefore},
243 $sampleissuingrule1->{auto_renew},
244 $sampleissuingrule1->{reservesallowed},
245 $sampleissuingrule1->{issuelength},
246 $sampleissuingrule1->{lengthunit},
247 $sampleissuingrule1->{hardduedate},
248 $sampleissuingrule1->{hardduedatecompare},
249 $sampleissuingrule1->{fine},
250 $sampleissuingrule1->{finedays},
251 $sampleissuingrule1->{firstremind},
252 $sampleissuingrule1->{chargeperiod},
253 $sampleissuingrule1->{chargeperiod_charge_at},
254 $sampleissuingrule1->{rentaldiscount},
255 $sampleissuingrule1->{overduefinescap},
256 $sampleissuingrule1->{accountsent},
257 $sampleissuingrule1->{reservecharge},
258 $sampleissuingrule1->{chargename},
259 $sampleissuingrule1->{restrictedtype},
260 $sampleissuingrule1->{maxsuspensiondays},
261 $sampleissuingrule1->{onshelfholds},
262 $sampleissuingrule1->{opacitemholds},
263 $sampleissuingrule1->{cap_fine_to_replacement_price},
266 $sampleissuingrule2->{branchcode},
267 $sampleissuingrule2->{categorycode},
268 $sampleissuingrule2->{itemtype},
269 $sampleissuingrule2->{maxissueqty},
270 $sampleissuingrule2->{maxonsiteissueqty},
271 $sampleissuingrule2->{renewalsallowed},
272 $sampleissuingrule2->{renewalperiod},
273 $sampleissuingrule2->{norenewalbefore},
274 $sampleissuingrule2->{auto_renew},
275 $sampleissuingrule2->{reservesallowed},
276 $sampleissuingrule2->{issuelength},
277 $sampleissuingrule2->{lengthunit},
278 $sampleissuingrule2->{hardduedate},
279 $sampleissuingrule2->{hardduedatecompare},
280 $sampleissuingrule2->{fine},
281 $sampleissuingrule2->{finedays},
282 $sampleissuingrule2->{firstremind},
283 $sampleissuingrule2->{chargeperiod},
284 $sampleissuingrule2->{chargeperiod_charge_at},
285 $sampleissuingrule2->{rentaldiscount},
286 $sampleissuingrule2->{overduefinescap},
287 $sampleissuingrule2->{accountsent},
288 $sampleissuingrule2->{reservecharge},
289 $sampleissuingrule2->{chargename},
290 $sampleissuingrule2->{restrictedtype},
291 $sampleissuingrule2->{maxsuspensiondays},
292 $sampleissuingrule2->{onshelfholds},
293 $sampleissuingrule2->{opacitemholds},
294 $sampleissuingrule2->{cap_fine_to_replacement_price},
297 $sampleissuingrule3->{branchcode},
298 $sampleissuingrule3->{categorycode},
299 $sampleissuingrule3->{itemtype},
300 $sampleissuingrule3->{maxissueqty},
301 $sampleissuingrule3->{maxonsiteissueqty},
302 $sampleissuingrule3->{renewalsallowed},
303 $sampleissuingrule3->{renewalperiod},
304 $sampleissuingrule3->{norenewalbefore},
305 $sampleissuingrule3->{auto_renew},
306 $sampleissuingrule3->{reservesallowed},
307 $sampleissuingrule3->{issuelength},
308 $sampleissuingrule3->{lengthunit},
309 $sampleissuingrule3->{hardduedate},
310 $sampleissuingrule3->{hardduedatecompare},
311 $sampleissuingrule3->{fine},
312 $sampleissuingrule3->{finedays},
313 $sampleissuingrule3->{firstremind},
314 $sampleissuingrule3->{chargeperiod},
315 $sampleissuingrule3->{chargeperiod_charge_at},
316 $sampleissuingrule3->{rentaldiscount},
317 $sampleissuingrule3->{overduefinescap},
318 $sampleissuingrule3->{accountsent},
319 $sampleissuingrule3->{reservecharge},
320 $sampleissuingrule3->{chargename},
321 $sampleissuingrule3->{restrictedtype},
322 $sampleissuingrule3->{maxsuspensiondays},
323 $sampleissuingrule3->{onshelfholds},
324 $sampleissuingrule3->{opacitemholds},
325 $sampleissuingrule3->{cap_fine_to_replacement_price},
330 $samplecat->{categorycode},
331 'Book', $samplebranch1->{branchcode}
334 "GetIssuingCharge returns issuingrule1's informations"
339 C4::Circulation::GetLoanLength(
340 $samplecat->{categorycode},
341 'BOOK', $samplebranch1->{branchcode}
343 { issuelength => 5, lengthunit => 'Null', renewalperiod => 5 },
347 C4::Circulation::GetLoanLength(),
351 lengthunit => 'days',
353 "Without parameters, GetLoanLength returns hardcoded values"
356 C4::Circulation::GetLoanLength( -1, -1 ),
360 lengthunit => 'days',
362 "With wrong parameters, GetLoanLength returns hardcoded values"
365 C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
369 lengthunit => 'days',
371 "With only one parameter, GetLoanLength returns hardcoded values"
372 ); #NOTE : is that really what is expected?
374 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
378 lengthunit => 'days',
380 "With only one parameter, GetLoanLength returns hardcoded values"
381 ); #NOTE : is that really what is expected?
384 my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
385 'BOOK', $samplebranch1->{branchcode} );
389 dt_from_string( $sampleissuingrule1->{hardduedate}, 'iso' ),
390 $sampleissuingrule1->{hardduedatecompare}
392 "GetHardDueDate returns the duedate and the duedatecompare"