From aa9de3389274a4b7814f864c365f7efc8356baa9 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 --- installer/data/mysql/atomicupdate/bug_19191.sql | 4 ++ t/db_dependent/Accounts.t | 56 +++++++++++++++---------- 2 files changed, 39 insertions(+), 21 deletions(-) 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 ad04d0e212..47dd605868 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -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 { @@ -904,40 +906,52 @@ subtest "Koha::Account::Line::void tests" => sub { is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' ); }; -subtest "Koha::Account::Offset tests" => sub { +subtest "Payment notice tests" => sub { - plan tests => 2; + plan tests => 6; 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', - } ); - $borrower->categorycode( $categorycode ); - $borrower->branchcode( $branchcode ); - $borrower->store; + 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 $id = $account->pay( - { - amount => 13, - } - ); - - my $offset = Koha::Account::Offsets->find( { credit_id => $id } ); - - is( $offset->credit->id, $id, 'Got correct credit for account offset' ); - is( $offset->debit->id, $line->id, 'Got correct debit for account offset' ); + 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(); + + my $id = $account->pay( { amount => 13 } ); + 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 13.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 => 14, 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 14.00 has been applied to your account.', 'Notice content is correct for writeoff' ); }; 1; -- 2.15.1 (Apple Git-101)