Bug 7639: (follow-up) add Unit Tests
authorKyle M Hall <kyle@bywatersolutions.com>
Mon, 19 Aug 2013 12:01:13 +0000 (08:01 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 17 Sep 2013 15:22:07 +0000 (15:22 +0000)
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
All tests and QA script pass.
I fixed a redundant 'my' that the QA script pointed out.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
t/db_dependent/Circulation.t

index 1ef6271..60b93e2 100755 (executable)
@@ -9,7 +9,7 @@ use C4::Items;
 use C4::Members;
 use C4::Reserves;
 
-use Test::More tests => 36;
+use Test::More tests => 38;
 
 BEGIN {
     use_ok('C4::Circulation');
@@ -132,16 +132,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
@@ -160,7 +163,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
 
@@ -177,16 +180,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 = (
@@ -284,6 +297,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' );
 }
 
 {