From 2b2beba3d861bc373a34f06cfe98f2feef8eb5e0 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 26 Oct 2018 18:34:35 +0100 Subject: [PATCH] Bug 21681: (follow-up) Add tests for Koha::Account->lines --- t/db_dependent/Koha/Account.t | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index 21f0e62191..ae79acef6c 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Koha::Account; use Koha::Account::Lines; @@ -192,3 +192,36 @@ subtest 'add_credit() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'lines() tests' => sub { + + plan tests => 1; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $account = $patron->account; + + my @generated_lines; + + # Add Credits + push @generated_lines, $account->add_credit({ amount => 1 }); + push @generated_lines, $account->add_credit({ amount => 2 }); + push @generated_lines, $account->add_credit({ amount => 3 }); + push @generated_lines, $account->add_credit({ amount => 4 }); + + # Add Debits + push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1 })->store; + push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2 })->store; + push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3 })->store; + push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4 })->store; + + # Paid Off + push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0 })->store; + push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0 })->store; + + my $lines = $account->lines; + is( $lines->_resultset->count, 10, "All accountlines (debits, credits and paid off) were fetched"); + + $schema->storage->txn_rollback; +}; -- 2.19.1