Context.pm fatalsToBrowser now dependent on $ENV{USER_AGENT}.
[koha.git] / t / Dates.t
1 #!/bin/perl
2
3 use Test::More tests => 82;
4 BEGIN {
5                 use_ok('C4::Dates');
6 }
7
8 my %thash = (
9           iso  => ['2001-01-01','1989-09-21'],
10         metric => ["01-01-2001",'21-09-1989'],
11            us  => ["01-01-2001",'09-21-1989'],
12           sql  => ['20010101    010101',
13                            '19890921    143907'     ],
14 );
15
16 my @formats = sort keys %thash;
17 diag "\nNote: CGI::Carp may throw an initial error here.  Ignore that.\n";
18 diag "Testing " . scalar(@formats) . " formats.\nTesting no input:\n";
19 my ($today, $today0, $val, $re);
20 ok($today0 = C4::Dates->today(),                "(default) CLASS ->today : $today0" );
21 foreach (@formats) {
22         my $pre = sprintf '(%-6s)', $_;
23         ok($date = C4::Dates->new(),                "$pre Date Creation   : new()");
24         ok($_ eq ($format = $date->format($_)),     "$pre format($_)      : $format" );
25         ok($today  = $date->output(),               "$pre output()        : $today" );
26         ok($today  = $date->today(),                "$pre object->today   : $today" );
27         print "\n";
28 }
29
30 foreach my $format (@formats) {
31         my $pre = sprintf '(%-6s)', $format;
32   foreach my $testval (@{$thash{ $format }}) {
33         ok($date = C4::Dates->new($testval,$format),      "$pre Date Creation   : new('$testval','$format')");
34         ok($re   = $date->regexp,                   "$pre has regexp()" );
35         ok($val  = $date->output(),                 "$pre output()        : $val" );
36         foreach (grep {!/$format/} @formats) {
37                 ok($today = $date->output($_),          "$pre output(" . sprintf("%8s","'$_'") . "): $today");
38         }
39         ok($today  = $date->today(),                "$pre object->today   : $today" );
40         # ok($today == ($today = C4::Dates->today()), "$pre CLASS ->today   : $today" );
41         ok($val  = $date->output(),                 "$pre output()        : $val" );
42         # ok($format eq ($format = $date->format()),  "$pre format()        : $format" );
43         print "\n";
44   }
45 }
46
47 diag "done.\n";