From ff10cb7b986847a5bd7638c17feb0d6a2ccc20e9 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Fri, 14 Jul 2023 07:32:11 -0400
Subject: [PATCH] Bug 34279: Unit tests

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
---
 t/db_dependent/Circulation/CalcFine.t | 80 ++++++++++++++++++++++++++-
 1 file changed, 79 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/Circulation/CalcFine.t b/t/db_dependent/Circulation/CalcFine.t
index 23607b3160..628e45b460 100755
--- a/t/db_dependent/Circulation/CalcFine.t
+++ b/t/db_dependent/Circulation/CalcFine.t
@@ -2,7 +2,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 5;
+use Test::More tests => 7;
 use Test::Warn;
 
 use C4::Context;
@@ -101,6 +101,84 @@ subtest 'Test basic functionality' => sub {
     teardown();
 };
 
+subtest 'Overdue fines cap should be disabled when value is 0' => sub {
+    plan tests => 1;
+
+    Koha::CirculationRules->set_rules(
+        {
+            branchcode   => undef,
+            categorycode => undef,
+            itemtype     => undef,
+            rules        => {
+                fine                          => '1.00',
+                lengthunit                    => 'days',
+                finedays                      => 0,
+                firstremind                   => 0,
+                chargeperiod                  => 1,
+                overduefinescap               => "0",
+                cap_fine_to_replacement_price => 0,
+            }
+        },
+    );
+
+    my $start_dt = DateTime->new(
+        year       => 2000,
+        month      => 1,
+        day        => 1,
+    );
+
+    my $end_dt = DateTime->new(
+        year       => 2000,
+        month      => 1,
+        day        => 30,
+    );
+
+    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
+
+    is( $amount, 29, 'Amount is calculated correctly' );
+
+    teardown();
+};
+
+subtest 'Overdue fines cap should be disabled when value is 0.00' => sub {
+    plan tests => 1;
+
+    Koha::CirculationRules->set_rules(
+        {
+            branchcode   => undef,
+            categorycode => undef,
+            itemtype     => undef,
+            rules        => {
+                fine                          => '1.00',
+                lengthunit                    => 'days',
+                finedays                      => 0,
+                firstremind                   => 0,
+                chargeperiod                  => 1,
+                overduefinescap               => "0.00",
+                cap_fine_to_replacement_price => 0,
+            }
+        },
+    );
+
+    my $start_dt = DateTime->new(
+        year       => 2000,
+        month      => 1,
+        day        => 1,
+    );
+
+    my $end_dt = DateTime->new(
+        year       => 2000,
+        month      => 1,
+        day        => 30,
+    );
+
+    my ($amount) = CalcFine( $item->unblessed, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
+
+    is( $amount, 29, 'Amount is calculated correctly' );
+
+    teardown();
+};
+
 subtest 'Test with fine amount empty' => sub {
     plan tests => 1;
 
-- 
2.30.2