From 5d8943c80c51365c8f2bc78c85da6f037c4ffd7a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 27 Jun 2016 18:41:32 +0000 Subject: [PATCH] Bug 7595 - Unit Tests --- t/db_dependent/Accounts.t | 52 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index fb0ffb7..358058a 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -18,16 +18,19 @@ use Modern::Perl; -use Test::More tests => 19; +use Test::More tests => 33; use Test::MockModule; use Test::Warn; use t::lib::TestBuilder; +use C4::Circulation; + BEGIN { use_ok('C4::Accounts'); use_ok('Koha::Object'); use_ok('Koha::Patron'); + use_ok('Koha::Account::Lines'); use_ok('Data::Dumper'); } @@ -60,7 +63,6 @@ $dbh->do(q|DELETE FROM issues|); $dbh->do(q|DELETE FROM borrowers|); my $branchcode = $library->{branchcode}; -my $borrower_number; my $context = new Test::MockModule('C4::Context'); $context->mock( 'userenv', sub { @@ -71,6 +73,52 @@ $context->mock( 'userenv', sub { }; }); + +# Test chargelostitem +my $item = $builder->build( { source => 'Item' } ); +my $patron = $builder->build( { source => 'Borrower' } ); +my $amount = '5.000000'; +my $description = "Test fee!"; +chargelostitem( $patron->{borrowernumber}, $item->{itemnumber}, $amount, $description ); +my ($accountline) = Koha::Account::Lines->search( + { + borrowernumber => $patron->{borrowernumber} + } +); +is( $accountline->amount, $amount, 'Accountline amount set correctly for chargelostitem' ); +is( $accountline->description, $description, 'Accountline description set correctly for chargelostitem' ); +is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for chargelostitem' ); +$dbh->do(q|DELETE FROM accountlines|); + +# Test manualinvoice, reuse some of the vars from testing chargelostitem +my $type = 'L'; +my $note = 'Test note!'; +manualinvoice( $patron->{borrowernumber}, $item->{itemnumber}, $description, $type, $amount, $note ); +($accountline) = Koha::Account::Lines->search( + { + borrowernumber => $patron->{borrowernumber} + } +); +is( $accountline->accounttype, $type, 'Accountline type set correctly for manualinvoice' ); +is( $accountline->amount, $amount, 'Accountline amount set correctly for manualinvoice' ); +ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' ); +is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' ); +is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for manualinvoice' ); + +# Test _FixAccountForLostAndReturned, use the accountline from the manualinvoice to test +C4::Circulation::_FixAccountForLostAndReturned( $item->{itemnumber} ); +my ( $accountline_fee, $accountline_payment ) = Koha::Account::Lines->search( + { + borrowernumber => $patron->{borrowernumber} + } +); +is( $accountline_fee->accounttype, 'LR', 'Lost item fee account type updated to LR' ); +is( $accountline_fee->amountoutstanding, '0.000000', 'Lost item fee amount outstanding updated to 0' ); +is( $accountline_payment->accounttype, 'CR', 'Lost item fee account type is CR' ); +is( $accountline_payment->amount, "-$amount", 'Lost item refund amount is correct' ); +is( $accountline_payment->branchcode, $branchcode, 'Lost item refund branchcode is set correctly' ); +$dbh->do(q|DELETE FROM accountlines|); + # Testing purge_zero_balance_fees # The 3rd value in the insert is 'days ago' -- -- 2.1.4