Lines 1-16
Link Here
|
1 |
#!/usr/bin/perl; |
1 |
#!/usr/bin/perl; |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More tests => 16; |
4 |
use Test::More tests => 17; |
5 |
|
5 |
|
6 |
use C4::Context; |
6 |
use C4::Context; |
7 |
use Koha::Database; |
7 |
use Koha::Database; |
8 |
use Koha::Libraries; |
8 |
use Koha::Libraries; |
|
|
9 |
|
10 |
use t::lib::Mocks; |
11 |
use t::lib::TestBuilder; |
12 |
|
9 |
use_ok('C4::Overdues'); |
13 |
use_ok('C4::Overdues'); |
10 |
can_ok('C4::Overdues', 'GetOverdueMessageTransportTypes'); |
14 |
can_ok('C4::Overdues', 'GetOverdueMessageTransportTypes'); |
11 |
can_ok('C4::Overdues', 'GetBranchcodesWithOverdueRules'); |
15 |
can_ok('C4::Overdues', 'GetBranchcodesWithOverdueRules'); |
12 |
|
16 |
|
13 |
my $schema = Koha::Database->new->schema; |
17 |
my $schema = Koha::Database->new->schema; |
|
|
18 |
my $builder = t::lib::TestBuilder->new; |
19 |
|
14 |
$schema->storage->txn_begin; |
20 |
$schema->storage->txn_begin; |
15 |
my $dbh = C4::Context->dbh; |
21 |
my $dbh = C4::Context->dbh; |
16 |
|
22 |
|
Lines 121-123
$dbh->do(q|
Link Here
|
121 |
|
127 |
|
122 |
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(); |
128 |
@overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules(); |
123 |
is_deeply( \@overdue_branches, ['CPL', 'MPL'] , 'If only 2 specific rules exist, 2 branches should be returned' ); |
129 |
is_deeply( \@overdue_branches, ['CPL', 'MPL'] , 'If only 2 specific rules exist, 2 branches should be returned' ); |
124 |
- |
130 |
|
|
|
131 |
$schema->storage->txn_rollback; |
132 |
|
133 |
subtest 'UpdateFine tests' => sub { |
134 |
|
135 |
plan tests => 25; |
136 |
|
137 |
$schema->storage->txn_begin; |
138 |
|
139 |
t::lib::Mocks::mock_preference( 'MaxFine', '100' ); |
140 |
|
141 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
142 |
my $item1 = $builder->build_sample_item(); |
143 |
my $item2 = $builder->build_sample_item(); |
144 |
my $checkout1 = $builder->build_object( |
145 |
{ |
146 |
class => 'Koha::Checkouts', |
147 |
value => { itemnumber => $item1->itemnumber } |
148 |
} |
149 |
); |
150 |
my $checkout2 = $builder->build_object( |
151 |
{ |
152 |
class => 'Koha::Checkouts', |
153 |
value => { itemnumber => $item2->itemnumber } |
154 |
} |
155 |
); |
156 |
|
157 |
# Try to add 0 amount fine |
158 |
UpdateFine( |
159 |
{ |
160 |
issue_id => $checkout1->issue_id, |
161 |
itemnumber => $item1->itemnumber, |
162 |
borrowernumber => $patron->borrowernumber, |
163 |
amount => '0', |
164 |
due => $checkout1->date_due |
165 |
} |
166 |
); |
167 |
|
168 |
my $fines = Koha::Account::Lines->search( |
169 |
{ borrowernumber => $patron->borrowernumber } ); |
170 |
is( $fines->count, 0, "No fine added when amount is 0" ); |
171 |
|
172 |
# Add fine 1 |
173 |
UpdateFine( |
174 |
{ |
175 |
issue_id => $checkout1->issue_id, |
176 |
itemnumber => $item1->itemnumber, |
177 |
borrowernumber => $patron->borrowernumber, |
178 |
amount => '50', |
179 |
due => $checkout1->date_due |
180 |
} |
181 |
); |
182 |
|
183 |
$fines = Koha::Account::Lines->search( |
184 |
{ borrowernumber => $patron->borrowernumber } ); |
185 |
is( $fines->count, 1, "Fine added when amount is greater than 0" ); |
186 |
my $fine = $fines->next; |
187 |
is( $fine->amount, '50.000000', "Fine amount correctly set to 50" ); |
188 |
is( $fine->issue_id, $checkout1->issue_id, "Fine is associated with the correct issue" ); |
189 |
is( $fine->itemnumber, $checkout1->itemnumber, "Fine is associated with the correct item" ); |
190 |
|
191 |
# Increase fine 1 |
192 |
UpdateFine( |
193 |
{ |
194 |
issue_id => $checkout1->issue_id, |
195 |
itemnumber => $item1->itemnumber, |
196 |
borrowernumber => $patron->borrowernumber, |
197 |
amount => '80', |
198 |
due => $checkout1->date_due |
199 |
} |
200 |
); |
201 |
|
202 |
$fines = Koha::Account::Lines->search( |
203 |
{ borrowernumber => $patron->borrowernumber } ); |
204 |
is( $fines->count, 1, "Existing fine updated" ); |
205 |
$fine = $fines->next; |
206 |
is( $fine->amount, '80.000000', "Fine amount correctly updated to 80" ); |
207 |
|
208 |
# Add fine 2 |
209 |
UpdateFine( |
210 |
{ |
211 |
issue_id => $checkout2->issue_id, |
212 |
itemnumber => $item2->itemnumber, |
213 |
borrowernumber => $patron->borrowernumber, |
214 |
amount => '30', |
215 |
due => $checkout2->date_due |
216 |
} |
217 |
); |
218 |
|
219 |
$fines = Koha::Account::Lines->search( |
220 |
{ borrowernumber => $patron->borrowernumber }, |
221 |
{ order_by => { '-asc' => 'accountlines_id' } } |
222 |
); |
223 |
is( $fines->count, 2, "New fine added for second checkout" ); |
224 |
$fine = $fines->next; |
225 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
226 |
my $fine2 = $fines->next; |
227 |
is( $fine2->amount, '20.000000', "Second fine capped at '20' by MaxFine" ); |
228 |
is( $fine2->issue_id, $checkout2->issue_id, "Second fine is associated with the correct issue" ); |
229 |
is( $fine2->itemnumber, $checkout2->itemnumber, "Second fine is associated with the correct item" ); |
230 |
|
231 |
# Partial pay fine 1 |
232 |
$fine->amountoutstanding('50')->store; |
233 |
UpdateFine( |
234 |
{ |
235 |
issue_id => $checkout2->issue_id, |
236 |
itemnumber => $item2->itemnumber, |
237 |
borrowernumber => $patron->borrowernumber, |
238 |
amount => '30', |
239 |
due => $checkout2->date_due |
240 |
} |
241 |
); |
242 |
|
243 |
$fines = Koha::Account::Lines->search( |
244 |
{ borrowernumber => $patron->borrowernumber }, |
245 |
{ order_by => { '-asc' => 'accountlines_id' } } |
246 |
); |
247 |
is( $fines->count, 2, "Still two fines after second checkout update" ); |
248 |
$fine = $fines->next; |
249 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
250 |
$fine2 = $fines->next; |
251 |
is( $fine2->amount, '30.000000', "Second fine increased after partial payment of first" ); |
252 |
|
253 |
# Fix fine 1, create third fine |
254 |
$fine->accounttype('F')->store; |
255 |
UpdateFine( |
256 |
{ |
257 |
issue_id => $checkout1->issue_id, |
258 |
itemnumber => $item1->itemnumber, |
259 |
borrowernumber => $patron->borrowernumber, |
260 |
amount => '30', |
261 |
due => $checkout1->date_due |
262 |
} |
263 |
); |
264 |
|
265 |
$fines = Koha::Account::Lines->search( |
266 |
{ borrowernumber => $patron->borrowernumber }, |
267 |
{ order_by => { '-asc' => 'accountlines_id' } } |
268 |
); |
269 |
is( $fines->count, 3, "Third fine added for overdue renewal" ); |
270 |
$fine = $fines->next; |
271 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
272 |
$fine2 = $fines->next; |
273 |
is( $fine2->amount, '30.000000', "Second fine amount unchanged" ); |
274 |
my $fine3 = $fines->next; |
275 |
is( $fine3->amount, '20.000000', "Third fine amount capped due to MaxFine" ); |
276 |
is( $fine3->issue_id, $checkout1->issue_id, "Third fine is associated with the correct issue" ); |
277 |
is( $fine3->itemnumber, $checkout1->itemnumber, "Third fine is associated with the correct item" ); |
278 |
|
279 |
# FIXME: Add test to check whether sundry/manual charges are included within MaxFine. |
280 |
# FIXME: Add test to ensure other charges are not included within MaxFine. |
281 |
|
282 |
# Disable MaxFine |
283 |
t::lib::Mocks::mock_preference( 'MaxFine', '0' ); |
284 |
UpdateFine( |
285 |
{ |
286 |
issue_id => $checkout1->issue_id, |
287 |
itemnumber => $item1->itemnumber, |
288 |
borrowernumber => $patron->borrowernumber, |
289 |
amount => '30', |
290 |
due => $checkout1->date_due |
291 |
} |
292 |
); |
293 |
|
294 |
$fines = Koha::Account::Lines->search( |
295 |
{ borrowernumber => $patron->borrowernumber }, |
296 |
{ order_by => { '-asc' => 'accountlines_id' } } |
297 |
); |
298 |
is( $fines->count, 3, "Still only three fines after MaxFine cap removed" ); |
299 |
$fine = $fines->next; |
300 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
301 |
$fine2 = $fines->next; |
302 |
is( $fine2->amount, '30.000000', "Second fine amount unchanged" ); |
303 |
$fine3 = $fines->next; |
304 |
is( $fine3->amount, '30.000000', "Third fine increased now MaxFine cap is disabled" ); |
305 |
|
306 |
$schema->storage->txn_rollback; |
307 |
}; |