Bug 7939: Separate po files for different MARC dialects
[koha.git] / t / db_dependent / Circulation_Issuingrule.t
blobb1d9d729ad7dcc852394295c1ce1fee3e7a29d13
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use C4::Context;
5 use C4::Branch;
6 use DateTime;
7 use Koha::DateUtils;
9 use Test::More tests => 9;
11 BEGIN {
12 use_ok('C4::Circulation');
14 can_ok(
15 'C4::Circulation',
16 qw(
17 GetHardDueDate
18 GetIssuingRule
19 GetLoanLength
23 #Start transaction
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|);
35 #Add sample datas
37 #Add branch and category
38 my $samplebranch1 = {
39 add => 1,
40 branchcode => 'SAB1',
41 branchname => 'Sample Branch',
42 branchaddress1 => 'sample adr1',
43 branchaddress2 => 'sample adr2',
44 branchaddress3 => 'sample adr3',
45 branchzip => 'sample zip',
46 branchcity => 'sample city',
47 branchstate => 'sample state',
48 branchcountry => 'sample country',
49 branchphone => 'sample phone',
50 branchfax => 'sample fax',
51 branchemail => 'sample email',
52 branchurl => 'sample url',
53 branchip => 'sample ip',
54 branchprinter => undef,
55 opac_info => 'sample opac',
57 my $samplebranch2 = {
58 add => 1,
59 branchcode => 'SAB2',
60 branchname => 'Sample Branch2',
61 branchaddress1 => 'sample adr1_2',
62 branchaddress2 => 'sample adr2_2',
63 branchaddress3 => 'sample adr3_2',
64 branchzip => 'sample zip2',
65 branchcity => 'sample city2',
66 branchstate => 'sample state2',
67 branchcountry => 'sample country2',
68 branchphone => 'sample phone2',
69 branchfax => 'sample fax2',
70 branchemail => 'sample email2',
71 branchurl => 'sample url2',
72 branchip => 'sample ip2',
73 branchprinter => undef,
74 opac_info => 'sample opac2',
76 ModBranch($samplebranch1);
77 ModBranch($samplebranch2);
79 my $samplecat = {
80 categorycode => 'CAT1',
81 description => 'Description1',
82 enrolmentperiod => 'Null',
83 enrolmentperioddate => 'Null',
84 dateofbirthrequired => 'Null',
85 finetype => 'Null',
86 bulk => 'Null',
87 enrolmentfee => 'Null',
88 overduenoticerequired => 'Null',
89 issuelimit => 'Null',
90 reservefee => 'Null',
91 hidelostitems => 0,
92 category_type => 'Null'
94 my $query =
95 "INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,dateofbirthrequired ,finetype,bulk,enrolmentfee,overduenoticerequired,issuelimit ,reservefee ,hidelostitems ,category_type) VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?)";
96 $dbh->do(
97 $query, {},
98 $samplecat->{categorycode}, $samplecat->{description},
99 $samplecat->{enrolmentperiod}, $samplecat->{enrolmentperioddate},
100 $samplecat->{dateofbirthrequired}, $samplecat->{finetype},
101 $samplecat->{bulk}, $samplecat->{enrolmentfee},
102 $samplecat->{overduenoticerequired}, $samplecat->{issuelimit},
103 $samplecat->{reservefee}, $samplecat->{hidelostitems},
104 $samplecat->{category_type}
107 #Begin Tests
109 #Test GetIssuingRule
110 my $sampleissuingrule1 = {
111 reservecharge => '0.000000',
112 chargename => 'Null',
113 restrictedtype => 0,
114 accountsent => 0,
115 maxissueqty => 5,
116 finedays => 0,
117 lengthunit => 'Null',
118 renewalperiod => 5,
119 norenewalbefore => 6,
120 auto_renew => 0,
121 issuelength => 5,
122 chargeperiod => 0,
123 rentaldiscount => '2.000000',
124 reservesallowed => 0,
125 hardduedate => '2013-01-01',
126 branchcode => $samplebranch1->{branchcode},
127 fine => '0.000000',
128 hardduedatecompare => 5,
129 overduefinescap => '0.000000',
130 renewalsallowed => 0,
131 firstremind => 0,
132 itemtype => 'BOOK',
133 categorycode => $samplecat->{categorycode},
134 maxsuspensiondays => 0,
135 onshelfholds => 0,
136 opacitemholds => 'N',
138 my $sampleissuingrule2 = {
139 branchcode => $samplebranch2->{branchcode},
140 categorycode => $samplecat->{categorycode},
141 itemtype => 'BOOK',
142 maxissueqty => 2,
143 renewalsallowed => 'Null',
144 renewalperiod => 2,
145 norenewalbefore => 7,
146 auto_renew => 0,
147 reservesallowed => 'Null',
148 issuelength => 2,
149 lengthunit => 'Null',
150 hardduedate => 2,
151 hardduedatecompare => 'Null',
152 fine => 'Null',
153 finedays => 'Null',
154 firstremind => 'Null',
155 chargeperiod => 'Null',
156 rentaldiscount => 2.00,
157 overduefinescap => 'Null',
158 accountsent => 'Null',
159 reservecharge => 'Null',
160 chargename => 'Null',
161 restrictedtype => 'Null',
162 maxsuspensiondays => 0,
163 onshelfholds => 1,
164 opacitemholds => 'Y',
166 my $sampleissuingrule3 = {
167 branchcode => $samplebranch1->{branchcode},
168 categorycode => $samplecat->{categorycode},
169 itemtype => 'DVD',
170 maxissueqty => 3,
171 renewalsallowed => 'Null',
172 renewalperiod => 3,
173 norenewalbefore => 8,
174 auto_renew => 0,
175 reservesallowed => 'Null',
176 issuelength => 3,
177 lengthunit => 'Null',
178 hardduedate => 3,
179 hardduedatecompare => 'Null',
180 fine => 'Null',
181 finedays => 'Null',
182 firstremind => 'Null',
183 chargeperiod => 'Null',
184 rentaldiscount => 3.00,
185 overduefinescap => 'Null',
186 accountsent => 'Null',
187 reservecharge => 'Null',
188 chargename => 'Null',
189 restrictedtype => 'Null',
190 maxsuspensiondays => 0,
191 onshelfholds => 1,
192 opacitemholds => 'F',
194 $query = 'INSERT INTO issuingrules (
195 branchcode,
196 categorycode,
197 itemtype,
198 maxissueqty,
199 renewalsallowed,
200 renewalperiod,
201 norenewalbefore,
202 auto_renew,
203 reservesallowed,
204 issuelength,
205 lengthunit,
206 hardduedate,
207 hardduedatecompare,
208 fine,
209 finedays,
210 firstremind,
211 chargeperiod,
212 rentaldiscount,
213 overduefinescap,
214 accountsent,
215 reservecharge,
216 chargename,
217 restrictedtype,
218 maxsuspensiondays
219 ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
220 my $sth = $dbh->prepare($query);
221 $sth->execute(
222 $sampleissuingrule1->{branchcode},
223 $sampleissuingrule1->{categorycode},
224 $sampleissuingrule1->{itemtype},
225 $sampleissuingrule1->{maxissueqty},
226 $sampleissuingrule1->{renewalsallowed},
227 $sampleissuingrule1->{renewalperiod},
228 $sampleissuingrule1->{norenewalbefore},
229 $sampleissuingrule1->{auto_renew},
230 $sampleissuingrule1->{reservesallowed},
231 $sampleissuingrule1->{issuelength},
232 $sampleissuingrule1->{lengthunit},
233 $sampleissuingrule1->{hardduedate},
234 $sampleissuingrule1->{hardduedatecompare},
235 $sampleissuingrule1->{fine},
236 $sampleissuingrule1->{finedays},
237 $sampleissuingrule1->{firstremind},
238 $sampleissuingrule1->{chargeperiod},
239 $sampleissuingrule1->{rentaldiscount},
240 $sampleissuingrule1->{overduefinescap},
241 $sampleissuingrule1->{accountsent},
242 $sampleissuingrule1->{reservecharge},
243 $sampleissuingrule1->{chargename},
244 $sampleissuingrule1->{restrictedtype},
245 $sampleissuingrule1->{maxsuspensiondays},
247 $sth->execute(
248 $sampleissuingrule2->{branchcode},
249 $sampleissuingrule2->{categorycode},
250 $sampleissuingrule2->{itemtype},
251 $sampleissuingrule2->{maxissueqty},
252 $sampleissuingrule2->{renewalsallowed},
253 $sampleissuingrule2->{renewalperiod},
254 $sampleissuingrule2->{norenewalbefore},
255 $sampleissuingrule2->{auto_renew},
256 $sampleissuingrule2->{reservesallowed},
257 $sampleissuingrule2->{issuelength},
258 $sampleissuingrule2->{lengthunit},
259 $sampleissuingrule2->{hardduedate},
260 $sampleissuingrule2->{hardduedatecompare},
261 $sampleissuingrule2->{fine},
262 $sampleissuingrule2->{finedays},
263 $sampleissuingrule2->{firstremind},
264 $sampleissuingrule2->{chargeperiod},
265 $sampleissuingrule2->{rentaldiscount},
266 $sampleissuingrule2->{overduefinescap},
267 $sampleissuingrule2->{accountsent},
268 $sampleissuingrule2->{reservecharge},
269 $sampleissuingrule2->{chargename},
270 $sampleissuingrule2->{restrictedtype},
271 $sampleissuingrule2->{maxsuspensiondays},
273 $sth->execute(
274 $sampleissuingrule3->{branchcode},
275 $sampleissuingrule3->{categorycode},
276 $sampleissuingrule3->{itemtype},
277 $sampleissuingrule3->{maxissueqty},
278 $sampleissuingrule3->{renewalsallowed},
279 $sampleissuingrule3->{renewalperiod},
280 $sampleissuingrule3->{norenewalbefore},
281 $sampleissuingrule3->{auto_renew},
282 $sampleissuingrule3->{reservesallowed},
283 $sampleissuingrule3->{issuelength},
284 $sampleissuingrule3->{lengthunit},
285 $sampleissuingrule3->{hardduedate},
286 $sampleissuingrule3->{hardduedatecompare},
287 $sampleissuingrule3->{fine},
288 $sampleissuingrule3->{finedays},
289 $sampleissuingrule3->{firstremind},
290 $sampleissuingrule3->{chargeperiod},
291 $sampleissuingrule3->{rentaldiscount},
292 $sampleissuingrule3->{overduefinescap},
293 $sampleissuingrule3->{accountsent},
294 $sampleissuingrule3->{reservecharge},
295 $sampleissuingrule3->{chargename},
296 $sampleissuingrule3->{restrictedtype},
297 $sampleissuingrule3->{maxsuspensiondays},
300 is_deeply(
301 GetIssuingRule(
302 $samplecat->{categorycode},
303 'Book', $samplebranch1->{branchcode}
305 $sampleissuingrule1,
306 "GetIssuingCharge returns issuingrule1's informations"
309 #Test GetLoanLength
310 is_deeply(
311 C4::Circulation::GetLoanLength(
312 $samplecat->{categorycode},
313 'BOOK', $samplebranch1->{branchcode}
315 { issuelength => 5, lengthunit => 'Null', renewalperiod => 5 },
316 "GetLoanLength"
318 is_deeply(
319 C4::Circulation::GetLoanLength(),
321 issuelength => 21,
322 renewalperiod => 21,
323 lengthunit => 'days',
325 "Without parameters, GetLoanLength returns hardcoded values"
327 is_deeply(
328 C4::Circulation::GetLoanLength( -1, -1 ),
330 issuelength => 21,
331 renewalperiod => 21,
332 lengthunit => 'days',
334 "With wrong parameters, GetLoanLength returns hardcoded values"
336 is_deeply(
337 C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
339 issuelength => 21,
340 renewalperiod => 21,
341 lengthunit => 'days',
343 "With only one parameter, GetLoanLength returns hardcoded values"
344 ); #NOTE : is that really what is expected?
345 is_deeply(
346 C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
348 issuelength => 21,
349 renewalperiod => 21,
350 lengthunit => 'days',
352 "With only one parameter, GetLoanLength returns hardcoded values"
353 ); #NOTE : is that really what is expected?
355 #Test GetHardDueDate
356 my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
357 'BOOK', $samplebranch1->{branchcode} );
358 is_deeply(
359 \@hardduedate,
361 dt_from_string( $sampleissuingrule1->{hardduedate}, 'iso' ),
362 $sampleissuingrule1->{hardduedatecompare}
364 "GetHardDueDate returns the duedate and the duedatecompare"
367 #End transaction
368 $dbh->rollback;