From 893a4f84e6676ab4e1cbb13ddf526d671d87614b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Dec 2021 16:03:46 +0100 Subject: [PATCH] Bug 21729: Add tests Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Holds.t | 107 +++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t index 51c3383277..d3cafc8b1c 100755 --- a/t/db_dependent/Koha/Holds.t +++ b/t/db_dependent/Koha/Holds.t @@ -19,13 +19,14 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use Test::Warn; use C4::Circulation qw( AddIssue ); use C4::Reserves qw( AddReserve ModReserve ModReserveCancelAll ); use Koha::AuthorisedValueCategory; use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); use Koha::Holds; use t::lib::Mocks; @@ -500,6 +501,110 @@ subtest 'get_items_that_can_fill' => sub { }; +subtest 'set_waiting+patron_expiration_date' => sub { + plan tests => 2; + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + + my $item = + $builder->build_sample_item( { library => $library->branchcode } ); + my $manager = $builder->build_object( { class => "Koha::Patrons" } ); + t::lib::Mocks::mock_userenv( + { patron => $manager, branchcode => $manager->branchcode } ); + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { branchcode => $library->branchcode, } + } + ); + + subtest 'patron_expiration_date < expiration_date' => sub { + plan tests => 6; + t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 5 ); + my $patron_expiration_date = dt_from_string->add( days => 3 )->ymd; + my $reserve_id = C4::Reserves::AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item->biblionumber, + priority => 1, + itemnumber => $item->itemnumber, + expiration_date => $patron_expiration_date, + } + ); + + my $hold = Koha::Holds->find($reserve_id); + + is( + $hold->expirationdate, + $patron_expiration_date, + 'expiration date set to patron expiration date' + ); + is( + $hold->patron_expiration_date, $patron_expiration_date, + 'patron expiration date correctly set' + ); + + $hold->set_waiting; + + $hold = $hold->get_from_storage; + is( $hold->expirationdate, $patron_expiration_date ); + is( $hold->patron_expiration_date, $patron_expiration_date ); + + C4::Reserves::RevertWaitingStatus( + { itemnumber => $item->itemnumber } + ); + + $hold = $hold->get_from_storage; + is( $hold->expirationdate, $patron_expiration_date ); + is( $hold->patron_expiration_date, $patron_expiration_date ); + }; + + subtest 'patron_expiration_date > expiration_date' => sub { + plan tests => 6; + t::lib::Mocks::mock_preference( 'ReservesMaxPickUpDelay', 5 ); + my $new_expiration_date = dt_from_string->add( days => 5 )->ymd; + my $patron_expiration_date = dt_from_string->add( days => 6 )->ymd; + my $reserve_id = C4::Reserves::AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item->biblionumber, + priority => 1, + itemnumber => $item->itemnumber, + expiration_date => $patron_expiration_date, + } + ); + + my $hold = Koha::Holds->find($reserve_id); + + is( + $hold->expirationdate, + $patron_expiration_date, + 'expiration date set to patron expiration date' + ); + is( + $hold->patron_expiration_date, $patron_expiration_date, + 'patron expiration date correctly set' + ); + + $hold->set_waiting; + + $hold = $hold->get_from_storage; + is( $hold->expirationdate, $new_expiration_date ); + is( $hold->patron_expiration_date, $patron_expiration_date ); + + C4::Reserves::RevertWaitingStatus( + { itemnumber => $item->itemnumber } + ); + + $hold = $hold->get_from_storage; + is( $hold->expirationdate, $patron_expiration_date ); + is( $hold->patron_expiration_date, $patron_expiration_date ); + }; +}; + + $schema->storage->txn_rollback; 1; -- 2.20.1