From 6627096fb673cb74767686090c1191dc4a1b3ae8 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 26 Oct 2021 15:20:39 +0100 Subject: [PATCH] Bug 24609: Unit tests for Koha::Checkout->store This patch adds unit tests for the Koha::Item onloan trigger inside Koha::Checkout->store(); Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Checkout.t | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Checkout.t b/t/db_dependent/Koha/Checkout.t index f8288ea02a..ec8e198861 100755 --- a/t/db_dependent/Koha/Checkout.t +++ b/t/db_dependent/Koha/Checkout.t @@ -19,14 +19,40 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use t::lib::TestBuilder; use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); my $builder = t::lib::TestBuilder->new; my $schema = Koha::Database->new->schema; +subtest 'store() tests' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + my $checkout = $builder->build_object( + { + class => 'Koha::Checkouts' + } + ); + + my $new_due = dt_from_string()->add( days => 7 ); + + # Update date due for checkout + $checkout->date_due($new_due)->store(); + $checkout->discard_changes; + + is( dt_from_string($checkout->date_due), $new_due, "Checkout date_due updated" ); + + my $item = $checkout->item; + is( dt_from_string($item->onloan), $new_due->truncate( to => 'day' ), "Item->onloan update with date_due"); + + $schema->storage->txn_rollback; +}; + subtest 'library() tests' => sub { plan tests => 2; -- 2.20.1