1 package KohaTest::Calendar::New;
2 use base qw( KohaTest );
10 sub testing_class { 'C4::Calendar' };
13 =head2 STARTUP METHODS
15 These get run once, before the main test methods in this module
25 just test to see if I can instantiate an object
29 sub instantiation : Test( 14 ) {
32 my $calendar = C4::Calendar->new( branchcode => '' );
33 isa_ok( $calendar, 'C4::Calendar' );
34 # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
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' );
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' );
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' );
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' );
58 sub week_day_holidays : Test( 8 ) {
61 my $calendar = C4::Calendar->new( branchcode => '' );
62 isa_ok( $calendar, 'C4::Calendar' );
63 # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
65 ok( exists $calendar->{'week_days_holidays'}, 'week_days_holidays' );
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 );
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' );
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' );
87 sub day_month_holidays : Test( 8 ) {
90 my $calendar = C4::Calendar->new( branchcode => '' );
91 isa_ok( $calendar, 'C4::Calendar' );
92 # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
94 ok( exists $calendar->{'day_month_holidays'}, 'day_month_holidays' );
96 my %new_holiday = ( day => 4,
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 );
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' );
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' );
119 sub exception_holidays : Test( 8 ) {
122 my $calendar = C4::Calendar->new( branchcode => '' );
123 isa_ok( $calendar, 'C4::Calendar' );
124 # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
126 ok( exists $calendar->{'exception_holidays'}, 'exception_holidays' );
128 my %new_holiday = ( day => 4,
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' ] ) );
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' );
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' );
152 sub single_holidays : Test( 8 ) {
155 my $calendar = C4::Calendar->new( branchcode => '' );
156 isa_ok( $calendar, 'C4::Calendar' );
157 # diag( Data::Dumper->Dump( [ $calendar ], [ 'calendar' ] ) );
159 ok( exists $calendar->{'single_holidays'}, 'single_holidays' );
161 my %new_holiday = ( day => 4,
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' ] ) );
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' );
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' );