Bug 24850: Add tests for invalid RFC3339 dates

We should die on invalidly formatted dates being passed.  This patch
adds such a test case.

Signed-off-by: David Cook <dcook@prosentient.com.au>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2020-03-11 16:20:36 +00:00 committed by Jonathan Druart
parent 1059303f90
commit 911f9bcde5

View file

@ -4,7 +4,7 @@ use DateTime::TimeZone;
use C4::Context; use C4::Context;
use Test::More tests => 78; use Test::More tests => 79;
use Test::MockModule; use Test::MockModule;
use Test::Warn; use Test::Warn;
@ -137,6 +137,13 @@ cmp_ok( $dt0->epoch(), 'eq', '1325462399', 'dt_from_string handles seconds with
$dt0 = dt_from_string( '2012-01-01T23:59:59.999+02:00', 'rfc3339' ); $dt0 = dt_from_string( '2012-01-01T23:59:59.999+02:00', 'rfc3339' );
cmp_ok( $dt0->epoch(), 'eq', '1325455199', 'dt_from_string handles seconds with 3 decimal places and a timezone' ); cmp_ok( $dt0->epoch(), 'eq', '1325455199', 'dt_from_string handles seconds with 3 decimal places and a timezone' );
try {
$dt0 = dt_from_string( '2012-01-01T23:59:59.999Z+02:00', 'rfc3339' );
}
catch {
like( $_, qr/.*does not match the date format \(rfc3339\).*/, 'dt_from_string should die when passed a bad date string' );
};
# Return undef if passed mysql 0 dates # Return undef if passed mysql 0 dates
$dt0 = dt_from_string( '0000-00-00', 'iso' ); $dt0 = dt_from_string( '0000-00-00', 'iso' );
is( $dt0, undef, "undefined returned for 0 iso date" ); is( $dt0, undef, "undefined returned for 0 iso date" );