@@ -, +, @@ - Run: $ kshell k$ prove t/db_dependent/Koha/Account.t --- Koha/Account.pm | 1 - t/db_dependent/Accounts.t | 2 +- t/db_dependent/Koha/Account.t | 29 ++++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) --- a/Koha/Account.pm +++ a/Koha/Account.pm @@ -81,7 +81,6 @@ sub pay { my $offset_type = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment'; my $userenv = C4::Context->userenv; - $library_id ||= $userenv ? $userenv->{branch} : undef; my $patron = Koha::Patrons->find( $self->{patron_id} ); --- a/t/db_dependent/Accounts.t +++ a/t/db_dependent/Accounts.t @@ -292,7 +292,7 @@ subtest "Koha::Account::pay tests" => sub { is( $payment->amount(), '-42.000000', "Payment paid the specified fine" ); $line3 = Koha::Account::Lines->find( $line3->id ); is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" ); - is( $payment->branchcode, $userenv_branchcode, 'Branchcode set correctly' ); + is( $payment->branchcode, undef, 'branchcode passed, then undef' ); }; subtest "Koha::Account::pay particular line tests" => sub { --- a/t/db_dependent/Koha/Account.t +++ a/t/db_dependent/Koha/Account.t @@ -19,7 +19,8 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; +use Test::MockModule; use Koha::Account; use Koha::Account::Lines; @@ -396,3 +397,29 @@ subtest 'reconcile_balance' => sub { $schema->storage->txn_rollback; }; }; + +subtest 'pay() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $account = $patron->account; + + my $context = Test::MockModule->new('C4::Context'); + $context->mock( 'userenv', { branch => $library->id } ); + + my $credit_1_id = $account->pay({ amount => 200 }); + my $credit_1 = Koha::Account::Lines->find( $credit_1_id ); + + is( $credit_1->branchcode, undef, 'No branchcode is set if library_id was not passed' ); + + my $credit_2_id = $account->pay({ amount => 150, library_id => $library->id }); + my $credit_2 = Koha::Account::Lines->find( $credit_2_id ); + + is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' ); + + $schema->storage->txn_rollback; +}; --