View | Details | Raw Unified | Return to bug 21401
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Account.t (-2 / +42 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
23
24
use Koha::Account;
24
use Koha::Account;
25
use Koha::Account::Lines;
25
use Koha::Account::Lines;
Lines 192-194 subtest 'add_credit() tests' => sub { Link Here
192
192
193
    $schema->storage->txn_rollback;
193
    $schema->storage->txn_rollback;
194
};
194
};
195
- 
195
196
subtest 'accountlines branchcode' => sub {
197
198
    plan tests => 3;
199
200
    $schema->storage->txn_begin;
201
202
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
203
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
204
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
205
206
    my $account = $patron->account;
207
    my $credit1 = $account->add_credit({
208
        amount      => 13,
209
        description => 'Payment of 13',
210
        note        => 'some note',
211
    });
212
    my $line1 = Koha::Account::Lines->find( $credit1->id );
213
    is($line1->branchcode, undef, "No branchcode without userenv and no library set");
214
215
    C4::Context->_new_userenv('my_session1');
216
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library1->branchcode, $library1->branchname, '', '', '');
217
    my $credit2 = $account->add_credit({
218
        amount      => 14,
219
        description => 'Payment of 14',
220
        note        => 'some note',
221
    });
222
    my $line2 = Koha::Account::Lines->find( $credit2->id );
223
    is($line2->branchcode, $library1->branchcode, "Branchcode should be taken from userenv");
224
225
    my $line3 = Koha::Account::Line->new({
226
        amount         => 15,
227
        accounttype    => 'Payment',
228
        branchcode     => $library2->branchcode,
229
        borrowernumber => $patron->id,
230
    })->store;
231
    my $line3_from_db = Koha::Account::Lines->find( $line3->id );
232
    is($line3_from_db->branchcode, $library2->branchcode, "Branchcode should be set when creating line with branchcode");
233
234
    $schema->storage->txn_rollback;
235
};

Return to bug 21401