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

(-)a/t/db_dependent/Koha/Account.t (-2 / +66 lines)
Lines 19-29 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 2;
23
23
24
use Koha::Account;
24
use Koha::Account;
25
use Koha::Account::Lines;
25
use Koha::Account::Lines;
26
use Koha::Account::Offsets;
26
27
28
use t::lib::Mocks;
27
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
28
30
29
my $schema  = Koha::Database->new->schema;
31
my $schema  = Koha::Database->new->schema;
Lines 80-82 subtest 'outstanding_debits() tests' => sub { Link Here
80
82
81
    $schema->storage->txn_rollback;
83
    $schema->storage->txn_rollback;
82
};
84
};
83
- 
85
86
subtest 'add_credit() tests' => sub {
87
88
    plan tests => 13;
89
90
    $schema->storage->txn_begin;
91
92
    # delete logs and statistics
93
    $schema->resultset('ActionLog')->search()->delete();
94
    $schema->resultset('Statistic')->search()->delete();
95
96
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
97
    my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } );
98
99
    is( $account->balance, 0, 'Patron has no balance' );
100
101
    # Disable logs
102
    t::lib::Mocks::mock_preference( 'FinesLog', 0 );
103
104
    my $line_1 = $account->add_credit(
105
        {   amount      => 25,
106
            description => 'Payment of 25',
107
            library_id  => $patron->branchcode,
108
            note        => 'not really important',
109
            user_id     => $patron->id
110
        }
111
    );
112
113
    is( $account->balance, -25, 'Patron has a balance of -25' );
114
    is( $schema->resultset('ActionLog')->count(), 0, 'No log was added' );
115
    is( $schema->resultset('Statistic')->count(), 1, 'Action added to statistics' );
116
    is( $line_1->accounttype, $Koha::Account::account_type->{'payment'}, 'Account type is correctly set' );
117
118
    # Enable logs
119
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
120
121
    my $sip_code = "1";
122
    my $line_2 = $account->add_credit(
123
        {   amount      => 37,
124
            description => 'Payment of 37',
125
            library_id  => $patron->branchcode,
126
            note        => 'not really important',
127
            user_id     => $patron->id,
128
            sip         => $sip_code
129
        }
130
    );
131
132
    is( $account->balance, -62, 'Patron has a balance of -25' );
133
    is( $schema->resultset('ActionLog')->count(), 1, 'Log was added' );
134
    is( $schema->resultset('Statistic')->count(), 2, 'Action added to statistics' );
135
    is( $line_2->accounttype, $Koha::Account::account_type->{'payment'} . $sip_code, 'Account type is correctly set' );
136
137
    # offsets have the credit_id set to accountlines_id, and debit_id is undef
138
    my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next;
139
    my $offset_2 = Koha::Account::Offsets->search({ credit_id => $line_2->id })->next;
140
141
    is( $offset_1->credit_id, $line_1->id, 'No debit_id is set for credits' );
142
    is( $offset_1->debit_id, undef, 'No debit_id is set for credits' );
143
    is( $offset_2->credit_id, $line_2->id, 'No debit_id is set for credits' );
144
    is( $offset_2->debit_id, undef, 'No debit_id is set for credits' );
145
146
    $schema->storage->txn_rollback;
147
};

Return to bug 20978