From 7dfd5a74bc8d76c5e07622d5680f846fc6de3eaa Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 13 Apr 2022 08:52:02 +0100 Subject: [PATCH] Bug 30518: Unit test This patch adds tests for checking the needs_advancing method against a timezone and datetime that would cause an Invalid local time failure To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/StockRotationItems.t => FAIL: The feature is not implemented, tests fail to complete Signed-off-by: Nick Clemens Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall (cherry picked from commit 4450ad21100a02055e3f0f05918b2d4b17852107) Signed-off-by: Andrew Fuerste-Henry (cherry picked from commit b8c1391c4a7e23d6c1de25bd03b95612c8f99de8) Signed-off-by: Victor Grousset/tuxayo --- t/db_dependent/StockRotationItems.t | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/StockRotationItems.t b/t/db_dependent/StockRotationItems.t index 49da2cc304..0f69edb7b7 100755 --- a/t/db_dependent/StockRotationItems.t +++ b/t/db_dependent/StockRotationItems.t @@ -22,9 +22,12 @@ use Modern::Perl; use DateTime; use DateTime::Duration; use Koha::Database; +use Koha::DateUtils qw(dt_from_string); use Koha::Item::Transfer; -use t::lib::TestBuilder; + use Test::Warn; +use t::lib::Mocks; +use t::lib::TestBuilder; use Test::More tests => 8; @@ -160,7 +163,7 @@ subtest "Tests for repatriate." => sub { }; subtest "Tests for needs_advancing." => sub { - plan tests => 7; + plan tests => 8; $schema->storage->txn_begin; # Test behaviour of item freshly added to rota. @@ -224,6 +227,21 @@ subtest "Tests for needs_advancing." => sub { DateTime->now - DateTime::Duration->new( days => 75 ) )->store; is($dbitem->needs_advancing, 1, "Ready to be advanced."); + + # Bug 30518: Confirm that DST boundaries do not explode. + # mock_config does not work here, because of tz vs timezone subroutines + my $context = Test::MockModule->new('C4::Context'); + $context->mock( 'tz', sub { + 'Europe/London'; + }); + my $bad_date = dt_from_string("2020-09-29T01:15:30", 'iso'); + $dbtransfer->datesent($bad_date)->store; + $dbtransfer->datearrived($bad_date)->store; + $dbitem->stage->duration(180)->store; + is( $dbitem->needs_advancing, 1, "DST boundary doesn't cause failure." ); + $context->unmock('tz'); + + # Test that missing historical branch transfers do not crash $dbtransfer->delete; warning_is {$dbitem->needs_advancing} "We have no historical branch transfer for itemnumber " . $dbitem->itemnumber->itemnumber . "; This should not have happened!", "Missing transfer is warned."; -- 2.39.5