From 4973ac57af8a3d8837ac1072d1db4013b72e56b3 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 19 Aug 2013 08:01:13 -0400 Subject: [PATCH] [PASSED QA] Bug 7639 - system preference to forgive fines on lost items - Add Unit Tests Signed-off-by: Katrin Fischer All tests and QA script pass. I fixed a redundant 'my' that the QA script pointed out. --- t/db_dependent/Circulation.t | 70 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index bf27fb5..03a1d51 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -9,7 +9,7 @@ use C4::Items; use C4::Members; use C4::Reserves; -use Test::More tests => 30; +use Test::More tests => 32; BEGIN { use_ok('C4::Circulation'); @@ -129,16 +129,19 @@ $dbh->do('DELETE FROM issuingrules'); $dbh->do( q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, - renewalsallowed, renewalperiod) + renewalsallowed, renewalperiod, + fine, chargeperiod) VALUES (?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ? ) }, {}, '*', '*', '*', 25, 20, 14, 'days', - 1, 7 + 1, 7, + .10, 1 ); # Test C4::Circulation::ProcessOfflinePayment @@ -157,7 +160,7 @@ ok( $new_count == $original_count + 1, 'ProcessOfflinePayment makes payment cor C4::Context->dbh->do("DELETE FROM accountlines WHERE borrowernumber IN ( SELECT borrowernumber FROM borrowers WHERE cardnumber = '99999999999' )"); C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'"); - +C4::Context->dbh->do("DELETE FROM accountlines"); { # CanBookBeRenewed tests @@ -174,16 +177,26 @@ C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'"); my $barcode = 'R00000342'; my $branch = 'MPL'; - my ($item_bibnum, $item_bibitemnum, $itemnumber) = - AddItem({ homebranch => $branch, - holdingbranch => $branch, - barcode => $barcode, } , $biblionumber); + my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( + { + homebranch => $branch, + holdingbranch => $branch, + barcode => $barcode, + replacementprice => 12.00 + }, + $biblionumber + ); my $barcode2 = 'R00000343'; - my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = - AddItem({ homebranch => $branch, - holdingbranch => $branch, - barcode => $barcode2, } , $biblionumber); + my ( $item_bibnum2, $item_bibitemnum2, $itemnumber2 ) = AddItem( + { + homebranch => $branch, + holdingbranch => $branch, + barcode => $barcode2, + replacementprice => 23.00 + }, + $biblionumber + ); # Create 2 borrowers my %renewing_borrower_data = ( @@ -281,6 +294,39 @@ C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'"); is( $renewokay, 0, 'Cannot renew, 0 renewals allowed'); is( $error, 'too_many', 'Cannot renew, 0 renewals allowed (returned code is too_many)'); + # Test WhenLostForgiveFine and WhenLostChargeReplacementFee + diag("WhenLostForgiveFine and WhenLostChargeReplacementFee"); + C4::Context->set_preference('WhenLostForgiveFine','1'); + C4::Context->set_preference('WhenLostChargeReplacementFee','1'); + + C4::Overdues::UpdateFine( $itemnumber, $renewing_borrower->{borrowernumber}, + 15.00, q{}, Koha::DateUtils::output_pref($datedue) ); + + LostItem( $itemnumber, 1 ); + + my $total_due = $dbh->selectrow_array( + 'SELECT SUM( amountoutstanding ) FROM accountlines WHERE borrowernumber = ?', + undef, $renewing_borrower->{borrowernumber} + ); + + ok( $total_due == 12, 'Borrower only charged replacement fee with both WhenLostForgiveFine and WhenLostChargeReplacementFee enabled' ); + + C4::Context->dbh->do("DELETE FROM accountlines"); + + C4::Context->set_preference('WhenLostForgiveFine','0'); + C4::Context->set_preference('WhenLostChargeReplacementFee','0'); + + C4::Overdues::UpdateFine( $itemnumber2, $renewing_borrower->{borrowernumber}, + 15.00, q{}, Koha::DateUtils::output_pref($datedue) ); + + LostItem( $itemnumber2, 1 ); + + $total_due = $dbh->selectrow_array( + 'SELECT SUM( amountoutstanding ) FROM accountlines WHERE borrowernumber = ?', + undef, $renewing_borrower->{borrowernumber} + ); + + ok( $total_due == 15, 'Borrower only charged fine with both WhenLostForgiveFine and WhenLostChargeReplacementFee disabled' ); } $dbh->rollback; -- 1.7.9.5