Bug 19066: Add tests for Koha::Account->pay

This patch adds tests for Koha::Account->pay, to make sure the
library_id param is used to set the branchcode attribute. The use of
userenv to set branchcode if library_id not passed is removed.
Responsability is left to the callers to pass library_id.

To test:
- Run:
  $ kshell
 k$ prove t/db_dependent/Koha/Account.t
=> SUCCESS: Tests pass!

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2018-11-08 11:15:25 -03:00 committed by Nick Clemens
parent 48dab3c126
commit faafdb53b7
3 changed files with 29 additions and 3 deletions

View File

@ -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} );

View File

@ -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 {

View File

@ -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;
@ -404,3 +405,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;
};