From 7447c93282e02a5c82c2c16aba23ca09c4a3c752 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 Signed-off-by: Kyle M Hall --- 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 7459cbcbf8a..5effd76a692 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.39.5 (Apple Git-154)