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