Bug 36486: Add tests for Koha::DateTime::Format::SQL

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Julian Maurice 2024-04-02 09:34:25 +02:00 committed by Katrin Fischer
parent faeebd7486
commit e6382d04ad
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834

View file

@ -0,0 +1,84 @@
#!/usr/bin/perl
use Modern::Perl;
use DateTime::TimeZone;
use Test::Exception;
use Test::MockModule;
use Test::More;
BEGIN { use_ok('Koha::DateTime::Format::SQL'); }
my $local_timezone = DateTime::TimeZone->new( name => 'local' );
my $koha_config_mock = Test::MockModule->new('Koha::Config');
my $config = { timezone => '' };
$koha_config_mock->mock('get', sub { $config->{$_[1]} });
subtest 'normal datetime, no timezone configured' => sub {
plan tests => 7;
$config->{timezone} = '';
$Koha::DateTime::Format::SQL::timezone = undef;
my $dt = Koha::DateTime::Format::SQL->parse_datetime('2024-01-02 10:11:12');
is( $dt->year, 2024 );
is( $dt->month, 1 );
is( $dt->day, 2 );
is( $dt->hour, 10 );
is( $dt->minute, 11 );
is( $dt->second, 12 );
is( $dt->time_zone->name, $local_timezone->name );
};
subtest 'normal datetime, with timezone configured' => sub {
plan tests => 7;
$config->{timezone} = 'Pacific/Auckland';
$Koha::DateTime::Format::SQL::timezone = undef;
my $dt = Koha::DateTime::Format::SQL->parse_datetime('2024-01-02 10:11:12');
is( $dt->year, 2024 );
is( $dt->month, 1 );
is( $dt->day, 2 );
is( $dt->hour, 10 );
is( $dt->minute, 11 );
is( $dt->second, 12 );
is( $dt->time_zone->name, 'Pacific/Auckland' );
};
subtest 'infinite datetime, no timezone configured' => sub {
plan tests => 7;
$config->{timezone} = '';
$Koha::DateTime::Format::SQL::timezone = undef;
my $dt = Koha::DateTime::Format::SQL->parse_datetime('9999-01-02 10:11:12');
is( $dt->year, 9999 );
is( $dt->month, 1 );
is( $dt->day, 2 );
is( $dt->hour, 10 );
is( $dt->minute, 11 );
is( $dt->second, 12 );
is( $dt->time_zone->name, 'floating' );
};
subtest 'normal datetime, with timezone configured' => sub {
plan tests => 7;
$config->{timezone} = 'Pacific/Auckland';
$Koha::DateTime::Format::SQL::timezone = undef;
my $dt = Koha::DateTime::Format::SQL->parse_datetime('9999-01-02 10:11:12');
is( $dt->year, 9999 );
is( $dt->month, 1 );
is( $dt->day, 2 );
is( $dt->hour, 10 );
is( $dt->minute, 11 );
is( $dt->second, 12 );
is( $dt->time_zone->name, 'floating' );
};
done_testing;