3 # Copyright 2018 Koha Development team
5 # This file is part of Koha
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.
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.
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>
22 use Test::More tests => 1;
25 use Koha::Account::Lines;
27 use t::lib::TestBuilder;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 subtest 'outstanding_debits() tests' => sub {
36 $schema->storage->txn_begin;
38 my $patron = $builder->build_object({ class => 'Koha::Patrons' });
41 push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1 })->store;
42 push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2 })->store;
43 push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3 })->store;
44 push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4 })->store;
46 my $account = Koha::Account->new({ patron_id => $patron->id });
47 my ( $total, $lines ) = $account->outstanding_debits();
49 is( $total, 10, 'Outstandig debits total is correctly calculated' );
52 foreach my $line ( @{ $lines->as_list } ) {
53 my $fetched_line = Koha::Account::Lines->find( $generated_lines[$i]->id );
54 is_deeply( $line->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" );
58 ( $total, $lines ) = Koha::Account->new({ patron_id => 'InvalidBorrowernumber' })->outstanding_debits();
59 is( $total, 0, "Total if no outstanding debits is 0" );
60 is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" );
63 $schema->storage->txn_rollback;