From 019b61c85bf5eea9560f9d94960596ba3db6109a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 12 Apr 2018 14:10:58 +0000 Subject: [PATCH] Bug 19191: Add correct unit tests --- Koha/Account.pm | 17 +++++++++++++- t/db_dependent/Accounts.t | 56 +++++++++++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index 596b137682..e02725ee1f 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -260,10 +260,25 @@ sub pay { ) ); } + my $letter = C4::Letters::GetPreparedLetter( + module => 'circulation', + letter_code => uc("ACCOUNT_$type"), + message_transport_type => 'email', + lang => Koha::Patrons->find( $self->{patron_id} )->lang, + tables => { + borrowers => $self->{patron_id}, + branches => $self->{library_id}, + }, + substitute => { + credit => $payment, + offsets => scalar Koha::Account::Offsets->search( { id => { -in => [ map { $_->id } @account_offsets ] } } ), + }, + ); + warn "LETTER: " . Data::Dumper::Dumper( $letter ); require C4::Letters; if ( - my $letter = C4::Letters::GetPreparedLetter( + $letter = C4::Letters::GetPreparedLetter( module => 'circulation', letter_code => uc("ACCOUNT_$type"), message_transport_type => 'email', diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index 72589cbe11..18a418ac7c 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(); + + my $id = $account->pay( { amount => 14, type => 'writeoff' } ); + my $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)