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

(-)a/t/db_dependent/Koha/Account.t (-7 / +14 lines)
Lines 33-43 my $builder = t::lib::TestBuilder->new; Link Here
33
33
34
subtest 'outstanding_debits() tests' => sub {
34
subtest 'outstanding_debits() tests' => sub {
35
35
36
    plan tests => 13;
36
    plan tests => 22;
37
37
38
    $schema->storage->txn_begin;
38
    $schema->storage->txn_begin;
39
39
40
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
40
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
41
    my $account = $patron->account;
41
42
42
    my @generated_lines;
43
    my @generated_lines;
43
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
44
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
Lines 45-59 subtest 'outstanding_debits() tests' => sub { Link Here
45
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
46
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
46
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
47
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
47
48
48
    my $account = $patron->account;
49
    my $lines     = $account->outstanding_debits();
49
    my $lines   = $account->outstanding_debits();
50
    my @lines_arr = $account->outstanding_debits();
50
51
52
    is( ref($lines), 'Koha::Account::Lines', 'Called in scalar context, outstanding_debits returns a Koha::Account::Lines object' );
51
    is( $lines->total_outstanding, 10, 'Outstandig debits total is correctly calculated' );
53
    is( $lines->total_outstanding, 10, 'Outstandig debits total is correctly calculated' );
52
54
53
    my $i = 0;
55
    my $i = 0;
54
    foreach my $line ( @{ $lines->as_list } ) {
56
    foreach my $line ( @{ $lines->as_list } ) {
55
        my $fetched_line = Koha::Account::Lines->find( $generated_lines[$i]->id );
57
        my $fetched_line = Koha::Account::Lines->find( $generated_lines[$i]->id );
56
        is_deeply( $line->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" );
58
        is_deeply( $line->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" );
59
        is_deeply( $lines_arr[$i]->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" );
60
        is( ref($lines_arr[$i]), 'Koha::Account::Line', 'outstanding_debits returns a list of Koha::Account::Line objects in list context' );
57
        $i++;
61
        $i++;
58
    }
62
    }
59
63
Lines 91-97 subtest 'outstanding_debits() tests' => sub { Link Here
91
95
92
subtest 'outstanding_credits() tests' => sub {
96
subtest 'outstanding_credits() tests' => sub {
93
97
94
    plan tests => 8;
98
    plan tests => 17;
95
99
96
    $schema->storage->txn_begin;
100
    $schema->storage->txn_begin;
97
101
Lines 104-117 subtest 'outstanding_credits() tests' => sub { Link Here
104
    push @generated_lines, $account->add_credit({ amount => 3 });
108
    push @generated_lines, $account->add_credit({ amount => 3 });
105
    push @generated_lines, $account->add_credit({ amount => 4 });
109
    push @generated_lines, $account->add_credit({ amount => 4 });
106
110
107
    my $lines = $account->outstanding_credits();
111
    my $lines     = $account->outstanding_credits();
112
    my @lines_arr = $account->outstanding_credits();
108
113
114
    is( ref($lines), 'Koha::Account::Lines', 'Called in scalar context, outstanding_credits returns a Koha::Account::Lines object' );
109
    is( $lines->total_outstanding, -10, 'Outstandig credits total is correctly calculated' );
115
    is( $lines->total_outstanding, -10, 'Outstandig credits total is correctly calculated' );
110
116
111
    my $i = 0;
117
    my $i = 0;
112
    foreach my $line ( @{ $lines->as_list } ) {
118
    foreach my $line ( @{ $lines->as_list } ) {
113
        my $fetched_line = Koha::Account::Lines->find( $generated_lines[$i]->id );
119
        my $fetched_line = Koha::Account::Lines->find( $generated_lines[$i]->id );
114
        is_deeply( $line->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" );
120
        is_deeply( $line->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" );
121
        is_deeply( $lines_arr[$i]->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" );
122
        is( ref($lines_arr[$i]), 'Koha::Account::Line', 'outstanding_debits returns a list of Koha::Account::Line objects in list context' );
115
        $i++;
123
        $i++;
116
    }
124
    }
117
125
118
- 

Return to bug 21909