Bugzilla – Attachment 35405 Details for
Bug 13601
Get rid of DateTime::Format::DateParse
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13601: Add tests to highlight the problems with DateTime::Format::DateParse
Bug-13601-Add-tests-to-highlight-the-problems-with.patch (text/plain), 3.30 KB, created by
Jonathan Druart
on 2015-01-20 15:12:20 UTC
(
hide
)
Description:
Bug 13601: Add tests to highlight the problems with DateTime::Format::DateParse
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-01-20 15:12:20 UTC
Size:
3.30 KB
patch
obsolete
>From b64e39c4ee1e0c8a03e8f536d74bc611717e5296 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 20 Jan 2015 15:28:19 +0100 >Subject: [PATCH] Bug 13601: Add tests to highlight the problems with > DateTime::Format::DateParse > >--- > t/DateUtils.t | 45 ++++++++++++++++++++++++++++++++++++--------- > 1 file changed, 36 insertions(+), 9 deletions(-) > >diff --git a/t/DateUtils.t b/t/DateUtils.t >index 6030e68..886e1d6 100755 >--- a/t/DateUtils.t >+++ b/t/DateUtils.t >@@ -3,9 +3,10 @@ use DateTime; > use DateTime::TimeZone; > > use C4::Context; >-use Test::More tests => 42; >+use Test::More tests => 52; > use Test::MockModule; > use Time::HiRes qw/ gettimeofday /; >+use t::lib::Mocks; > > BEGIN { use_ok('Koha::DateUtils'); } > >@@ -25,13 +26,7 @@ $dt->set_minute(0); > > my $date_string; > >-my $module_context = new Test::MockModule('C4::Context'); >-$module_context->mock( >- 'preference', >- sub { >- return 'us'; >- } >-); >+t::lib::Mocks::mock_preference('dateformat', 'us'); > > my $dateformat = C4::Context->preference('dateformat'); > cmp_ok output_pref({ dt => $dt, dateformat => $dateformat }), >@@ -117,7 +112,7 @@ $dt0 = dt_from_string( '0000-00-00', 'iso' ); > is( $dt0, undef, "undefined returned for 0 iso date" ); > > # Return undef if passed mysql 9999-* date >-my $dt9999 = dt_from_string( '9999-12-31' ); >+my $dt9999 = dt_from_string( '9999-12-31', 'sql' ); > is( $dt9999->ymd(), '9999-12-31', "dt_from_string should return a DateTime object for 9999-12-31" ); > > my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric', '24hr' ); >@@ -162,3 +157,35 @@ cmp_ok $date_string, 'eq', '12/11/2013 06:35 PM', 'as_due_date with hours and ti > > my $now = DateTime->now; > is( dt_from_string, $now, "Without parameter, dt_from_string should return today" ); >+ >+# Test dt_from_string >+t::lib::Mocks::mock_preference('dateformat', 'metric'); >+t::lib::Mocks::mock_preference('TimeFormat', '24hr'); >+ >+# dt_from_string should take into account the dateformat pref, or the given parameter >+$dt = dt_from_string('31/01/2015'); >+is( ref($dt), 'DateTime', '31/01/2015 is a correct date in metric format' ); >+is( output_pref( { dt => $dt, dateonly => 1 } ), '31/01/2015' ); >+$dt = eval { dt_from_string( '31/01/2015', 'iso' ); }; >+is( ref($dt), '', '31/01/2015 is not a correct date in iso format' ); >+$dt = eval { dt_from_string( '01/01/2015', 'iso' ); }; >+is( ref($dt), '', '01/01/2015 is not a correct date in iso format' ); >+$dt = eval { dt_from_string( '31/01/2015', 'us' ); }; >+is( ref($dt), '', '31/01/2015 is not a correct date in us format' ); >+$dt = dt_from_string( '01/01/2015', 'us' ); >+is( ref($dt), 'DateTime', '01/01/2015 is a correct date in us format' ); >+ >+ >+# default value for hh and mm is 00:00 >+$dt = dt_from_string('31/01/2015'); >+is( output_pref( { dt => $dt } ), '31/01/2015 00:00', 'dt_from_string should generate a DT object with 00:00 as default hh:mm' ); >+ >+$dt = dt_from_string('31/01/2015 12:34'); >+is( output_pref( { dt => $dt } ), '31/01/2015 12:34', 'dt_from_string should match hh:mm' ); >+ >+$dt = dt_from_string('31/01/2015 12:34:56'); >+is( output_pref( { dt => $dt } ), '31/01/2015 12:34', 'dt_from_string should match hh:mm:ss' ); >+ >+# date before 1900 >+$dt = dt_from_string('01/01/1900'); >+is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900', 'dt_from_string should manage date < 1900' ); >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13601
:
35405
|
35406
|
35407
|
35408
|
35433
|
36733
|
36734
|
36735
|
36736
|
36737
|
36745
|
36746
|
36747
|
36748
|
36754
|
36755
|
36756
|
36928
|
36933
|
36939
|
37023
|
37087
|
37088
|
37089
|
37090
|
37091
|
37092
|
37093