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

(-)a/t/db_dependent/Koha/Account.t (-1 / +94 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2018 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use Koha::Account::Lines;
25
use Koha::Account::Offsets;
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
subtest 'add_credit() tests' => sub {
34
35
    plan tests => 13;
36
37
    $schema->storage->txn_begin;
38
39
    # delete logs and statistics
40
    $schema->resultset('ActionLog')->search()->delete();
41
    $schema->resultset('Statistic')->search()->delete();
42
43
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
44
    my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } );
45
46
    is( $account->balance, 0, 'Patron has no balance' );
47
48
    # Disable logs
49
    t::lib::Mocks::mock_preference( 'FinesLog', 0 );
50
51
    my $line_1 = $account->add_credit(
52
        {   amount      => 25,
53
            description => 'Payment of 25',
54
            library_id  => $patron->branchcode,
55
            note        => 'not really important',
56
            user_id     => $patron->id
57
        }
58
    );
59
60
    is( $account->balance, -25, 'Patron has a balance of -25' );
61
    is( $schema->resultset('ActionLog')->count(), 0, 'No log was added' );
62
    is( $schema->resultset('Statistic')->count(), 1, 'Action added to statistics' );
63
    is( $line_1->accounttype, $Koha::Account::account_type->{'payment'}, 'Account type is correctly set' );
64
65
    # Enable logs
66
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
67
68
    my $sip_code = "1";
69
    my $line_2 = $account->add_credit(
70
        {   amount      => 37,
71
            description => 'Payment of 37',
72
            library_id  => $patron->branchcode,
73
            note        => 'not really important',
74
            user_id     => $patron->id,
75
            sip         => $sip_code
76
        }
77
    );
78
79
    is( $account->balance, -62, 'Patron has a balance of -25' );
80
    is( $schema->resultset('ActionLog')->count(), 1, 'Log was added' );
81
    is( $schema->resultset('Statistic')->count(), 2, 'Action added to statistics' );
82
    is( $line_2->accounttype, $Koha::Account::account_type->{'payment'} . $sip_code, 'Account type is correctly set' );
83
84
    # offsets have the credit_id set to accountlines_id, and debit_id is undef
85
    my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next;
86
    my $offset_2 = Koha::Account::Offsets->search({ credit_id => $line_2->id })->next;
87
88
    is( $offset_1->credit_id, $line_1->id, 'No debit_id is set for credits' );
89
    is( $offset_1->debit_id, undef, 'No debit_id is set for credits' );
90
    is( $offset_2->credit_id, $line_2->id, 'No debit_id is set for credits' );
91
    is( $offset_2->debit_id, undef, 'No debit_id is set for credits' );
92
93
    $schema->storage->txn_rollback;
94
};

Return to bug 20978