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

Return to bug 20978