|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 12; |
22 |
use Test::More tests => 13; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
| 25 |
|
25 |
|
|
Lines 1037-1040
subtest "reduce() tests" => sub {
Link Here
|
| 1037 |
$schema->storage->txn_rollback; |
1037 |
$schema->storage->txn_rollback; |
| 1038 |
}; |
1038 |
}; |
| 1039 |
|
1039 |
|
|
|
1040 |
subtest "cancel() tests" => sub { |
| 1041 |
plan tests => 9; |
| 1042 |
|
| 1043 |
$schema->storage->txn_begin; |
| 1044 |
|
| 1045 |
# Create a borrower |
| 1046 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
| 1047 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
| 1048 |
|
| 1049 |
my $borrower = Koha::Patron->new( { |
| 1050 |
cardnumber => 'dariahall', |
| 1051 |
surname => 'Hall', |
| 1052 |
firstname => 'Daria', |
| 1053 |
} ); |
| 1054 |
$borrower->categorycode( $categorycode ); |
| 1055 |
$borrower->branchcode( $branchcode ); |
| 1056 |
$borrower->store; |
| 1057 |
|
| 1058 |
t::lib::Mocks::mock_userenv({ branchcode => $branchcode, borrowernumber => $borrower->borrowernumber }); |
| 1059 |
|
| 1060 |
my $account = Koha::Account->new({ patron_id => $borrower->id }); |
| 1061 |
|
| 1062 |
my $line1 = Koha::Account::Line->new( |
| 1063 |
{ |
| 1064 |
borrowernumber => $borrower->borrowernumber, |
| 1065 |
amount => 10, |
| 1066 |
amountoutstanding => 10, |
| 1067 |
interface => 'commandline', |
| 1068 |
debit_type_code => 'OVERDUE', |
| 1069 |
} |
| 1070 |
)->store(); |
| 1071 |
my $line2 = Koha::Account::Line->new( |
| 1072 |
{ |
| 1073 |
borrowernumber => $borrower->borrowernumber, |
| 1074 |
amount => 20, |
| 1075 |
amountoutstanding => 20, |
| 1076 |
interface => 'commandline', |
| 1077 |
debit_type_code => 'OVERDUE', |
| 1078 |
} |
| 1079 |
)->store(); |
| 1080 |
|
| 1081 |
my $id = $account->pay({ |
| 1082 |
lines => [$line2], |
| 1083 |
amount => 5, |
| 1084 |
}); |
| 1085 |
|
| 1086 |
is( $account->balance(), 25, "Account balance is 25" ); |
| 1087 |
is( $line1->amountoutstanding+0, 10, 'First fee has amount outstanding of 10' ); |
| 1088 |
is( $line2->amountoutstanding+0, 15, 'Second fee has amount outstanding of 15' ); |
| 1089 |
|
| 1090 |
my $ret = $line1->cancel(); |
| 1091 |
is( ref($ret), 'Koha::Account::Line', 'Cancel returns the account line' ); |
| 1092 |
is( $account->balance(), 15, "Account balance is 15" ); |
| 1093 |
is( $line1->amount+0, 0, 'First fee has amount of 0' ); |
| 1094 |
is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' ); |
| 1095 |
|
| 1096 |
$ret = $line2->cancel(); |
| 1097 |
is ($ret, undef, 'cancel returns undef when line cannot be cancelled'); |
| 1098 |
|
| 1099 |
my $account_payment = Koha::Account::Lines->find($id); |
| 1100 |
$ret = $account_payment->cancel(); |
| 1101 |
is ($ret, undef, 'payment cannot be cancelled'); |
| 1102 |
|
| 1103 |
$schema->storage->txn_rollback; |
| 1104 |
}; |
| 1105 |
|
| 1040 |
1; |
1106 |
1; |
| 1041 |
- |
|
|