Bug 19191: Add correct unit tests

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Kyle Hall 2018-04-12 14:12:29 +00:00 committed by Nick Clemens
parent fb6da950a7
commit db4beb014b
2 changed files with 65 additions and 1 deletions

View file

@ -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');

View file

@ -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;