Lines 1084-1128
subtest "cancel() tests" => sub {
Link Here
|
1084 |
|
1084 |
|
1085 |
$schema->storage->txn_begin; |
1085 |
$schema->storage->txn_begin; |
1086 |
|
1086 |
|
1087 |
# Create a borrower |
1087 |
my $library = $builder->build_object( { class => 'Koha::Libraries' }); |
1088 |
my $categorycode = |
1088 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->branchcode } }); |
1089 |
$builder->build( { source => 'Category' } )->{categorycode}; |
1089 |
my $staff = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->branchcode } }); |
1090 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
|
|
1091 |
|
1092 |
my $borrower = Koha::Patron->new( |
1093 |
{ |
1094 |
cardnumber => 'dariahall', |
1095 |
surname => 'Hall', |
1096 |
firstname => 'Daria', |
1097 |
} |
1098 |
); |
1099 |
$borrower->categorycode($categorycode); |
1100 |
$borrower->branchcode($branchcode); |
1101 |
$borrower->store; |
1102 |
|
1103 |
my $staff = Koha::Patron->new( |
1104 |
{ |
1105 |
cardnumber => 'bobby', |
1106 |
surname => 'Bloggs', |
1107 |
firstname => 'Bobby', |
1108 |
} |
1109 |
); |
1110 |
$staff->categorycode($categorycode); |
1111 |
$staff->branchcode($branchcode); |
1112 |
$staff->store; |
1113 |
|
1090 |
|
1114 |
t::lib::Mocks::mock_userenv( |
1091 |
t::lib::Mocks::mock_userenv({ patron => $patron }); |
1115 |
{ |
|
|
1116 |
branchcode => $branchcode, |
1117 |
borrowernumber => $borrower->borrowernumber |
1118 |
} |
1119 |
); |
1120 |
|
1092 |
|
1121 |
my $account = Koha::Account->new( { patron_id => $borrower->id } ); |
1093 |
my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } ); |
1122 |
|
1094 |
|
1123 |
my $debit1 = Koha::Account::Line->new( |
1095 |
my $debit1 = Koha::Account::Line->new( |
1124 |
{ |
1096 |
{ |
1125 |
borrowernumber => $borrower->borrowernumber, |
1097 |
borrowernumber => $patron->borrowernumber, |
1126 |
amount => 10, |
1098 |
amount => 10, |
1127 |
amountoutstanding => 10, |
1099 |
amountoutstanding => 10, |
1128 |
interface => 'commandline', |
1100 |
interface => 'commandline', |
Lines 1131-1137
subtest "cancel() tests" => sub {
Link Here
|
1131 |
)->store(); |
1103 |
)->store(); |
1132 |
my $debit2 = Koha::Account::Line->new( |
1104 |
my $debit2 = Koha::Account::Line->new( |
1133 |
{ |
1105 |
{ |
1134 |
borrowernumber => $borrower->borrowernumber, |
1106 |
borrowernumber => $patron->borrowernumber, |
1135 |
amount => 20, |
1107 |
amount => 20, |
1136 |
amountoutstanding => 20, |
1108 |
amountoutstanding => 20, |
1137 |
interface => 'commandline', |
1109 |
interface => 'commandline', |
Lines 1154-1160
subtest "cancel() tests" => sub {
Link Here
|
1154 |
15, 'Second fee has amount outstanding of 15' ); |
1126 |
15, 'Second fee has amount outstanding of 15' ); |
1155 |
throws_ok { |
1127 |
throws_ok { |
1156 |
$credit->cancel( |
1128 |
$credit->cancel( |
1157 |
{ staff_id => $staff->borrowernumber, branch => $branchcode } ); |
1129 |
{ staff_id => $staff->borrowernumber, branch => $library->branchcode } ); |
1158 |
} |
1130 |
} |
1159 |
'Koha::Exceptions::Account::IsNotDebit', |
1131 |
'Koha::Exceptions::Account::IsNotDebit', |
1160 |
'->cancel() can only be used with debits'; |
1132 |
'->cancel() can only be used with debits'; |
Lines 1165-1184
subtest "cancel() tests" => sub {
Link Here
|
1165 |
'Koha::Exceptions::MissingParameter', |
1137 |
'Koha::Exceptions::MissingParameter', |
1166 |
"->cancel() requires the `branch` parameter is passed"; |
1138 |
"->cancel() requires the `branch` parameter is passed"; |
1167 |
throws_ok { |
1139 |
throws_ok { |
1168 |
$debit1->reduce( { branch => $branchcode } ); |
1140 |
$debit1->reduce( { branch => $library->branchcode } ); |
1169 |
} |
1141 |
} |
1170 |
'Koha::Exceptions::MissingParameter', |
1142 |
'Koha::Exceptions::MissingParameter', |
1171 |
"->cancel() requires the `staff_id` parameter is passed"; |
1143 |
"->cancel() requires the `staff_id` parameter is passed"; |
1172 |
|
1144 |
|
1173 |
throws_ok { |
1145 |
throws_ok { |
1174 |
$debit2->cancel( |
1146 |
$debit2->cancel( |
1175 |
{ staff_id => $staff->borrowernumber, branch => $branchcode } ); |
1147 |
{ staff_id => $staff->borrowernumber, branch => $library->branchcode } ); |
1176 |
} |
1148 |
} |
1177 |
'Koha::Exceptions::Account', |
1149 |
'Koha::Exceptions::Account', |
1178 |
'->cancel() can only be used with debits that have not been offset'; |
1150 |
'->cancel() can only be used with debits that have not been offset'; |
1179 |
|
1151 |
|
1180 |
my $cancellation = $debit1->cancel( |
1152 |
my $cancellation = $debit1->cancel( |
1181 |
{ staff_id => $staff->borrowernumber, branch => $branchcode } ); |
1153 |
{ staff_id => $staff->borrowernumber, branch => $library->branchcode } ); |
1182 |
is( ref($cancellation), 'Koha::Account::Line', |
1154 |
is( ref($cancellation), 'Koha::Account::Line', |
1183 |
'Cancel returns an account line' ); |
1155 |
'Cancel returns an account line' ); |
1184 |
is( |
1156 |
is( |
1185 |
- |
|
|