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 57-59 subtest 'outstanding_debits() tests' => sub { Link Here
57
59
58
    $schema->storage->txn_rollback;
60
    $schema->storage->txn_rollback;
59
};
61
};
60
- 
62
63
subtest 'add_credit() tests' => sub {
64
65
    plan tests => 13;
66
67
    $schema->storage->txn_begin;
68
69
    # delete logs and statistics
70
    $schema->resultset('ActionLog')->search()->delete();
71
    $schema->resultset('Statistic')->search()->delete();
72
73
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
74
    my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } );
75
76
    is( $account->balance, 0, 'Patron has no balance' );
77
78
    # Disable logs
79
    t::lib::Mocks::mock_preference( 'FinesLog', 0 );
80
81
    my $line_1 = $account->add_credit(
82
        {   amount      => 25,
83
            description => 'Payment of 25',
84
            library_id  => $patron->branchcode,
85
            note        => 'not really important',
86
            user_id     => $patron->id
87
        }
88
    );
89
90
    is( $account->balance, -25, 'Patron has a balance of -25' );
91
    is( $schema->resultset('ActionLog')->count(), 0, 'No log was added' );
92
    is( $schema->resultset('Statistic')->count(), 1, 'Action added to statistics' );
93
    is( $line_1->accounttype, $Koha::Account::account_type->{'payment'}, 'Account type is correctly set' );
94
95
    # Enable logs
96
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
97
98
    my $sip_code = "1";
99
    my $line_2 = $account->add_credit(
100
        {   amount      => 37,
101
            description => 'Payment of 37',
102
            library_id  => $patron->branchcode,
103
            note        => 'not really important',
104
            user_id     => $patron->id,
105
            sip         => $sip_code
106
        }
107
    );
108
109
    is( $account->balance, -62, 'Patron has a balance of -25' );
110
    is( $schema->resultset('ActionLog')->count(), 1, 'Log was added' );
111
    is( $schema->resultset('Statistic')->count(), 2, 'Action added to statistics' );
112
    is( $line_2->accounttype, $Koha::Account::account_type->{'payment'} . $sip_code, 'Account type is correctly set' );
113
114
    # offsets have the credit_id set to accountlines_id, and debit_id is undef
115
    my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next;
116
    my $offset_2 = Koha::Account::Offsets->search({ credit_id => $line_2->id })->next;
117
118
    is( $offset_1->credit_id, $line_1->id, 'No debit_id is set for credits' );
119
    is( $offset_1->debit_id, undef, 'No debit_id is set for credits' );
120
    is( $offset_2->credit_id, $line_2->id, 'No debit_id is set for credits' );
121
    is( $offset_2->debit_id, undef, 'No debit_id is set for credits' );
122
123
    $schema->storage->txn_rollback;
124
};

Return to bug 20978