From 2b4f9b97e2aea9fde790a6985294865f11ae8079 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 6 Jun 2017 09:33:46 -0400 Subject: [PATCH] Bug 14826 - Add unit tests for _FixAccountForLostAndReturned and _FixOverduesOnReturn --- t/db_dependent/Circulation.t | 132 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 128 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index ae39393..8995060 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 102; +use Test::More tests => 104; use DateTime; @@ -257,9 +257,6 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $biblionumber ); - - - # Create borrowers my %renewing_borrower_data = ( firstname => 'John', @@ -1644,6 +1641,133 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { is( $debarments->[0]->{expiration}, $expected_expiration ); }; +subtest '_FixAccountForLostAndReturned' => sub { + plan tests => 2; + + # Generate test biblio + my $biblio = MARC::Record->new(); + my $title = 'Koha for Dummies'; + $biblio->append_fields( + MARC::Field->new( '100', ' ', ' ', a => 'Hall, Daria' ), + MARC::Field->new( '245', ' ', ' ', a => $title ), + ); + + my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' ); + + my $barcode = 'KD123456789'; + my $branchcode = $library2->{branchcode}; + + my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( + { + homebranch => $branchcode, + holdingbranch => $branchcode, + barcode => $barcode, + replacementprice => 99.00, + itype => $itemtype + }, + $biblionumber + ); + + my $patron = $builder->build( { source => 'Borrower' } ); + + my $accountline = Koha::Account::Line->new( + { + borrowernumber => $patron->{borrowernumber}, + accounttype => 'L', + itemnumber => $itemnumber, + amount => 99.00, + amountoutstanding => 99.00, + } + )->store(); + + C4::Circulation::_FixAccountForLostAndReturned( $itemnumber, $patron->{borrowernumber} ); + + $accountline->_result()->discard_changes(); + + is( $accountline->amountoutstanding, '0.000000', 'Lost fee has no outstanding amount' ); + is( $accountline->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )'); +}; + +subtest '_FixOverduesOnReturn' => sub { + plan tests => 6; + + # Generate test biblio + my $biblio = MARC::Record->new(); + my $title = 'Koha for Dummies'; + $biblio->append_fields( + MARC::Field->new( '100', ' ', ' ', a => 'Hall, Kylie' ), + MARC::Field->new( '245', ' ', ' ', a => $title ), + ); + + my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' ); + + my $barcode = 'KD987654321'; + my $branchcode = $library2->{branchcode}; + + my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( + { + homebranch => $branchcode, + holdingbranch => $branchcode, + barcode => $barcode, + replacementprice => 99.00, + itype => $itemtype + }, + $biblionumber + ); + + my $patron = $builder->build( { source => 'Borrower' } ); + + ## Start with basic call, should just close out the open fine + my $accountline = Koha::Account::Line->new( + { + borrowernumber => $patron->{borrowernumber}, + accounttype => 'FU', + itemnumber => $itemnumber, + amount => 99.00, + amountoutstanding => 99.00, + lastincrement => 9.00, + } + )->store(); + + C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber ); + + $accountline->_result()->discard_changes(); + + is( $accountline->amountoutstanding, '99.000000', 'Fine has the same amount outstanding as previously' ); + is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )'); + + + ## Run again, with exemptfine enabled + $accountline->set( + { + accounttype => 'FU', + amountoutstanding => 99.00, + } + )->store(); + + C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber, 1 ); + + $accountline->_result()->discard_changes(); + + is( $accountline->amountoutstanding, '0.000000', 'Fine has been reduced to 0' ); + is( $accountline->accounttype, 'FFOR', 'Open fine ( account type FU ) has been set to fine forgiven ( account type FFOR )'); + + ## Run again, with dropbox mode enabled + $accountline->set( + { + accounttype => 'FU', + amountoutstanding => 99.00, + } + )->store(); + + C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $itemnumber, 0, 1 ); + + $accountline->_result()->discard_changes(); + + is( $accountline->amountoutstanding, '90.000000', 'Fine has been reduced to 90' ); + is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )'); +}; + sub set_userenv { my ( $library ) = @_; C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); -- 2.1.4