From db4beb014b17a1097d2e642dc913ce2046c53e00 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 12 Apr 2018 14:12:29 +0000 Subject: [PATCH] Bug 19191: Add correct unit tests Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- .../data/mysql/atomicupdate/bug_19191.sql | 4 ++ t/db_dependent/Accounts.t | 62 ++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug_19191.sql diff --git a/installer/data/mysql/atomicupdate/bug_19191.sql b/installer/data/mysql/atomicupdate/bug_19191.sql new file mode 100644 index 0000000000..e081ef43e9 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_19191.sql @@ -0,0 +1,4 @@ +INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) + VALUES + ('circulation', 'ACCOUNT_PAYMENT', '', 'Account Payment', 0, 'Account Payment', '[%- USE Price -%]\r\nA payment of [% credit.amount * -1 | $Price %] has been applied to your account.\r\n\r\nThis payment affected the following fees:\r\n[%- FOREACH o IN offsets %]\r\nDescription: [% o.debit.description %]\r\nAmount paid: [% o.amount * -1 | $Price %]\r\nAmount remaining: [% o.debit.amountoutstanding | $Price %]\r\n[% END %]', 'email', 'default'), + ('circulation', 'ACCOUNT_WRITEOFF', '', 'Account Writeoff', 0, 'Account Writeoff', '[%- USE Price -%]\r\nAn account writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.\r\n\r\nThis writeoff affected the following fees:\r\n[%- FOREACH o IN offsets %]\r\nDescription: [% o.debit.description %]\r\nAmount paid: [% o.amount * -1 | $Price %]\r\nAmount remaining: [% o.debit.amountoutstanding | $Price %]\r\n[% END %]', 'email', 'default'); diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index f6cae2b272..26a789c96a 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -18,7 +18,7 @@ use Modern::Perl; -use Test::More tests => 27; +use Test::More tests => 28; use Test::MockModule; use Test::Warn; @@ -28,6 +28,8 @@ use t::lib::Mocks; use Koha::Account; use Koha::Account::Lines; use Koha::Account::Offsets; +use Koha::Notice::Messages; +use Koha::Notice::Templates; use Koha::DateUtils qw( dt_from_string ); BEGIN { @@ -958,4 +960,62 @@ subtest "Koha::Account::Offset credit & debit tests" => sub { is( $account_offset->credit, undef, "Koha::Account::Offset->credit returns undef if no associated credit" ); }; +subtest "Payment notice tests" => sub { + + plan tests => 8; + + Koha::Account::Lines->delete(); + Koha::Patrons->delete(); + Koha::Notice::Messages->delete(); + # Create a borrower + my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; + my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; + + my $borrower = Koha::Patron->new( + { + cardnumber => 'chelseahall', + surname => 'Hall', + firstname => 'Chelsea', + email => 'chelsea@example.com', + categorycode => $categorycode, + branchcode => $branchcode, + } + )->store(); + + my $account = Koha::Account->new({ patron_id => $borrower->id }); + + my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store(); + + my $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_PAYMENT' } ); + $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.'); + $letter->store(); + + t::lib::Mocks::mock_preference('UseEmailReceipts', '0'); + + my $id = $account->pay( { amount => 1 } ); + is( Koha::Notice::Messages->search()->count(), 0, 'Notice for payment not sent if UseEmailReceipts is disabled' ); + + $id = $account->pay( { amount => 1, type => 'writeoff' } ); + is( Koha::Notice::Messages->search()->count(), 0, 'Notice for writeoff not sent if UseEmailReceipts is disabled' ); + + t::lib::Mocks::mock_preference('UseEmailReceipts', '1'); + + $id = $account->pay( { amount => 12 } ); + my $notice = Koha::Notice::Messages->search()->next(); + is( $notice->subject, 'Account payment', 'Notice subject is correct for payment' ); + is( $notice->letter_code, 'ACCOUNT_PAYMENT', 'Notice letter code is correct for payment' ); + is( $notice->content, 'A payment of 12.00 has been applied to your account.', 'Notice content is correct for payment' ); + $notice->delete(); + + $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_WRITEOFF' } ); + $letter->content('[%- USE Price -%]A writeoff of [% credit.amount * -1 | $Price %] has been applied to your account.'); + $letter->store(); + + $id = $account->pay( { amount => 13, type => 'writeoff' } ); + $notice = Koha::Notice::Messages->search()->next(); + is( $notice->subject, 'Account writeoff', 'Notice subject is correct for payment' ); + is( $notice->letter_code, 'ACCOUNT_WRITEOFF', 'Notice letter code is correct for writeoff' ); + is( $notice->content, 'A writeoff of 13.00 has been applied to your account.', 'Notice content is correct for writeoff' ); +}; + 1; -- 2.39.5