From d5049580070af1d2f8a4fdc8bb67f3f0944724c6 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Mon, 10 Feb 2020 13:55:28 +0200 Subject: [PATCH 3/3] Bug 13961: Add unit test Sponsored-by: Koha-Suomi Oy --- t/db_dependent/Letters.t | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index bdeed6ead6..cdee2444d4 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,11 +18,12 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 73; +use Test::More tests => 74; use Test::MockModule; use Test::Warn; use MARC::Record; +use Locale::Currency::Format; my %mail; my $module = new Test::MockModule('Mail::Sendmail'); @@ -50,6 +51,8 @@ use Koha::Libraries; use Koha::Notice::Templates; use Koha::Patrons; use Koha::Subscriptions; +use Koha::Account; +use Koha::Account::Lines; my $schema = Koha::Database->schema; $schema->storage->txn_begin(); @@ -355,6 +358,29 @@ is( $prepared_letter->{content}, q|And also this one:| . output_pref({ dt => $ye $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('claimacquisition','TESTACQCLAIM','Acquisition Claim','Item Not Received','<>|<>|Ordernumber <> (<>) (<> ordered)');}); $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('orderacquisition','TESTACQORDER','Acquisition Order','Order','<>|<>|Ordernumber <> (<>) (<> ordered)');}); +# Test borrowers.account_balance +my $account = Koha::Account->new({ patron_id => $borrowernumber }); +$account->add_debit({ amount => 10, interface => 'test', type => 'OVERDUE'})->store; +$account->add_debit({ amount => 15, interface => 'test', type => 'OVERDUE'})->store; + +my $lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber }); +my $totalfine = $lines->total_outstanding; +my $active_currency = Koha::Acquisition::Currencies->get_active; +my $currency_format = $active_currency->currency if defined($active_currency); +my $totalfine_formatted = currency_format($currency_format, "$totalfine", FMT_SYMBOL); +$totalfine_formatted = sprintf("%.2f", $totalfine) unless $totalfine_formatted; + +$dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('test_fines','TEST_FINES','Test total of fines','','Total of fines is: <>.');}); +$prepared_letter = GetPreparedLetter(( + module => 'test_fines', + branchcode => '', + letter_code => 'test_fines', + tables => $tables, + substitute => $substitute, + repeat => $repeat, +)); +is( $prepared_letter->{content}, q|Total of fines is: | . $totalfine_formatted . q|.|, 'Account balance is printed correctly' ); + # Test that _parseletter doesn't modify its parameters bug 15429 { my $values = { dateexpiry => '2015-12-13', }; -- 2.17.1