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 |
is( output_pref(), undef, 'Call output_pref without parameters' ); |
227 |
is( output_pref( 'no_dt' ), undef, 'Passed single invalid dt to output_pref' ); |
229 |
try { |
|
|
230 |
output_pref( 'no_dt' ); |
231 |
ok( 0, 'Passed single invalid dt to output_pref' ); |
232 |
} catch { |
233 |
is( ref($_), 'Koha::Exceptions::WrongParameter', |
234 |
'Passed single invalid dt to output_pref' ); |
235 |
}; |
228 |
|
236 |
|
229 |
# pass invalid dt via hash |
237 |
# pass invalid dt via hash |
230 |
is( output_pref({ dt => 'no_dt' }), undef, 'Passed invalid dt in hash to output_pref' ); |
238 |
try { |
|
|
239 |
output_pref({ dt => 'no_dt' }); |
240 |
ok( 0, 'Passed invalid dt in hash to output_pref' ); |
241 |
} catch { |
242 |
is( ref($_), 'Koha::Exceptions::WrongParameter', |
243 |
'Passed invalid dt in hash to output_pref' ); |
244 |
}; |
231 |
|
245 |
|
232 |
# output_pref with str parameter |
246 |
# 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' ); |
247 |
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; |
248 |
my $output_for_invalid_date; |
235 |
warning_like { $output_for_invalid_date = output_pref( { str => 'invalid_date' } ) } |
249 |
try { |
236 |
{ carped => qr[^Invalid date 'invalid_date' passed to output_pref] }, |
250 |
$output_for_invalid_date = output_pref({ str => 'invalid_date' }); |
237 |
'output_pref should carp if an invalid date is passed for the str parameter'; |
251 |
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' ); |
252 |
} catch { |
239 |
warning_is { output_pref( { 'str' => $testdate_iso, dt => $dt, dateformat => 'iso', dateonly => 1 } ) } |
253 |
is( ref($_), 'Koha::Exceptions::WrongParameter', |
240 |
{ carped => 'output_pref should not be called with both dt and str parameters' }, |
254 |
'Invalid date string passed to output_pref' ); |
241 |
'output_pref should carp if str and dt parameters are passed together'; |
255 |
}; |
|
|
256 |
is( $output_for_invalid_date, undef, 'No return value from output_pref' ); |
257 |
try { |
258 |
output_pref({ 'str' => $testdate_iso, dt => $dt, dateformat => 'iso', dateonly => 1 }); |
259 |
ok( 0, 'output_pref should carp if str and dt parameters are passed together' ); |
260 |
} catch { |
261 |
is( ref($_), 'Koha::Exceptions::WrongParameter', 'output_pref should throw an exception if str and dt parameters are passed together' ); |
262 |
}; |
263 |
|
264 |
# End of tests |
242 |
- |
|
|