Lines 1-14
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/env perl |
2 |
# |
|
|
3 |
# This Koha test module is a stub! |
4 |
# Add more tests here!!! |
5 |
|
2 |
|
6 |
use strict; |
3 |
use strict; |
7 |
use warnings; |
4 |
use warnings; |
8 |
|
5 |
use DateTime; |
9 |
use Test::More tests => 1; |
6 |
use Test::More tests => 21; |
|
|
7 |
use Koha::DateUtils; |
10 |
|
8 |
|
11 |
BEGIN { |
9 |
BEGIN { |
12 |
use_ok('C4::Calendar'); |
10 |
use_ok('Koha::Calendar'); |
|
|
11 |
|
12 |
# This was the only test C4 had |
13 |
# Remove when no longer used |
14 |
use_ok('C4::Calendar'); |
13 |
} |
15 |
} |
14 |
|
16 |
|
|
|
17 |
my $cal = Koha::Calendar->new( TEST_MODE => 1 ); |
18 |
|
19 |
isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' ); |
20 |
|
21 |
my $saturday = DateTime->new( |
22 |
year => 2011, |
23 |
month => 6, |
24 |
day => 25, |
25 |
time_zone => 'Europe/London', |
26 |
); |
27 |
my $sunday = DateTime->new( |
28 |
year => 2011, |
29 |
month => 6, |
30 |
day => 26, |
31 |
time_zone => 'Europe/London', |
32 |
); |
33 |
my $monday = DateTime->new( |
34 |
year => 2011, |
35 |
month => 6, |
36 |
day => 27, |
37 |
time_zone => 'Europe/London', |
38 |
); |
39 |
my $bloomsday = DateTime->new( |
40 |
year => 2011, |
41 |
month => 6, |
42 |
day => 16, |
43 |
time_zone => 'Europe/London', |
44 |
); # should be a holiday |
45 |
my $special = DateTime->new( |
46 |
year => 2011, |
47 |
month => 6, |
48 |
day => 1, |
49 |
time_zone => 'Europe/London', |
50 |
); # should be a holiday |
51 |
my $notspecial = DateTime->new( |
52 |
year => 2011, |
53 |
month => 6, |
54 |
day => 2, |
55 |
time_zone => 'Europe/London', |
56 |
); # should NOT be a holiday |
57 |
|
58 |
is( $cal->is_holiday($sunday), 1, 'Sunday is a closed day' ); # wee free test; |
59 |
is( $cal->is_holiday($monday), 0, 'Monday is not a closed day' ); # alas |
60 |
is( $cal->is_holiday($bloomsday), 1, 'month/day closed day test' ); |
61 |
is( $cal->is_holiday($special), 1, 'special closed day test' ); |
62 |
is( $cal->is_holiday($notspecial), 0, 'open day test' ); |
63 |
|
64 |
my $dt = $cal->addDate( $saturday, 1, 'days' ); |
65 |
is( $dt->day_of_week, 1, 'addDate skips closed Sunday' ); |
66 |
|
67 |
$dt = $cal->addDate( $bloomsday, -1 ); |
68 |
is( $dt->ymd(), '2011-06-15', 'Negative call to addDate' ); |
69 |
|
70 |
my $test_dt = DateTime->new( # Monday |
71 |
year => 2012, |
72 |
month => 7, |
73 |
day => 23, |
74 |
hour => 11, |
75 |
minute => 53, |
76 |
time_zone => 'Europe/London', |
77 |
); |
78 |
|
79 |
my $later_dt = DateTime->new( # Monday |
80 |
year => 2012, |
81 |
month => 9, |
82 |
day => 17, |
83 |
hour => 17, |
84 |
minute => 30, |
85 |
time_zone => 'Europe/London', |
86 |
); |
87 |
|
88 |
my $daycount = $cal->days_between( $test_dt, $later_dt ); |
89 |
cmp_ok( $daycount->in_units('days'), |
90 |
'==', 48, 'days_between calculates correctly' ); |
91 |
|
92 |
my $ret = $cal->addDate( $test_dt, 1, 'days' ); |
93 |
|
94 |
cmp_ok( $ret->ymd(), 'eq', '2012-07-24', 'Simple Single Day Add (Calendar)`' ); |
95 |
|
96 |
$ret = $cal->addDate( $test_dt, 7, 'days' ); |
97 |
cmp_ok( $ret->ymd(), 'eq', '2012-07-31', 'Add 7 days Calendar mode' ); |
98 |
$cal->set_daysmode('Datedue'); |
99 |
$ret = $cal->addDate( $test_dt, 7, 'days' ); |
100 |
cmp_ok( $ret->ymd(), 'eq', '2012-07-30', 'Add 7 days Datedue mode' ); |
101 |
$cal->set_daysmode('Days'); |
102 |
$ret = $cal->addDate( $test_dt, 7, 'days' ); |
103 |
cmp_ok( $ret->ymd(), 'eq', '2012-07-30', 'Add 7 days Days mode' ); |
104 |
$cal->set_daysmode('Calendar'); |
105 |
|
106 |
# example tests for bug report |
107 |
$cal->clear_weekly_closed_days(); |
108 |
|
109 |
$daycount = $cal->days_between( dt_from_string('2012-01-10'), |
110 |
dt_from_string("2012-05-05") )->in_units('days'); |
111 |
cmp_ok( $daycount, '==', 116, 'test larger intervals' ); |
112 |
$daycount = $cal->days_between( dt_from_string("2012-01-01"), |
113 |
dt_from_string("2012-05-05") )->in_units('days'); |
114 |
cmp_ok( $daycount, '==', 125, 'test positive intervals' ); |
115 |
my $daycount2 = $cal->days_between( dt_from_string("2012-05-05"), |
116 |
dt_from_string("2012-01-01") )->in_units('days'); |
117 |
cmp_ok( $daycount2, '==', $daycount, 'test parameter order not relevant' ); |
118 |
$daycount = $cal->days_between( dt_from_string("2012-07-01"), |
119 |
dt_from_string("2012-07-15") )->in_units('days'); |
120 |
cmp_ok( $daycount, '==', 14, 'days_between calculates correctly' ); |
121 |
$cal->add_holiday( dt_from_string('2012-07-06') ); |
122 |
$daycount = $cal->days_between( dt_from_string("2012-07-01"), |
123 |
dt_from_string("2012-07-15") )->in_units('days'); |
124 |
cmp_ok( $daycount, '==', 13, 'holiday correctly recognized' ); |
125 |
|
126 |
$cal->add_holiday( dt_from_string('2012-07-07') ); |
127 |
$daycount = $cal->days_between( dt_from_string("2012-07-01"), |
128 |
dt_from_string("2012-07-15") )->in_units('days'); |
129 |
cmp_ok( $daycount, '==', 12, 'multiple holidays correctly recognized' ); |