@@ -, +, @@ makepartialpayment() WriteOffFee() --- t/db_dependent/Accounts.t | 79 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 7 deletions(-) mode change 100644 => 100755 t/db_dependent/Accounts.t --- a/t/db_dependent/Accounts.t +++ a/t/db_dependent/Accounts.t @@ -1,16 +1,81 @@ #!/usr/bin/perl -# -# This Koha test module is a stub! -# Add more tests here!!! - use strict; use warnings; - -use Test::More tests => 1; +use Test::More tests => 9; +use Test::MockModule; +use DBD::Mock; +use C4::Accounts; BEGIN { - use_ok('C4::Accounts'); + use_ok('C4::Accounts'); } +my $dbh = C4::Context->dbh; +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +my $FinesLogPref = C4::Context->preference("FinesLog"); +C4::Context->set_preference("FinesLog", 0); +# BUG 11373 - Subs to test +#makepartialpayment($accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note) +#WriteOffFee($borrowernumber, $accountlines_id, $itemnum, $accounttype, $amoutn, $branch, $payment_note) + +# Creating an outstanding fee +my $borrowernumber = 123456789; +my $accountno = 1; +my $accountlines_id = 1234; +my $categorycode = 'ZYX'; +my $branchcode = 'XYZ'; + +my $insertcategory="INSERT INTO categories (categorycode, description, enrolmentperiod, upperagelimit, dateofbirthrequired,". + "finetype, bulk, enrolmentfee, overduenoticerequired, issuelimit, reservefee, category_type)". + "VALUES (?,'Placeholder',99,999,18,NULL,NULL,'0.000000',0,NULL,'0.000000',?)"; + +my $insertbranch="INSERT INTO branches ( branchcode, branchname, branchaddress1) VALUES (?,'Placeholder','Placeholder')"; + +my $insertborrower='insert into borrowers (borrowernumber, categorycode, branchcode, cardnumber,'. + 'surname, dateenrolled, dateexpiry, flags, userid, password, privacy, email)'. + 'values (?, ?, ?, "123456789", "UnitTester", "2001-01-01", "2099-01-01", 1, "userid", "pa$$word", 1, "ph@pholder.com")'; + +my $insertfee = 'INSERT INTO accountlines (accountlines_id, borrowernumber, accountno, date, amount, amountoutstanding) ' + . ' VALUES (?, ?, ?, NOW(), ?, ?)'; + +print "\nTesting makepartialpayment\nCreating an outstanding fee of \$5 for testing purposes\n"; +$dbh->do($insertbranch, undef, $branchcode); +$dbh->do($insertcategory, undef, $categorycode, 'S'); +$dbh->do($insertborrower, undef, $borrowernumber, $categorycode, $branchcode); +$dbh->do($insertfee, undef, $accountlines_id, $borrowernumber, $accountno, 0, 5); + +print "Making a partial payment of \$3\n"; +makepartialpayment($accountlines_id, $borrowernumber, $accountno, 3, 'user', $branchcode, 'Testing'); + +my $statement = $dbh->prepare('SELECT * from accountlines where borrowernumber = ?'); +$statement->execute($borrowernumber); +my $result = $statement->fetchall_hashref('accountno'); + +is(scalar(keys(%$result)), 2, 'A new entry is added in accountlines'); +is($result->{2}->{'accounttype'}, 'Pay', 'The new entry is a payment'); +is($result->{2}->{'amount'}*1, -3, 'Amount paid is -3'); +is($result->{1}->{'amountoutstanding'}*1, 2, 'Amount outstanding is 2'); + +$dbh->rollback; # Making sure the two test sets are independant. + +print "\nTesting WriteOffFee\nCreating an outstanding fee of \$10 for testing purposes\n"; +$dbh->do($insertbranch, undef, $branchcode); +$dbh->do($insertcategory, undef, $categorycode, 'S'); +$dbh->do($insertborrower, undef, $borrowernumber, $categorycode, $branchcode); +$dbh->do($insertfee, undef, $accountlines_id, $borrowernumber, $accountno, 0, 10); + +print "Writing off the fee (10)\n"; +WriteOffFee($borrowernumber, $accountlines_id, undef, 'wut', 10, $branchcode, 'Testing'); +$statement = $dbh->prepare('SELECT * from accountlines where borrowernumber = ?'); +$statement->execute($borrowernumber); +$result = $statement->fetchall_hashref('accountno'); +is(scalar(keys(%$result)), 2, 'A new entry is added in accountlines'); +is($result->{2}->{'accounttype'}, 'W', 'The new entry is a writeoff'); +is($result->{2}->{'amount'}*1, -10, 'Amount paid is -10'); +is($result->{1}->{'amountoutstanding'}*1, 0, 'Amount outstanding is 0'); +$dbh->rollback; +C4::Context->set_preference("FinesLog", $FinesLogPref); --