From 7fd12b6bb15a638b2e30ebfb670f45833d2a0924 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 --- t/db_dependent/Accounts.t | 56 +++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index 72589cb..1f8b473 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 { @@ -844,40 +846,52 @@ subtest "Koha::Account::non_issues_charges tests" => sub { is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" ); }; -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.1.4