From de286e44a816dd16f817a049385f6860e1c5e72c Mon Sep 17 00:00:00 2001 From: Rafal Kopaczka Date: Fri, 28 Mar 2014 10:00:36 +0100 Subject: [PATCH] Bug 9481 (QA follow-up) - Add unit test for GetItemCharges in C4::Overdues. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Holger Meißner --- t/db_dependent/Overdues.t | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 t/db_dependent/Overdues.t diff --git a/t/db_dependent/Overdues.t b/t/db_dependent/Overdues.t new file mode 100644 index 0000000..43d290c --- /dev/null +++ b/t/db_dependent/Overdues.t @@ -0,0 +1,80 @@ +#!/usr/bin/perl + +use Modern::Perl; + +use C4::Members; +use C4::Biblio; +use C4::Items; + +use Test::More tests => 3; + +BEGIN { + use_ok('C4::Overdues'); +} + +my $dbh = C4::Context->dbh; + +# Start transaction +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +#Populate database +my $biblio = MARC::Record->new(); +my $title = 'Title to add'; + +$biblio->append_fields( + MARC::Field->new('100', ' ', ' ', a => 'Anonymous'), + MARC::Field->new('245', ' ', ' ', a => $title), +); +my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, ''); +my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( + { + homebranch => 'CPL', + holdingbranch => 'CPL', + barcode => 'T000001', + }, + $biblionumber +); +my ( $item_bibnum2, $item_bibitemnum2, $itemnumber2 ) = AddItem( + { + homebranch => 'CPL', + holdingbranch => 'CPL', + barcode => 'T000002', + }, + $biblionumber +); + +my $borrowernumber = AddMember( + firstname => 'my firstname', + surname => 'my surname', + categorycode => 'S', + branchcode => 'CPL', +); + +my $insertdb = q/ + INSERT INTO accountlines ( + borrowernumber, itemnumber, amount, + accounttype, amountoutstanding, timestamp ) + VALUES ( ?, ?, ?, ?, ?, CURRENT_TIMESTAMP )/; +my @data = ( + [$borrowernumber, $itemnumber, 123.50, 'F', 123.45], + [$borrowernumber, $itemnumber, 12.34, 'FU', 123.45], + [$borrowernumber, $itemnumber, 123.45, 'Rent', 12.34], + [$borrowernumber, $itemnumber, 567.89, 'F', 89.01], + [$borrowernumber, $itemnumber2, 543.21, 'F', 543.21], + ); + +my $sth = $dbh->prepare($insertdb); +foreach my $loop (@data) { + $sth->execute(@$loop); +} + +ok(GetItemCharges($itemnumber, $borrowernumber) == 348.25, "GetItemCharges returns all outstanding charges for item"); + +my $anotheritemnumber = $itemnumber + 999999; +my $anotherborrowernumber = $borrowernumber + 999999; +ok(GetItemCharges($anotheritemnumber, $anotherborrowernumber) == 0, "There's no charges for item"); + + +$dbh->rollback; + -- 1.7.10.4