|
Lines 9-14
use Test::More tests => 63;
Link Here
|
| 9 |
use Test::MockModule; |
9 |
use Test::MockModule; |
| 10 |
use Test::Warn; |
10 |
use Test::Warn; |
| 11 |
use Time::HiRes qw/ gettimeofday /; |
11 |
use Time::HiRes qw/ gettimeofday /; |
|
|
12 |
use Try::Tiny; |
| 13 |
|
| 12 |
use t::lib::Mocks; |
14 |
use t::lib::Mocks; |
| 13 |
|
15 |
|
| 14 |
BEGIN { use_ok('Koha::DateUtils'); } |
16 |
BEGIN { use_ok('Koha::DateUtils'); } |
|
Lines 223-241
$dt = dt_from_string('2015-01-31 01:02:03');
Link Here
|
| 223 |
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' ); |
225 |
is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' ); |
| 224 |
|
226 |
|
| 225 |
# output_pref with no parameters, single parameter (no hash) |
227 |
# output_pref with no parameters, single parameter (no hash) |
| 226 |
is( output_pref(), undef, 'output_pref without parameters' ); |
228 |
try { |
| 227 |
is( output_pref( 'no_dt' ), undef, 'Passed single invalid dt to output_pref' ); |
229 |
output_pref(); |
|
|
230 |
ok( 0, 'output_pref without parameters' ); |
| 231 |
} catch { |
| 232 |
is( ref($_), 'Koha::Exceptions::DateUtils::output_pref::NoDateTime', |
| 233 |
'output_pref without parameters' ); |
| 234 |
}; |
| 235 |
try { |
| 236 |
output_pref( 'no_dt' ); |
| 237 |
ok( 0, 'Passed single invalid dt to output_pref' ); |
| 238 |
} catch { |
| 239 |
is( ref($_), 'Koha::Exceptions::DateUtils::output_pref::NoDateTime', |
| 240 |
'Passed single invalid dt to output_pref' ); |
| 241 |
}; |
| 228 |
|
242 |
|
| 229 |
# pass invalid dt via hash |
243 |
# pass invalid dt via hash |
| 230 |
is( output_pref({ dt => 'no_dt' }), undef, 'Passed invalid dt in hash to output_pref' ); |
244 |
try { |
|
|
245 |
output_pref({ dt => 'no_dt' }); |
| 246 |
ok( 0, 'Passed invalid dt in hash to output_pref' ); |
| 247 |
} catch { |
| 248 |
is( ref($_), 'Koha::Exceptions::DateUtils::output_pref::NoDateTime', |
| 249 |
'Passed invalid dt in hash to output_pref' ); |
| 250 |
}; |
| 231 |
|
251 |
|
| 232 |
# output_pref with str parameter |
252 |
# output_pref with str parameter |
| 233 |
is( output_pref( { 'str' => $testdate_iso, dateformat => 'iso', dateonly => 1 } ), $testdate_iso, 'output_pref should handle correctly the iso parameter' ); |
253 |
is( output_pref( { 'str' => $testdate_iso, dateformat => 'iso', dateonly => 1 } ), $testdate_iso, 'output_pref should handle correctly the iso parameter' ); |
| 234 |
my $output_for_invalid_date; |
254 |
my $output_for_invalid_date; |
| 235 |
warning_like { $output_for_invalid_date = output_pref( { str => 'invalid_date' } ) } |
255 |
try { |
| 236 |
{ carped => qr[^Invalid date 'invalid_date' passed to output_pref] }, |
256 |
$output_for_invalid_date = output_pref({ str => 'invalid_date' }); |
| 237 |
'output_pref should carp if an invalid date is passed for the str parameter'; |
257 |
ok( 0, 'Invalid date string passed to output_pref' ); |
| 238 |
is( $output_for_invalid_date, undef, 'output_pref should return undef if an invalid date is passed' ); |
258 |
} catch { |
| 239 |
warning_is { output_pref( { 'str' => $testdate_iso, dt => $dt, dateformat => 'iso', dateonly => 1 } ) } |
259 |
is( ref($_), 'Koha::Exceptions::DateUtils::output_pref::InvalidDateString', |
| 240 |
{ carped => 'output_pref should not be called with both dt and str parameters' }, |
260 |
'Invalid date string passed to output_pref' ); |
| 241 |
'output_pref should carp if str and dt parameters are passed together'; |
261 |
}; |
|
|
262 |
is( $output_for_invalid_date, undef, 'No return value from output_pref' ); |
| 263 |
try { |
| 264 |
output_pref({ 'str' => $testdate_iso, dt => $dt, dateformat => 'iso', dateonly => 1 }); |
| 265 |
ok( 0, 'output_pref should carp if str and dt parameters are passed together' ); |
| 266 |
} catch { |
| 267 |
is( ref($_), 'Koha::Exceptions::DateUtils::output_pref::ConflictingParameters', 'output_pref should throw an exception if str and dt parameters are passed together' ); |
| 268 |
}; |
| 269 |
|
| 270 |
# End of tests |
| 242 |
- |
|
|