[Koha-patches] [PATCH] Test rental charges properly

Srdjan srdjan at catalyst.net.nz
Fri Jun 10 02:58:26 CEST 2016


* AddIssuingCharge() test was always returning pass - removed and
  replaced with:
* Test rental charges properly for both checkout and renewal

https://bugs.koha-community.org/show_bug.cgi?id=14803
---
 t/db_dependent/Circulation/issue.t | 49 ++++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t
index bbb7909..040b9ed 100644
--- a/t/db_dependent/Circulation/issue.t
+++ b/t/db_dependent/Circulation/issue.t
@@ -16,6 +16,7 @@
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
+use Data::Dumper;
 
 use Koha::DateUtils;
 use DateTime::Duration;
@@ -143,6 +144,15 @@ $dbh->do(
     $samplecat->{category_type}
 );
 
+my $TEST_ITEMTYPE = "_T_ITYPE";
+my %TEST_ITEMTYPE_REC = (
+    itemtype => $TEST_ITEMTYPE,
+    rentalcharge => "1.50",
+);
+Koha::ItemType->new(\%TEST_ITEMTYPE_REC)->store;
+
+t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
+
 #Add biblio and item
 my $record = MARC::Record->new();
 $record->append_fields(
@@ -158,7 +168,8 @@ my @sampleitem1 = C4::Items::AddItem(
         homebranch     => $samplebranch1->{branchcode},
         holdingbranch  => $samplebranch1->{branchcode},
         issue          => 1,
-        reserve        => 1
+        reserve        => 1,
+        itype          => $TEST_ITEMTYPE,
     },
     $biblionumber
 );
@@ -170,7 +181,8 @@ my @sampleitem2 = C4::Items::AddItem(
         homebranch     => $samplebranch2->{branchcode},
         holdingbranch  => $samplebranch2->{branchcode},
         notforloan     => 1,
-        issue          => 1
+        issue          => 1,
+        itype          => $TEST_ITEMTYPE,
     },
     $biblionumber
 );
@@ -209,9 +221,16 @@ my $userenv = C4::Context->userenv
 
 #Begin Tests
 
+my $bib = GetBiblioFromItemNumber( $item_id1);
+$query = " SELECT count(*) FROM accountlines";
+my $sth = $dbh->prepare($query);
+$sth->execute;
+my $countaccount = $sth -> fetchrow_array;
+is ($countaccount,0,"0 accountline exists");
+
 #Test AddIssue
 $query = " SELECT count(*) FROM issues";
-my $sth = $dbh->prepare($query);
+$sth = $dbh->prepare($query);
 $sth->execute;
 my $countissue = $sth -> fetchrow_array;
 is ($countissue ,0, "there is no issue");
@@ -232,20 +251,16 @@ my $issue_id2 = $dbh->last_insert_id( undef, undef, 'issues', undef );
 
 $sth->execute;
 $countissue = $sth -> fetchrow_array;
-is ($countissue,1,"1 issues have been added");
+is ($countissue,1,"1 issue has been added");
 
 #Test AddIssuingCharge
-$query = " SELECT count(*) FROM accountlines";
-$sth = $dbh->prepare($query);
-$sth->execute;
-my $countaccount = $sth -> fetchrow_array;
-is ($countaccount,0,"0 accountline exists");
-is( C4::Circulation::AddIssuingCharge( $item_id1, $borrower_id1, 10 ),
-    1, "An issuing charge has been added" );
-my $account_id = $dbh->last_insert_id( undef, undef, 'accountlines', undef );
-$sth->execute;
-$countaccount = $sth -> fetchrow_array;
-is ($countaccount,1,"1 accountline has been added");
+$query = " SELECT * FROM accountlines";
+my $acc_sth = $dbh->prepare($query);
+$acc_sth->execute;
+my $account = $acc_sth -> fetchall_arrayref({});
+ok (scalar(@$account) == 1 && $account->[0]{accounttype} eq "Rent","accountline has been added")
+  or diag( Dumper($account) );
+
 
 #Test AddRenewal
 my $datedue3 =
@@ -256,6 +271,10 @@ like(
     qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/,
     "AddRenewal returns a date"
 );
+$acc_sth->execute;
+$account = $acc_sth -> fetchall_arrayref({});
+ok (scalar(@$account) == 2 && $account->[1]{accounttype} eq "Rent","another accountline has been added")
+  or diag( Dumper($account) );
 
 #Test GetBiblioIssues
 is( GetBiblioIssues(), undef, "GetBiblio Issues without parameters" );
-- 
2.7.4


More information about the Koha-patches mailing list