From 9b966c15713955eaa64dbeaab6c81edc05a11e6f Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Wed, 15 Jun 2011 12:53:13 +0100 Subject: [PATCH] Bug 5549 : Merge old and new DateUtils tests --- t/DateUtils.t | 42 +++++++++++++++++++++++++++++------------- t/dateutils.t | 32 -------------------------------- 2 files changed, 29 insertions(+), 45 deletions(-) delete mode 100644 t/dateutils.t diff --git a/t/DateUtils.t b/t/DateUtils.t index ed1ac9f715..f922d52eb9 100755 --- a/t/DateUtils.t +++ b/t/DateUtils.t @@ -2,25 +2,41 @@ use strict; use warnings; use 5.010; use DateTime; +use DateTime::TimeZone; -use Test::More tests => 8; # last test to print +use C4::Context; +use Test::More tests => 9; # last test to print -use_ok('Koha::DateUtils'); +BEGIN { use_ok('Koha::DateUtils'); } -my $dt_metric = dt_from_string('01/02/2010', 'metric', 'Europe/London'); -isa_ok $dt_metric, 'DateTime', 'metric returns a DateTime object'; -cmp_ok $dt_metric->ymd(), 'eq', '2010-02-01', 'metric date correct'; +my $tz = C4::Context->tz; -my $dt_us = dt_from_string('02/01/2010', 'us', 'Europe/London'); -isa_ok $dt_us, 'DateTime', 'us returns a DateTime object'; -cmp_ok $dt_us->ymd(), 'eq', '2010-02-01', 'us date correct'; +isa_ok( $tz, 'DateTime::TimeZone', 'Context returns timezone object' ); -my $dt_iso = dt_from_string('2010-02-01', 'iso', 'Europe/London'); -isa_ok $dt_iso, 'DateTime', 'iso returns a DateTime object'; -cmp_ok $dt_iso->ymd(), 'eq', '2010-02-01', 'iso date correct'; +my $testdate_iso = '2011-06-16'; # Bloomsday 2011 +my $dt = dt_from_string( $testdate_iso, 'iso' ); +isa_ok( $dt, 'DateTime', 'dt_from_string returns a DateTime object' ); +cmp_ok( $dt->ymd(), 'eq', $testdate_iso, 'Returned object matches input' ); -my $dt = dt_from_string( undef ); +$dt->set_hour(12); +$dt->set_minute(0); + +my $date_string = output_pref( $dt, 'iso' ); +cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output'; + +$date_string = output_pref( $dt, 'us' ); +cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output'; + +# metric should return the French Revolutionary Calendar Really +$date_string = output_pref( $dt, 'metric' ); +cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output'; + +my $dear_dirty_dublin = DateTime::TimeZone->new( name => 'Europe/Dublin'); +my $new_dt = dt_from_string('16/06/2011', 'metric', $dear_dirty_dublin); + +isa_ok( $new_dt, 'DateTime', 'Create DateTime with different timezone' ); + +cmp_ok( $new_dt->ymd(), 'eq', $testdate_iso, 'Returned Dublin object matches input' ); -isa_ok $dt, 'DateTime', 'No string returns a DateTime object'; diff --git a/t/dateutils.t b/t/dateutils.t deleted file mode 100644 index 3d64d4f742..0000000000 --- a/t/dateutils.t +++ /dev/null @@ -1,32 +0,0 @@ -use strict; -use warnings; -use 5.010; - -use C4::Context; -use Test::More tests => 7; # last test to print - -BEGIN { use_ok('Koha::DateUtils'); } - -my $tz = C4::Context->tz; - -isa_ok( $tz, 'DateTime::TimeZone', 'Context returns timezone object' ); - -my $testdate_iso = '2011-06-16'; # Bloomsday 2011 -my $dt = dt_from_string( $testdate_iso, 'iso' ); - -isa_ok( $dt, 'DateTime', 'dt_from_string returns a DateTime object' ); - -cmp_ok( $dt->ymd(), 'eq', $testdate_iso, 'Returned object matches input' ); - -$dt->set_hour(12); -$dt->set_minute(0); - -my $date_string = output_pref( $dt, 'iso' ); -cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output'; - -$date_string = output_pref( $dt, 'us' ); -cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output'; - -# metric should return the French Revolutionary Calendar Really -$date_string = output_pref( $dt, 'metric' ); -cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output'; -- 2.20.1