Bug 5327 shifting database dependent modules and scripts to t/db_dependent
[koha.git] / t / db_dependent / lib / KohaTest / Calendar / New.pm
1 package KohaTest::Calendar::New;
2 use base qw( KohaTest );
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8
9 use C4::Calendar;
10 sub testing_class { 'C4::Calendar' };
11
12
13 =head2 STARTUP METHODS
14
15 These get run once, before the main test methods in this module
16
17 =cut
18
19 =head2 TEST METHODS
20
21 standard test methods
22
23 =head3 instantiation
24
25   just test to see if I can instantiate an object
26
27 =cut
28
29 sub instantiation : Test( 14 ) {
30     my $self = shift;
31
32     my $calendar = C4::Calendar->new( branchcode => '' );
33     isa_ok( $calendar, 'C4::Calendar' );
34     # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
35
36     ok( exists $calendar->{'day_month_holidays'}, 'day_month_holidays' );
37     ok( exists $calendar->{'single_holidays'},    'single_holidays' );
38     ok( exists $calendar->{'week_days_holidays'}, 'week_days_holidays' );
39     ok( exists $calendar->{'exception_holidays'}, 'exception_holidays' );
40
41     # sample data has Sundays as a holiday
42     ok( exists $calendar->{'week_days_holidays'}->{'0'} );
43     is( $calendar->{'week_days_holidays'}->{'0'}->{'title'},       '',        'Sunday title' );
44     is( $calendar->{'week_days_holidays'}->{'0'}->{'description'}, 'Sundays', 'Sunday description' );
45     
46     # sample data has Christmas as a holiday
47     ok( exists $calendar->{'day_month_holidays'}->{'12/25'} );
48     is( $calendar->{'day_month_holidays'}->{'12/25'}->{'title'},       '',          'Christmas title' );
49     is( $calendar->{'day_month_holidays'}->{'12/25'}->{'description'}, 'Christmas', 'Christmas description' );
50     
51     # sample data has New Year's Day as a holiday
52     ok( exists $calendar->{'day_month_holidays'}->{'1/1'} );
53     is( $calendar->{'day_month_holidays'}->{'1/1'}->{'title'},       '',                'New Year title' );
54     is( $calendar->{'day_month_holidays'}->{'1/1'}->{'description'}, q(New Year's Day), 'New Year description' );
55     
56 }
57
58 sub week_day_holidays : Test( 8 ) {
59     my $self = shift;
60
61     my $calendar = C4::Calendar->new( branchcode => '' );
62     isa_ok( $calendar, 'C4::Calendar' );
63     # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
64
65     ok( exists $calendar->{'week_days_holidays'}, 'week_days_holidays' );
66
67     my %new_holiday = ( weekday     => 1,
68                         title       => 'example week_day_holiday',
69                         description => 'This is an example week_day_holiday used for testing' );
70     my $new_calendar = $calendar->insert_week_day_holiday( %new_holiday );
71
72     # the calendar object returned from insert_week_day_holiday should be updated
73     isa_ok( $new_calendar, 'C4::Calendar' );
74     is( $new_calendar->{'week_days_holidays'}->{ $new_holiday{'weekday'} }->{'title'}, $new_holiday{'title'}, 'title' );
75     is( $new_calendar->{'week_days_holidays'}->{ $new_holiday{'weekday'} }->{'description'}, $new_holiday{'description'}, 'description' );
76
77     # new calendar objects should have the newly inserted holiday.
78     my $refreshed_calendar = C4::Calendar->new( branchcode => '' );
79     isa_ok( $refreshed_calendar, 'C4::Calendar' );
80     # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
81     is( $new_calendar->{'week_days_holidays'}->{ $new_holiday{'weekday'} }->{'title'}, $new_holiday{'title'}, 'title' );
82     is( $new_calendar->{'week_days_holidays'}->{ $new_holiday{'weekday'} }->{'description'}, $new_holiday{'description'}, 'description' );
83
84 }
85   
86
87 sub day_month_holidays : Test( 8 ) {
88     my $self = shift;
89
90     my $calendar = C4::Calendar->new( branchcode => '' );
91     isa_ok( $calendar, 'C4::Calendar' );
92     # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
93
94     ok( exists $calendar->{'day_month_holidays'}, 'day_month_holidays' );
95
96     my %new_holiday = ( day        => 4,
97                         month       => 5,
98                         title       => 'example day_month_holiday',
99                         description => 'This is an example day_month_holiday used for testing' );
100     my $new_calendar = $calendar->insert_day_month_holiday( %new_holiday );
101
102     # the calendar object returned from insert_week_day_holiday should be updated
103     isa_ok( $new_calendar, 'C4::Calendar' );
104     my $mmdd = sprintf('%s/%s', $new_holiday{'month'}, $new_holiday{'day'} ) ;
105     is( $new_calendar->{'day_month_holidays'}->{ $mmdd }->{'title'}, $new_holiday{'title'}, 'title' );
106     is( $new_calendar->{'day_month_holidays'}->{ $mmdd }->{'description'}, $new_holiday{'description'}, 'description' );
107
108     # new calendar objects should have the newly inserted holiday.
109     my $refreshed_calendar = C4::Calendar->new( branchcode => '' );
110     isa_ok( $refreshed_calendar, 'C4::Calendar' );
111     # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
112     is( $new_calendar->{'day_month_holidays'}->{ $mmdd }->{'title'}, $new_holiday{'title'}, 'title' );
113     is( $new_calendar->{'day_month_holidays'}->{ $mmdd }->{'description'}, $new_holiday{'description'}, 'description' );
114
115 }
116   
117
118
119 sub exception_holidays : Test( 8 ) {
120     my $self = shift;
121
122     my $calendar = C4::Calendar->new( branchcode => '' );
123     isa_ok( $calendar, 'C4::Calendar' );
124     # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
125
126     ok( exists $calendar->{'exception_holidays'}, 'exception_holidays' );
127
128     my %new_holiday = ( day        => 4,
129                         month       => 5,
130                         year        => 2010,
131                         title       => 'example exception_holiday',
132                         description => 'This is an example exception_holiday used for testing' );
133     my $new_calendar = $calendar->insert_exception_holiday( %new_holiday );
134     # diag( Data::Dumper->Dump( [ $new_calendar ], [ 'newcalendar' ] ) );
135
136     # the calendar object returned from insert_week_day_holiday should be updated
137     isa_ok( $new_calendar, 'C4::Calendar' );
138     my $yyyymmdd = sprintf('%s/%s/%s', $new_holiday{'year'}, $new_holiday{'month'}, $new_holiday{'day'} ) ;
139     is( $new_calendar->{'exception_holidays'}->{ $yyyymmdd }->{'title'}, $new_holiday{'title'}, 'title' );
140     is( $new_calendar->{'exception_holidays'}->{ $yyyymmdd }->{'description'}, $new_holiday{'description'}, 'description' );
141
142     # new calendar objects should have the newly inserted holiday.
143     my $refreshed_calendar = C4::Calendar->new( branchcode => '' );
144     isa_ok( $refreshed_calendar, 'C4::Calendar' );
145     # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
146     is( $new_calendar->{'exception_holidays'}->{ $yyyymmdd }->{'title'}, $new_holiday{'title'}, 'title' );
147     is( $new_calendar->{'exception_holidays'}->{ $yyyymmdd }->{'description'}, $new_holiday{'description'}, 'description' );
148
149 }
150
151
152 sub single_holidays : Test( 8 ) {
153     my $self = shift;
154
155     my $calendar = C4::Calendar->new( branchcode => '' );
156     isa_ok( $calendar, 'C4::Calendar' );
157     # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
158
159     ok( exists $calendar->{'single_holidays'}, 'single_holidays' );
160
161     my %new_holiday = ( day        => 4,
162                         month       => 5,
163                         year        => 2011,
164                         title       => 'example single_holiday',
165                         description => 'This is an example single_holiday used for testing' );
166     my $new_calendar = $calendar->insert_single_holiday( %new_holiday );
167     # diag( Data::Dumper->Dump( [ $new_calendar ], [ 'newcalendar' ] ) );
168
169     # the calendar object returned from insert_week_day_holiday should be updated
170     isa_ok( $new_calendar, 'C4::Calendar' );
171     my $yyyymmdd = sprintf('%s/%s/%s', $new_holiday{'year'}, $new_holiday{'month'}, $new_holiday{'day'} ) ;
172     is( $new_calendar->{'single_holidays'}->{ $yyyymmdd }->{'title'}, $new_holiday{'title'}, 'title' );
173     is( $new_calendar->{'single_holidays'}->{ $yyyymmdd }->{'description'}, $new_holiday{'description'}, 'description' );
174
175     # new calendar objects should have the newly inserted holiday.
176     my $refreshed_calendar = C4::Calendar->new( branchcode => '' );
177     isa_ok( $refreshed_calendar, 'C4::Calendar' );
178     # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
179     is( $new_calendar->{'single_holidays'}->{ $yyyymmdd }->{'title'}, $new_holiday{'title'}, 'title' );
180     is( $new_calendar->{'single_holidays'}->{ $yyyymmdd }->{'description'}, $new_holiday{'description'}, 'description' );
181
182 }
183   
184
185 1;
186