Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 11; |
22 |
use Test::More tests => 12; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
25 |
|
25 |
|
Lines 269-284
subtest 'apply() tests' => sub {
Link Here
|
269 |
|
269 |
|
270 |
my $accountline = Koha::Account::Line->new( |
270 |
my $accountline = Koha::Account::Line->new( |
271 |
{ |
271 |
{ |
272 |
issue_id => $checkout->id, |
272 |
issue_id => $checkout->id, |
273 |
borrowernumber => $patron->id, |
273 |
borrowernumber => $patron->id, |
274 |
itemnumber => $item->id, |
274 |
itemnumber => $item->id, |
275 |
branchcode => $library->id, |
275 |
branchcode => $library->id, |
276 |
date => \'NOW()', |
276 |
date => \'NOW()', |
277 |
accounttype => 'OVERDUE', |
277 |
debit_type_code => 'OVERDUE', |
278 |
status => 'UNRETURNED', |
278 |
status => 'UNRETURNED', |
279 |
interface => 'cli', |
279 |
interface => 'cli', |
280 |
amount => '1', |
280 |
amount => '1', |
281 |
amountoutstanding => '1', |
281 |
amountoutstanding => '1', |
282 |
} |
282 |
} |
283 |
)->store(); |
283 |
)->store(); |
284 |
|
284 |
|
Lines 288-294
subtest 'apply() tests' => sub {
Link Here
|
288 |
my $module = new Test::MockModule('C4::Circulation'); |
288 |
my $module = new Test::MockModule('C4::Circulation'); |
289 |
$module->mock('AddRenewal', sub { $called = 1; }); |
289 |
$module->mock('AddRenewal', sub { $called = 1; }); |
290 |
my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); |
290 |
my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); |
291 |
my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id }); |
291 |
my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; |
292 |
$credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); |
292 |
$credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); |
293 |
|
293 |
|
294 |
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); |
294 |
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); |
Lines 345-350
subtest 'Keep account info when related patron, staff, item or cash_register is
Link Here
|
345 |
$schema->storage->txn_rollback; |
345 |
$schema->storage->txn_rollback; |
346 |
}; |
346 |
}; |
347 |
|
347 |
|
|
|
348 |
subtest 'Renewal related tests' => sub { |
349 |
|
350 |
plan tests => 7; |
351 |
|
352 |
$schema->storage->txn_begin; |
353 |
|
354 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
355 |
my $staff = $builder->build_object( { class => 'Koha::Patrons' } ); |
356 |
my $item = $builder->build_object({ class => 'Koha::Items' }); |
357 |
my $issue = $builder->build_object( |
358 |
{ |
359 |
class => 'Koha::Checkouts', |
360 |
value => { |
361 |
itemnumber => $item->itemnumber, |
362 |
onsite_checkout => 0, |
363 |
renewals => 99, |
364 |
auto_renew => 0 |
365 |
} |
366 |
} |
367 |
); |
368 |
my $line = Koha::Account::Line->new( |
369 |
{ |
370 |
borrowernumber => $patron->borrowernumber, |
371 |
manager_id => $staff->borrowernumber, |
372 |
itemnumber => $item->itemnumber, |
373 |
debit_type_code => "OVERDUE", |
374 |
status => "UNRETURNED", |
375 |
amountoutstanding => 0, |
376 |
interface => 'commandline', |
377 |
})->store; |
378 |
|
379 |
is( $line->renewable, 1, "Item is returned as renewable when it meets the conditions" ); |
380 |
$line->amountoutstanding(5); |
381 |
is( $line->renewable, 0, "Item is returned as unrenewable when it has outstanding fine" ); |
382 |
$line->amountoutstanding(0); |
383 |
$line->debit_type_code("VOID"); |
384 |
is( $line->renewable, 0, "Item is returned as unrenewable when it has the wrong account type" ); |
385 |
$line->debit_type_code("OVERDUE"); |
386 |
$line->status("RETURNED"); |
387 |
is( $line->renewable, 0, "Item is returned as unrenewable when it has the wrong account status" ); |
388 |
|
389 |
|
390 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 ); |
391 |
is ($line->renew_item, 0, 'Attempt to renew fails when syspref is not set'); |
392 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 ); |
393 |
is_deeply( |
394 |
$line->renew_item, |
395 |
{ |
396 |
itemnumber => $item->itemnumber, |
397 |
error => 'too_many', |
398 |
success => 0 |
399 |
}, |
400 |
'Attempt to renew fails when CanBookBeRenewed returns false' |
401 |
); |
402 |
$issue->delete; |
403 |
$issue = $builder->build_object( |
404 |
{ |
405 |
class => 'Koha::Checkouts', |
406 |
value => { |
407 |
itemnumber => $item->itemnumber, |
408 |
onsite_checkout => 0, |
409 |
renewals => 0, |
410 |
auto_renew => 0 |
411 |
} |
412 |
} |
413 |
); |
414 |
my $called = 0; |
415 |
my $module = new Test::MockModule('C4::Circulation'); |
416 |
$module->mock('AddRenewal', sub { $called = 1; }); |
417 |
$line->renew_item; |
418 |
is( $called, 1, 'Attempt to renew succeeds when conditions are met' ); |
419 |
|
420 |
$schema->storage->txn_rollback; |
421 |
}; |
422 |
|
348 |
subtest 'adjust() tests' => sub { |
423 |
subtest 'adjust() tests' => sub { |
349 |
|
424 |
|
350 |
plan tests => 29; |
425 |
plan tests => 29; |
Lines 606-612
subtest "void() tests" => sub {
Link Here
|
606 |
lines => [$line1, $line2], |
681 |
lines => [$line1, $line2], |
607 |
amount => 30, |
682 |
amount => 30, |
608 |
} |
683 |
} |
609 |
); |
684 |
)->{payment_id}; |
610 |
|
685 |
|
611 |
my $account_payment = Koha::Account::Lines->find( $id ); |
686 |
my $account_payment = Koha::Account::Lines->find( $id ); |
612 |
|
687 |
|
613 |
- |
|
|