View | Details | Raw Unified | Return to bug 10767
Collapse All | Expand All

(-)a/t/db_dependent/Circulation_Issuingrule.t (-1 / +357 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use C4::Context;
5
use C4::Branch;
6
use DateTime;
7
use Koha::DateUtils;
8
9
use Test::More tests => 9;
10
11
BEGIN {
12
    use_ok('C4::Circulation');
13
}
14
can_ok(
15
    'C4::Circulation',
16
    qw(
17
      GetHardDueDate
18
      GetIssuingRule
19
      GetLoanLength
20
      )
21
);
22
23
#Start transaction
24
my $dbh = C4::Context->dbh;
25
$dbh->{RaiseError} = 1;
26
$dbh->{AutoCommit} = 0;
27
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|);
34
35
#Add sample datas
36
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',
56
};
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',
75
};
76
ModBranch($samplebranch1);
77
ModBranch($samplebranch2);
78
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'
93
};
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}
105
);
106
107
#Begin Tests
108
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
    issuelength        => 5,
120
    chargeperiod       => 0,
121
    rentaldiscount     => '2.000000',
122
    reservesallowed    => 0,
123
    hardduedate        => '2013-01-01',
124
    branchcode         => $samplebranch1->{branchcode},
125
    fine               => '0.000000',
126
    hardduedatecompare => 5,
127
    overduefinescap    => '0.000000',
128
    renewalsallowed    => 0,
129
    firstremind        => 0,
130
    itemtype           => 'BOOK',
131
    categorycode       => $samplecat->{categorycode}
132
};
133
my $sampleissuingrule2 = {
134
    branchcode         => $samplebranch2->{branchcode},
135
    categorycode       => $samplecat->{categorycode},
136
    itemtype           => 'BOOK',
137
    maxissueqty        => 2,
138
    renewalsallowed    => 'Null',
139
    renewalperiod      => 2,
140
    reservesallowed    => 'Null',
141
    issuelength        => 2,
142
    lengthunit         => 'Null',
143
    hardduedate        => 2,
144
    hardduedatecompare => 'Null',
145
    fine               => 'Null',
146
    finedays           => 'Null',
147
    firstremind        => 'Null',
148
    chargeperiod       => 'Null',
149
    rentaldiscount     => 2.00,
150
    overduefinescap    => 'Null',
151
    accountsent        => 'Null',
152
    reservecharge      => 'Null',
153
    chargename         => 'Null',
154
    restrictedtype     => 'Null'
155
};
156
my $sampleissuingrule3 = {
157
    branchcode         => $samplebranch1->{branchcode},
158
    categorycode       => $samplecat->{categorycode},
159
    itemtype           => 'DVD',
160
    maxissueqty        => 3,
161
    renewalsallowed    => 'Null',
162
    renewalperiod      => 3,
163
    reservesallowed    => 'Null',
164
    issuelength        => 3,
165
    lengthunit         => 'Null',
166
    hardduedate        => 3,
167
    hardduedatecompare => 'Null',
168
    fine               => 'Null',
169
    finedays           => 'Null',
170
    firstremind        => 'Null',
171
    chargeperiod       => 'Null',
172
    rentaldiscount     => 3.00,
173
    overduefinescap    => 'Null',
174
    accountsent        => 'Null',
175
    reservecharge      => 'Null',
176
    chargename         => 'Null',
177
    restrictedtype     => 'Null'
178
};
179
$query = 'INSERT INTO issuingrules (
180
                branchcode,
181
                categorycode,
182
                itemtype,
183
                maxissueqty,
184
                renewalsallowed,
185
                renewalperiod,
186
                reservesallowed,
187
                issuelength,
188
                lengthunit,
189
                hardduedate,
190
                hardduedatecompare,
191
                fine,
192
                finedays,
193
                firstremind,
194
                chargeperiod,
195
                rentaldiscount,
196
                overduefinescap,
197
                accountsent,
198
                reservecharge,
199
                chargename,
200
                restrictedtype
201
                ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
202
my $sth = $dbh->prepare($query);
203
$sth->execute(
204
    $sampleissuingrule1->{branchcode},
205
    $sampleissuingrule1->{categorycode},
206
    $sampleissuingrule1->{itemtype},
207
    $sampleissuingrule1->{maxissueqty},
208
    $sampleissuingrule1->{renewalsallowed},
209
    $sampleissuingrule1->{renewalperiod},
210
    $sampleissuingrule1->{reservesallowed},
211
    $sampleissuingrule1->{issuelength},
212
    $sampleissuingrule1->{lengthunit},
213
    $sampleissuingrule1->{hardduedate},
214
    $sampleissuingrule1->{hardduedatecompare},
215
    $sampleissuingrule1->{fine},
216
    $sampleissuingrule1->{finedays},
217
    $sampleissuingrule1->{firstremind},
218
    $sampleissuingrule1->{chargeperiod},
219
    $sampleissuingrule1->{rentaldiscount},
220
    $sampleissuingrule1->{overduefinescap},
221
    $sampleissuingrule1->{accountsent},
222
    $sampleissuingrule1->{reservecharge},
223
    $sampleissuingrule1->{chargename},
224
    $sampleissuingrule1->{restrictedtype}
225
);
226
$sth->execute(
227
    $sampleissuingrule2->{branchcode},
228
    $sampleissuingrule2->{categorycode},
229
    $sampleissuingrule2->{itemtype},
230
    $sampleissuingrule2->{maxissueqty},
231
    $sampleissuingrule2->{renewalsallowed},
232
    $sampleissuingrule2->{renewalperiod},
233
    $sampleissuingrule2->{reservesallowed},
234
    $sampleissuingrule2->{issuelength},
235
    $sampleissuingrule2->{lengthunit},
236
    $sampleissuingrule2->{hardduedate},
237
    $sampleissuingrule2->{hardduedatecompare},
238
    $sampleissuingrule2->{fine},
239
    $sampleissuingrule2->{finedays},
240
    $sampleissuingrule2->{firstremind},
241
    $sampleissuingrule2->{chargeperiod},
242
    $sampleissuingrule2->{rentaldiscount},
243
    $sampleissuingrule2->{overduefinescap},
244
    $sampleissuingrule2->{accountsent},
245
    $sampleissuingrule2->{reservecharge},
246
    $sampleissuingrule2->{chargename},
247
    $sampleissuingrule2->{restrictedtype}
248
);
249
$sth->execute(
250
    $sampleissuingrule3->{branchcode},
251
    $sampleissuingrule3->{categorycode},
252
    $sampleissuingrule3->{itemtype},
253
    $sampleissuingrule3->{maxissueqty},
254
    $sampleissuingrule3->{renewalsallowed},
255
    $sampleissuingrule3->{renewalperiod},
256
    $sampleissuingrule3->{reservesallowed},
257
    $sampleissuingrule3->{issuelength},
258
    $sampleissuingrule3->{lengthunit},
259
    $sampleissuingrule3->{hardduedate},
260
    $sampleissuingrule3->{hardduedatecompare},
261
    $sampleissuingrule3->{fine},
262
    $sampleissuingrule3->{finedays},
263
    $sampleissuingrule3->{firstremind},
264
    $sampleissuingrule3->{chargeperiod},
265
    $sampleissuingrule3->{rentaldiscount},
266
    $sampleissuingrule3->{overduefinescap},
267
    $sampleissuingrule3->{accountsent},
268
    $sampleissuingrule3->{reservecharge},
269
    $sampleissuingrule3->{chargename},
270
    $sampleissuingrule3->{restrictedtype}
271
);
272
273
is_deeply(
274
    GetIssuingRule(
275
        $samplecat->{categorycode},
276
        'Book', $samplebranch1->{branchcode}
277
    ),
278
    $sampleissuingrule1,
279
    "GetIssuingCharge returns issuingrule1's informations"
280
);
281
282
#FIX ME: Currently, GetIssuingRule without parameters returns an issuingrule with branchcode -> *,categorycode -> *, itemtype -> *
283
#is_deeply ( GetIssuingRule(),{$sampleissuingrule1,$sampleissuingrule2,$sampleissuingrule3},"Without parameters, GetIssuingRule returns all the issuingrule");
284
285
#FIX ME: Currently, GetIssuingRule with only one parameter returns an issuingrule with branchcode -> *,categorycode -> *, itemtype -> *
286
#is_deeply(GetIssuingRule($samplecat->{categorycode}),{$sampleissuingrule1,$sampleissuingrule2,$sampleissuingrule3},"GetIssuingRule with a categorycode returns all the issuingrules of this category");
287
288
#FIX ME: Currently, GetIssuingRule with only two parameters returns an issuingrule with branchcode -> *,categorycode -> *, itemtype -> *
289
#is_deeply(GetIssuingRule($samplecat->{categorycode},'BOOK'),{$sampleissuingrule1,$sampleissuingrule2},"GetIssuingRule with a categorycode and'Book' returns all the issuingrules of this category and the itemtype = book");
290
291
#Test GetLoanLength
292
is_deeply(
293
    C4::Circulation::GetLoanLength(
294
        $samplecat->{categorycode},
295
        'BOOK', $samplebranch1->{branchcode}
296
    ),
297
    { issuelength => 5, lengthunit => 'Null', renewalperiod => 5 },
298
    "GetLoanLength"
299
);
300
is_deeply(
301
    C4::Circulation::GetLoanLength(),
302
    {
303
        issuelength   => 21,
304
        renewalperiod => 21,
305
        lengthunit    => 'days',
306
    },
307
    "Without parameters, GetLoanLength returns hardcoded values"
308
);
309
is_deeply(
310
    C4::Circulation::GetLoanLength( -1, -1 ),
311
    {
312
        issuelength   => 21,
313
        renewalperiod => 21,
314
        lengthunit    => 'days',
315
    },
316
    "With wrong parameters, GetLoanLength returns hardcoded values"
317
);
318
is_deeply(
319
    C4::Circulation::GetLoanLength( $samplecat->{categorycode} ),
320
    {
321
        issuelength   => 21,
322
        renewalperiod => 21,
323
        lengthunit    => 'days',
324
    },
325
    "With only one parameter, GetLoanLength returns hardcoded values"
326
);    #NOTE : is that really what is expected?
327
is_deeply(
328
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
329
    {
330
        issuelength   => 21,
331
        renewalperiod => 21,
332
        lengthunit    => 'days',
333
    },
334
    "With only one parameter, GetLoanLength returns hardcoded values"
335
);    #NOTE : is that really what is expected?
336
337
#Test GetHardDueDate
338
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
339
    'BOOK', $samplebranch1->{branchcode} );
340
is_deeply(
341
    \@hardduedate,
342
    [
343
        dt_from_string( $sampleissuingrule1->{hardduedate}, 'iso' ),
344
        $sampleissuingrule1->{hardduedatecompare}
345
    ],
346
    "GetHardDueDate returns the duedate and the duedatecompare"
347
);
348
349
#FIXME: Currently, with wrong parameters GetHardDueDate returns '' because GetIssuingrule returns wrong value
350
#@hardduedate = C4::Circulation::GetHardDueDate(-1,-1,-1);
351
#is_deeply(\@hardduedate,[undef,undef],"GetHardDueDate with wrong parameters returns undef");
352
#FIXME: Currently, without parameter GetHardDueDate returns '' because GetIssuingrule returns wrong value
353
#@hardduedate = C4::Circulation::GetHardDueDate();
354
#is_deeply(\@hardduedate,[undef,undef],"GetHardDueDate without parameter returns undef");
355
356
#End transaction
357
$dbh->rollback;

Return to bug 10767