Lines 4-9
use strict;
Link Here
|
4 |
use warnings; |
4 |
use warnings; |
5 |
|
5 |
|
6 |
use Test::More tests => 327; |
6 |
use Test::More tests => 327; |
|
|
7 |
use Test::Warn; |
7 |
|
8 |
|
8 |
BEGIN { |
9 |
BEGIN { |
9 |
use FindBin; |
10 |
use FindBin; |
Lines 43-71
$C4::Dates::prefformat = $fake_syspref; # So Dates doesn't have to ask the DB
Link Here
|
43 |
|
44 |
|
44 |
diag <<EndOfDiag; |
45 |
diag <<EndOfDiag; |
45 |
|
46 |
|
46 |
In order to run without DB access, this test will substitute '$fake_syspref' |
47 |
In order to run without DB access, this test will substitute |
47 |
as your default date format. Export environmental variable KOHA_TEST_DATE_FORMAT |
48 |
'$fake_syspref' as your default date format. Export |
48 |
to override this default, or pass the value as an argument to this test script. |
49 |
environmental variable KOHA_TEST_DATE_FORMAT to override this |
|
|
50 |
default, or pass the value as an argument to this test script. |
49 |
|
51 |
|
50 |
NOTE: we test for the system handling dd=00 and 00 for TIME values, therefore |
52 |
NOTE: we test for the system handling dd=00 and 00 for TIME |
51 |
you SHOULD see some warnings like: |
53 |
values, but you should not see any warnings. |
52 |
Illegal date specified (year = 1952, month = 1, day = 00) at t/Dates.t ... |
|
|
53 |
|
54 |
|
54 |
Testing Legacy Functions: format_date and format_date_in_iso |
55 |
Testing Legacy Functions: format_date and format_date_in_iso |
55 |
|
|
|
56 |
EndOfDiag |
56 |
EndOfDiag |
57 |
|
57 |
|
58 |
ok( $syspref = C4::Dates->new->format(), "Your system preference is: $syspref" ); |
58 |
ok( $syspref = C4::Dates->new->format(), "Your system preference is: $syspref" ); |
59 |
print "\n"; |
|
|
60 |
foreach ( @{ $thash{'iso'} } ) { |
59 |
foreach ( @{ $thash{'iso'} } ) { |
61 |
ok( $val = format_date($_), "format_date('$_'): $val" ); |
60 |
if ($_ =~ /1952/) { |
|
|
61 |
warning_like { $val = format_date($_); } qr/Illegal date/, |
62 |
"format_date('$_'): Warning as expected"; |
63 |
} |
64 |
else { |
65 |
ok( $val = format_date($_), "format_date('$_'): $val" ); |
66 |
} |
62 |
} |
67 |
} |
63 |
foreach ( @{ $thash{$syspref} } ) { |
68 |
foreach ( @{ $thash{$syspref} } ) { |
64 |
ok( $val = format_date_in_iso($_), "format_date_in_iso('$_'): $val" ); |
69 |
if ($_ =~ /1952/) { |
|
|
70 |
warning_like { $val = format_date_in_iso($_); } qr/Illegal date/, |
71 |
"format_date_in_iso('$_'): Warning as expected"; |
72 |
} |
73 |
else { |
74 |
ok( $val = format_date_in_iso($_), "format_date_in_iso('$_'): $val" ); |
75 |
} |
65 |
} |
76 |
} |
66 |
ok( $today0 = C4::Dates->today(), "(default) CLASS ->today : $today0" ); |
77 |
ok( $today0 = C4::Dates->today(), "(default) CLASS ->today : $today0" ); |
67 |
diag "\nTesting " . scalar(@formats) . " formats.\nTesting no input (defaults):\n"; |
78 |
diag "Testing " . scalar(@formats) . " formats.\nTesting no input (defaults):"; |
68 |
print "\n"; |
|
|
69 |
foreach (@formats) { |
79 |
foreach (@formats) { |
70 |
my $pre = sprintf '(%-6s)', $_; |
80 |
my $pre = sprintf '(%-6s)', $_; |
71 |
ok( $date = C4::Dates->new(), "$pre Date Creation : new()" ); |
81 |
ok( $date = C4::Dates->new(), "$pre Date Creation : new()" ); |
Lines 73-86
foreach (@formats) {
Link Here
|
73 |
ok( $format = $date->visual(), "$pre visual() : " . ( $format || 'FAILED' ) ); |
83 |
ok( $format = $date->visual(), "$pre visual() : " . ( $format || 'FAILED' ) ); |
74 |
ok( $today = $date->output(), "$pre output() : " . ( $today || 'FAILED' ) ); |
84 |
ok( $today = $date->output(), "$pre output() : " . ( $today || 'FAILED' ) ); |
75 |
ok( $today = $date->today(), "$pre object->today : " . ( $today || 'FAILED' ) ); |
85 |
ok( $today = $date->today(), "$pre object->today : " . ( $today || 'FAILED' ) ); |
76 |
print "\n"; |
|
|
77 |
} |
86 |
} |
78 |
|
87 |
|
79 |
diag "\nTesting with valid inputs:\n"; |
88 |
diag "Testing with valid inputs:"; |
80 |
foreach $format (@formats) { |
89 |
foreach $format (@formats) { |
81 |
my $pre = sprintf '(%-6s)', $format; |
90 |
my $pre = sprintf '(%-6s)', $format; |
82 |
foreach my $testval ( @{ $thash{$format} } ) { |
91 |
foreach my $testval ( @{ $thash{$format} } ) { |
83 |
ok( $date = C4::Dates->new( $testval, $format ), "$pre Date Creation : new('$testval','$format')" ); |
92 |
if ($testval =~ /1952/) { |
|
|
93 |
warning_like { $date = C4::Dates->new( $testval, $format ) } |
94 |
qr/Illegal date/, |
95 |
"$pre Date Creation : new('$testval','$format') -- Warning as expected."; |
96 |
} |
97 |
else { |
98 |
ok( $date = C4::Dates->new( $testval, $format ), "$pre Date Creation : new('$testval','$format')" ); |
99 |
} |
84 |
ok( $re = $date->regexp, "$pre has regexp()" ); |
100 |
ok( $re = $date->regexp, "$pre has regexp()" ); |
85 |
ok( $testval =~ /^$re$/, "$pre has regexp() match $testval" ); |
101 |
ok( $testval =~ /^$re$/, "$pre has regexp() match $testval" ); |
86 |
ok( $val = $date->output(), describe( "$pre output()", $val ) ); |
102 |
ok( $val = $date->output(), describe( "$pre output()", $val ) ); |
Lines 98-108
foreach $format (@formats) {
Link Here
|
98 |
ok( $val = $date->output(), describe( "$pre output()", $val ) ); |
114 |
ok( $val = $date->output(), describe( "$pre output()", $val ) ); |
99 |
|
115 |
|
100 |
# ok($format eq ($format = $date->format()), "$pre format() : $format" ); |
116 |
# ok($format eq ($format = $date->format()), "$pre format() : $format" ); |
101 |
print "\n"; |
|
|
102 |
} |
117 |
} |
103 |
} |
118 |
} |
104 |
|
119 |
|
105 |
diag "\nTesting object independence from class\n"; |
120 |
diag "Testing object independence from class"; |
106 |
my $in1 = '12/25/1952'; # us |
121 |
my $in1 = '12/25/1952'; # us |
107 |
my $in2 = '13/01/2001'; # metric |
122 |
my $in2 = '13/01/2001'; # metric |
108 |
my $d1 = C4::Dates->new( $in1, 'us' ); |
123 |
my $d1 = C4::Dates->new( $in1, 'us' ); |
Lines 110-113
my $d2 = C4::Dates->new( $in2, 'metric' );
Link Here
|
110 |
my $out1 = $d1->output('iso'); |
125 |
my $out1 = $d1->output('iso'); |
111 |
my $out2 = $d2->output('iso'); |
126 |
my $out2 = $d2->output('iso'); |
112 |
ok( $out1 ne $out2, "subsequent constructors get different dataspace ($out1 != $out2)" ); |
127 |
ok( $out1 ne $out2, "subsequent constructors get different dataspace ($out1 != $out2)" ); |
113 |
diag "done.\n"; |
128 |
diag "done."; |
114 |
- |
|
|