From 7cdf9741818e9bb132b3235e2278554d09ae2ada Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 1 Oct 2024 16:45:07 +0100 Subject: [PATCH] Bug 17976: Unit tests Add unit tests for the newly introduced overdue fines relation accessor. Signed-off-by: Emily Lamancusa --- t/db_dependent/Koha/Checkout.t | 57 +++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Checkout.t b/t/db_dependent/Koha/Checkout.t index 7459cbcbf8..5effd76a69 100755 --- a/t/db_dependent/Koha/Checkout.t +++ b/t/db_dependent/Koha/Checkout.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use t::lib::TestBuilder; use Koha::Database; @@ -27,6 +27,61 @@ use Koha::Database; my $builder = t::lib::TestBuilder->new; my $schema = Koha::Database->new->schema; +subtest 'overdue_fines' => sub { + plan tests => 4; + + my $checkout = $builder->build_object( + { + class => 'Koha::Checkouts', + } + ); + + my $overdueline = Koha::Account::Line->new( + { + issue_id => $checkout->id, + borrowernumber => $checkout->borrowernumber, + itemnumber => $checkout->itemnumber, + branchcode => $checkout->branchcode, + date => \'NOW()', + debit_type_code => 'OVERDUE', + status => 'UNRETURNED', + interface => 'cli', + amount => '1', + amountoutstanding => '1', + } + )->store(); + + my $accountline = Koha::Account::Line->new( + { + issue_id => $checkout->id, + borrowernumber => $checkout->borrowernumber, + itemnumber => $checkout->itemnumber, + branchcode => $checkout->branchcode, + date => \'NOW()', + debit_type_code => 'LOST', + status => '', + interface => 'cli', + amount => '1', + amountoutstanding => '1', + } + )->store(); + + my $overdue_fines = $checkout->overdue_fines; + is( ref($overdue_fines), 'Koha::Account::Lines', + 'Koha::Checkout->overdue_fines should return a Koha::Account::Lines' ); + is( $overdue_fines->count, 1, "Koha::Checkout->overdue_fines returns only overdue fines"); + + my $overdue = $overdue_fines->next; + is( ref($overdue), 'Koha::Account::Line', + 'next returns a Koha::Account::Line' ); + + is( + $overdueline->id, + $overdue->id, + 'Koha::Checkout->overdue_fines should return the correct overdue_fines' + ); +}; + subtest 'library() tests' => sub { plan tests => 2; -- 2.34.1