From 89ff4f66f8fb1797d05ab10d3eb08e179f487e6a Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Mon, 10 Feb 2020 13:55:28 +0200 Subject: [PATCH 3/5] Bug 13961: Add unit test Sponsored-by: Koha-Suomi Oy Signed-off-by: Sally --- 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 613f5696d3..98de56e443 100755 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,13 +18,14 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 83; +use Test::More tests => 84; use Test::MockModule; use Test::Warn; use Email::Sender::Failure; use MARC::Record; +use Locale::Currency::Format; use utf8; @@ -57,6 +58,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(); @@ -366,6 +369,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.25.1