From 88b8b3c6a745f5ebae290d42d9af669e09c4b297 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 14 Apr 2022 10:19:47 +0100
Subject: [PATCH] Bug 30540: Unit test
Content-Type: text/plain; charset=utf-8

This patch adds tests for checking the output_pref 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/DateUtils.t
=> FAIL: The feature is not implemented, tests fail to complete

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 t/DateUtils.t | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/t/DateUtils.t b/t/DateUtils.t
index 97cffd7509..ae39782321 100755
--- a/t/DateUtils.t
+++ b/t/DateUtils.t
@@ -4,7 +4,7 @@ use DateTime::TimeZone;
 
 use C4::Context;
 
-use Test::More tests => 81;
+use Test::More tests => 82;
 
 use Test::MockModule;
 use Test::Warn;
@@ -262,6 +262,22 @@ $module_context->mock(
 $dt = dt_from_string('2014-03-30 02:00:00');
 isa_ok( $dt, 'DateTime', 'dt_from_string should return a DateTime object if a DST is given' );
 
+# Test output_pref for invalid local time explosion
+$dt = DateTime->new(
+    year       => 2017,
+    month      => 03,
+    day        => 26,
+    hour       => 01,
+    minute     => 35,
+);
+$module_context->mock(
+    'tz',
+    sub {
+        return DateTime::TimeZone->new( name => 'Europe/London' );
+    }
+);
+is( output_pref( { dt => $dt, dateonly => 0 } ), '03/26/2017 01:35', 'output_pref should return even if an invalid DST time is passed' );
+
 # Test dt_from_string
 t::lib::Mocks::mock_preference('dateformat', 'metric');
 t::lib::Mocks::mock_preference('TimeFormat', '24hr');
-- 
2.20.1