|
Lines 175-181
subtest 'is_credit() and is_debit() tests' => sub {
Link Here
|
| 175 |
|
175 |
|
| 176 |
subtest 'apply() tests' => sub { |
176 |
subtest 'apply() tests' => sub { |
| 177 |
|
177 |
|
| 178 |
plan tests => 25; |
178 |
plan tests => 26; |
| 179 |
|
179 |
|
| 180 |
$schema->storage->txn_begin; |
180 |
$schema->storage->txn_begin; |
| 181 |
|
181 |
|
|
Lines 327-336
subtest 'apply() tests' => sub {
Link Here
|
| 327 |
my $module = Test::MockModule->new('C4::Circulation'); |
327 |
my $module = Test::MockModule->new('C4::Circulation'); |
| 328 |
$module->mock('AddRenewal', sub { $called = 1; }); |
328 |
$module->mock('AddRenewal', sub { $called = 1; }); |
| 329 |
$module->mock('CanBookBeRenewed', sub { return 1; }); |
329 |
$module->mock('CanBookBeRenewed', sub { return 1; }); |
| 330 |
my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); |
330 |
my $credit_forgive = $account->add_credit( |
|
|
331 |
{ |
| 332 |
amount => 1, |
| 333 |
user_id => $patron->id, |
| 334 |
interface => 'cli', |
| 335 |
type => 'FORGIVEN' |
| 336 |
} |
| 337 |
); |
| 331 |
my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; |
338 |
my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; |
| 332 |
$credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); |
339 |
$credit_forgive->apply( { debits => $debits_renew, offset_type => 'Forgiven' } ); |
|
|
340 |
is( $called, 0, 'C4::Circulation::AddRenew NOT called when RenewAccruingItemWhenPaid enabled but credit type is "FORGIVEN"' ); |
| 333 |
|
341 |
|
|
|
342 |
$accountline = Koha::Account::Line->new( |
| 343 |
{ |
| 344 |
issue_id => $checkout->id, |
| 345 |
borrowernumber => $patron->id, |
| 346 |
itemnumber => $item->id, |
| 347 |
branchcode => $library->id, |
| 348 |
date => \'NOW()', |
| 349 |
debit_type_code => 'OVERDUE', |
| 350 |
status => 'UNRETURNED', |
| 351 |
interface => 'cli', |
| 352 |
amount => '1', |
| 353 |
amountoutstanding => '1', |
| 354 |
} |
| 355 |
)->store(); |
| 356 |
my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); |
| 357 |
$debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; |
| 358 |
$credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); |
| 334 |
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); |
359 |
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); |
| 335 |
|
360 |
|
| 336 |
$schema->storage->txn_rollback; |
361 |
$schema->storage->txn_rollback; |
|
Lines 387-393
subtest 'Keep account info when related patron, staff, item or cash_register is
Link Here
|
| 387 |
|
412 |
|
| 388 |
subtest 'Renewal related tests' => sub { |
413 |
subtest 'Renewal related tests' => sub { |
| 389 |
|
414 |
|
| 390 |
plan tests => 7; |
415 |
plan tests => 8; |
| 391 |
|
416 |
|
| 392 |
$schema->storage->txn_begin; |
417 |
$schema->storage->txn_begin; |
| 393 |
|
418 |
|
|
Lines 428-437
subtest 'Renewal related tests' => sub {
Link Here
|
| 428 |
|
453 |
|
| 429 |
|
454 |
|
| 430 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 ); |
455 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 ); |
| 431 |
is ($line->renew_item, undef, 'Attempt to renew fails when syspref is not set'); |
456 |
is ($line->renew_item({ interface => 'intranet' }), undef, 'Attempt to renew fails when syspref is not set'); |
| 432 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 ); |
457 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 ); |
|
|
458 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemInOpac', 0 ); |
| 459 |
is ($line->renew_item({ interface => 'opac' }), undef, 'Attempt to renew fails when syspref is not set - OPAC'); |
| 460 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemInOpac', 1 ); |
| 433 |
is_deeply( |
461 |
is_deeply( |
| 434 |
$line->renew_item, |
462 |
$line->renew_item({ interface => 'intranet' }), |
| 435 |
{ |
463 |
{ |
| 436 |
itemnumber => $item->itemnumber, |
464 |
itemnumber => $item->itemnumber, |
| 437 |
error => 'too_many', |
465 |
error => 'too_many', |
| 438 |
- |
|
|