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

(-)a/t/db_dependent/Koha/Account.t (-1 / +86 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
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
subtest 'add_credit() tests' => sub {
33
34
    plan tests => 9;
35
36
    $schema->storage->txn_begin;
37
38
    # delete logs and statistics
39
    $schema->resultset('ActionLog')->search()->delete();
40
    $schema->resultset('Statistic')->search()->delete();
41
42
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
43
    my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } );
44
45
    is( $account->balance, 0, 'Patron has no balance' );
46
47
    # Disable logs
48
    t::lib::Mocks::mock_preference( 'FinesLog', 0 );
49
50
    my $line_1 = $account->add_credit(
51
        {   amount      => 25,
52
            description => 'Payment of 25',
53
            library_id  => $patron->branchcode,
54
            note        => 'not really important',
55
            user_id     => $patron->id
56
        }
57
    );
58
59
    is( $account->balance, -25, 'Patron has a balance of -25' );
60
    is( $schema->resultset('ActionLog')->count(), 0, 'No log was added' );
61
    is( $schema->resultset('Statistic')->count(), 1, 'Action added to statistics' );
62
    is( $line_1->accounttype, $Koha::Account::account_type->{'payment'}, 'Account type is correctly set' );
63
64
    # Enable logs
65
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
66
67
    my $sip_code = "1";
68
    my $line_2 = $account->add_credit(
69
        {   amount      => 37,
70
            description => 'Payment of 37',
71
            library_id  => $patron->branchcode,
72
            note        => 'not really important',
73
            user_id     => $patron->id,
74
            sip         => $sip_code
75
        }
76
    );
77
78
    is( $account->balance, -62, 'Patron has a balance of -25' );
79
    is( $schema->resultset('ActionLog')->count(), 1, 'Log was added' );
80
    is( $schema->resultset('Statistic')->count(), 2, 'Action added to statistics' );
81
    is( $line_2->accounttype, $Koha::Account::account_type->{'payment'} . $sip_code, 'Account type is correctly set' );
82
83
    $schema->storage->txn_rollback;
84
};
85
86
1;

Return to bug 20978