|
Lines 23-32
use Test::More tests => 11;
Link Here
|
| 23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
|
25 |
|
|
|
26 |
use DateTime; |
| 27 |
|
| 26 |
use Koha::Account; |
28 |
use Koha::Account; |
| 27 |
use Koha::Account::Lines; |
29 |
use Koha::Account::Lines; |
| 28 |
use Koha::Account::Offsets; |
30 |
use Koha::Account::Offsets; |
| 29 |
|
31 |
use Koha::DateUtils qw( dt_from_string ); |
| 30 |
|
32 |
|
| 31 |
use t::lib::Mocks; |
33 |
use t::lib::Mocks; |
| 32 |
use t::lib::TestBuilder; |
34 |
use t::lib::TestBuilder; |
|
Lines 567-572
subtest 'pay() tests' => sub {
Link Here
|
| 567 |
|
569 |
|
| 568 |
$schema->storage->txn_begin; |
570 |
$schema->storage->txn_begin; |
| 569 |
|
571 |
|
|
|
572 |
# Disable renewing upon fine payment |
| 573 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 ); |
| 574 |
|
| 570 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
575 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 571 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
576 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
| 572 |
my $account = $patron->account; |
577 |
my $account = $patron->account; |
|
Lines 584-589
subtest 'pay() tests' => sub {
Link Here
|
| 584 |
|
589 |
|
| 585 |
is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' ); |
590 |
is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' ); |
| 586 |
|
591 |
|
|
|
592 |
|
| 587 |
$schema->storage->txn_rollback; |
593 |
$schema->storage->txn_rollback; |
| 588 |
}; |
594 |
}; |
| 589 |
|
595 |
|
|
Lines 731-736
subtest 'pay() handles lost items when paying by amount ( not specifying the los
Link Here
|
| 731 |
$schema->storage->txn_rollback; |
737 |
$schema->storage->txn_rollback; |
| 732 |
}; |
738 |
}; |
| 733 |
|
739 |
|
|
|
740 |
subtest 'pay() renews items when appropriate' => sub { |
| 741 |
|
| 742 |
plan tests => 1; |
| 743 |
|
| 744 |
$schema->storage->txn_begin; |
| 745 |
|
| 746 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 747 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 748 |
my $account = $patron->account; |
| 749 |
|
| 750 |
my $context = Test::MockModule->new('C4::Context'); |
| 751 |
$context->mock( 'userenv', { branch => $library->id } ); |
| 752 |
|
| 753 |
my $biblio = $builder->build_sample_biblio(); |
| 754 |
my $item = |
| 755 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 756 |
|
| 757 |
my $now = dt_from_string(); |
| 758 |
my $seven_weeks = DateTime::Duration->new(weeks => 7); |
| 759 |
my $five_weeks = DateTime::Duration->new(weeks => 5); |
| 760 |
my $seven_weeks_ago = $now - $seven_weeks; |
| 761 |
my $five_weeks_ago = $now - $five_weeks; |
| 762 |
|
| 763 |
my $checkout = Koha::Checkout->new( |
| 764 |
{ |
| 765 |
borrowernumber => $patron->id, |
| 766 |
itemnumber => $item->id, |
| 767 |
date_due => $five_weeks_ago, |
| 768 |
branchcode => $patron->branchcode, |
| 769 |
issuedate => $seven_weeks_ago |
| 770 |
} |
| 771 |
)->store(); |
| 772 |
|
| 773 |
my $accountline = Koha::Account::Line->new( |
| 774 |
{ |
| 775 |
issue_id => $checkout->id, |
| 776 |
borrowernumber => $patron->id, |
| 777 |
itemnumber => $item->id, |
| 778 |
date => \'NOW()', |
| 779 |
accounttype => 'OVERDUE', |
| 780 |
status => 'UNRETURNED', |
| 781 |
interface => 'cli', |
| 782 |
amount => '1', |
| 783 |
amountoutstanding => '1', |
| 784 |
} |
| 785 |
)->store(); |
| 786 |
|
| 787 |
# Enable renewing upon fine payment |
| 788 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 ); |
| 789 |
my $called = 0; |
| 790 |
my $module = new Test::MockModule('C4::Circulation'); |
| 791 |
$module->mock('AddRenewal', sub { $called = 1; }); |
| 792 |
$account->pay( |
| 793 |
{ |
| 794 |
amount => '1', |
| 795 |
library_id => $library->id, |
| 796 |
} |
| 797 |
); |
| 798 |
|
| 799 |
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); |
| 800 |
|
| 801 |
$schema->storage->txn_rollback; |
| 802 |
}; |
| 803 |
|
| 734 |
subtest 'Koha::Account::Line::apply() handles lost items' => sub { |
804 |
subtest 'Koha::Account::Line::apply() handles lost items' => sub { |
| 735 |
|
805 |
|
| 736 |
plan tests => 4; |
806 |
plan tests => 4; |