From 607754230ff41d05f372af223aab883efe5f0de2 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 28 Apr 2022 11:35:54 +0100 Subject: [PATCH] Bug 30275: Add unit tests for AddRenewal addition This patch adds a test for the AddRenewal addition that creates Renewal lines. Test plan 1) Run the unit tests and confirm it passes --- t/db_dependent/Circulation.t | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 83602d9bc9..7de31c8d02 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -18,7 +18,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 60; +use Test::More tests => 61; use Test::Exception; use Test::MockModule; use Test::Deep qw( cmp_deeply ); @@ -4361,6 +4361,34 @@ subtest 'AddRenewal and AddIssuingCharge tests' => sub { }; +subtest 'AddRenewal() adds to renewals' => sub { + plan tests => 4; + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $patron = $builder->build_object({ + class => 'Koha::Patrons', + value => { branchcode => $library->id } + }); + + my $item = $builder->build_sample_item(); + + set_userenv( $library->unblessed ); + + # Check the item out + my $issue = AddIssue( $patron->unblessed, $item->barcode ); + is(ref($issue), 'Koha::Checkout', 'Issue added'); + + # Renew item + my $duedate = AddRenewal( $patron->id, $item->id, $library->id ); + + ok( $duedate, "Renewal added" ); + + my $renewals = Koha::Checkouts::Renewals->search({ checkout_id => $issue->issue_id }); + is($renewals->count, 1, 'One renewal added'); + my $THE_renewal = $renewals->next; + is( $THE_renewal->renewer_id, C4::Context->userenv->{'number'}, 'Renewer recorded from context' ); +}; + subtest 'ProcessOfflinePayment() tests' => sub { plan tests => 4; -- 2.20.1