|
Lines 1-16
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
# |
|
|
| 3 |
# This Koha test module is a stub! |
| 4 |
# Add more tests here!!! |
| 5 |
|
| 6 |
use strict; |
2 |
use strict; |
| 7 |
use warnings; |
3 |
use warnings; |
| 8 |
|
4 |
use Test::More tests => 9; |
| 9 |
use Test::More tests => 1; |
5 |
use Test::MockModule; |
|
|
6 |
use DBD::Mock; |
| 7 |
use C4::Accounts; |
| 10 |
|
8 |
|
| 11 |
BEGIN { |
9 |
BEGIN { |
| 12 |
use_ok('C4::Accounts'); |
10 |
use_ok('C4::Accounts'); |
| 13 |
} |
11 |
} |
|
|
12 |
my $dbh = C4::Context->dbh; |
| 13 |
$dbh->{AutoCommit} = 0; |
| 14 |
$dbh->{RaiseError} = 1; |
| 15 |
|
| 16 |
my $FinesLogPref = C4::Context->preference("FinesLog"); |
| 17 |
C4::Context->set_preference("FinesLog", 0); |
| 18 |
# BUG 11373 - Subs to test |
| 19 |
#makepartialpayment($accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note) |
| 20 |
#WriteOffFee($borrowernumber, $accountlines_id, $itemnum, $accounttype, $amoutn, $branch, $payment_note) |
| 21 |
|
| 22 |
# Creating an outstanding fee |
| 23 |
my $borrowernumber = 123456789; |
| 24 |
my $accountno = 1; |
| 25 |
my $accountlines_id = 1234; |
| 26 |
my $categorycode = 'ZYX'; |
| 27 |
my $branchcode = 'XYZ'; |
| 28 |
|
| 29 |
my $insertcategory="INSERT INTO categories (categorycode, description, enrolmentperiod, upperagelimit, dateofbirthrequired,". |
| 30 |
"finetype, bulk, enrolmentfee, overduenoticerequired, issuelimit, reservefee, category_type)". |
| 31 |
"VALUES (?,'Placeholder',99,999,18,NULL,NULL,'0.000000',0,NULL,'0.000000',?)"; |
| 32 |
|
| 33 |
my $insertbranch="INSERT INTO branches ( branchcode, branchname, branchaddress1) VALUES (?,'Placeholder','Placeholder')"; |
| 34 |
|
| 35 |
my $insertborrower='insert into borrowers (borrowernumber, categorycode, branchcode, cardnumber,'. |
| 36 |
'surname, dateenrolled, dateexpiry, flags, userid, password, privacy, email)'. |
| 37 |
'values (?, ?, ?, "123456789", "UnitTester", "2001-01-01", "2099-01-01", 1, "userid", "pa$$word", 1, "ph@pholder.com")'; |
| 38 |
|
| 39 |
my $insertfee = 'INSERT INTO accountlines (accountlines_id, borrowernumber, accountno, date, amount, amountoutstanding) ' |
| 40 |
. ' VALUES (?, ?, ?, NOW(), ?, ?)'; |
| 41 |
|
| 42 |
print "\nTesting makepartialpayment\nCreating an outstanding fee of \$5 for testing purposes\n"; |
| 43 |
$dbh->do($insertbranch, undef, $branchcode); |
| 44 |
$dbh->do($insertcategory, undef, $categorycode, 'S'); |
| 45 |
$dbh->do($insertborrower, undef, $borrowernumber, $categorycode, $branchcode); |
| 46 |
$dbh->do($insertfee, undef, $accountlines_id, $borrowernumber, $accountno, 0, 5); |
| 47 |
|
| 48 |
print "Making a partial payment of \$3\n"; |
| 49 |
makepartialpayment($accountlines_id, $borrowernumber, $accountno, 3, 'user', $branchcode, 'Testing'); |
| 50 |
|
| 51 |
my $statement = $dbh->prepare('SELECT * from accountlines where borrowernumber = ?'); |
| 52 |
$statement->execute($borrowernumber); |
| 53 |
my $result = $statement->fetchall_hashref('accountno'); |
| 54 |
|
| 55 |
is(scalar(keys(%$result)), 2, 'A new entry is added in accountlines'); |
| 56 |
is($result->{2}->{'accounttype'}, 'Pay', 'The new entry is a payment'); |
| 57 |
is($result->{2}->{'amount'}*1, -3, 'Amount paid is -3'); |
| 58 |
is($result->{1}->{'amountoutstanding'}*1, 2, 'Amount outstanding is 2'); |
| 59 |
|
| 60 |
$dbh->rollback; # Making sure the two test sets are independant. |
| 61 |
|
| 62 |
print "\nTesting WriteOffFee\nCreating an outstanding fee of \$10 for testing purposes\n"; |
| 63 |
$dbh->do($insertbranch, undef, $branchcode); |
| 64 |
$dbh->do($insertcategory, undef, $categorycode, 'S'); |
| 65 |
$dbh->do($insertborrower, undef, $borrowernumber, $categorycode, $branchcode); |
| 66 |
$dbh->do($insertfee, undef, $accountlines_id, $borrowernumber, $accountno, 0, 10); |
| 67 |
|
| 68 |
print "Writing off the fee (10)\n"; |
| 69 |
WriteOffFee($borrowernumber, $accountlines_id, undef, 'wut', 10, $branchcode, 'Testing'); |
| 14 |
|
70 |
|
|
|
71 |
$statement = $dbh->prepare('SELECT * from accountlines where borrowernumber = ?'); |
| 72 |
$statement->execute($borrowernumber); |
| 73 |
$result = $statement->fetchall_hashref('accountno'); |
| 15 |
|
74 |
|
|
|
75 |
is(scalar(keys(%$result)), 2, 'A new entry is added in accountlines'); |
| 76 |
is($result->{2}->{'accounttype'}, 'W', 'The new entry is a writeoff'); |
| 77 |
is($result->{2}->{'amount'}*1, -10, 'Amount paid is -10'); |
| 78 |
is($result->{1}->{'amountoutstanding'}*1, 0, 'Amount outstanding is 0'); |
| 16 |
|
79 |
|
| 17 |
- |
80 |
$dbh->rollback; |
|
|
81 |
C4::Context->set_preference("FinesLog", $FinesLogPref); |