Consider time zone when creating start/end dates for calendar view methods. Fixes bug #10924

This commit is contained in:
Colin Kuskie 2009-09-16 11:23:47 -07:00
parent c5824ab0e3
commit 96dba300f7
3 changed files with 108 additions and 27 deletions

View file

@ -57,7 +57,7 @@ use Data::Dumper;
use WebGUI::Asset::Wobject::Calendar;
use WebGUI::Asset::Event;
plan tests => 11 + scalar @icalWrapTests;
plan tests => 14 + scalar @icalWrapTests;
my $session = WebGUI::Test->session;
@ -69,6 +69,10 @@ $versionTag->set({name=>"Calendar Test"});
WebGUI::Test->tagsToRollback($versionTag);
my $cal = $node->addChild({className=>'WebGUI::Asset::Wobject::Calendar'});
my $windowCal = $node->addChild({
className => 'WebGUI::Asset::Wobject::Calendar',
title => 'Calendar for doing event window testing',
});
$versionTag->commit();
# Test for a sane object type
@ -118,14 +122,9 @@ cmp_deeply(
#
######################################################################
my $windowCal = $node->addChild({
className => 'WebGUI::Asset::Wobject::Calendar',
title => 'Calendar for doing event window testing',
});
my $tz = $session->datetime->getTimeZone();
my $bday = WebGUI::DateTime->new($session, WebGUI::Test->webguiBirthday);
my $dt = $bday->clone->truncate(to => 'day');
$dt = $bday->clone->truncate(to => 'day');
my $startDt = $dt->cloneToUserTimeZone->subtract(days => 1);
my $endDt = $dt->cloneToUserTimeZone->add(days => 1);
@ -244,6 +243,8 @@ my $weekCal = $node->addChild({
my $allDayDt = $bday->cloneToUserTimeZone;
my $nextWeekDt = $bday->cloneToUserTimeZone->add(weeks => 1)->truncate( to => 'week')->add(days => 6, hours => 19);
my $allDay = $weekCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'An event with explicit times that lasts all day',
@ -254,6 +255,16 @@ my $allDay = $weekCal->addChild({
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $endOfWeek = $weekCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'Event at the end of the week',
startDate => $nextWeekDt->toDatabaseDate,
endDate => $nextWeekDt->toDatabaseDate,
startTime => $nextWeekDt->toDatabaseTime,
endTime => $nextWeekDt->clone->add(hours => 1)->toDatabaseTime,
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $tag3 = WebGUI::VersionTag->getWorking($session);
$tag3->commit;
WebGUI::Test->tagsToRollback($tag3);
@ -272,6 +283,20 @@ cmp_deeply(
'viewWeek: all day event is only in 1 day when time zones line up correctly'
);
$weekVars = $weekCal->viewWeek({ start => $nextWeekDt });
@eventBins = ();
foreach my $day (@{ $weekVars->{days} }) {
if (exists $day->{events} and scalar @{ $day->{events} } > 0) {
push @eventBins, $day->{dayOfWeek};
}
}
cmp_deeply(
\@eventBins,
[ 7 ],
'... end of week event in proper bin, considering time zone'
);
################################################################
#
# wrapIcal
@ -297,9 +322,10 @@ my $monthCal = $node->addChild({
title => 'Calendar for doing event span testing, month',
});
my $allDayDt = $bday->cloneToUserTimeZone;
$allDayDt = $bday->cloneToUserTimeZone;
my $nextMonthDt = $bday->cloneToUserTimeZone->add(months => 1)->truncate( to => 'month')->add(days => 29, hours => 19);
my $allDay = $monthCal->addChild({
$allDay = $monthCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'An event with explicit times that lasts all day',
startDate => $allDayDt->toDatabaseDate,
@ -309,12 +335,22 @@ my $allDay = $monthCal->addChild({
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $endOfMonth = $monthCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'Event at the end of the month',
startDate => $nextMonthDt->toDatabaseDate,
endDate => $nextMonthDt->toDatabaseDate,
startTime => $nextMonthDt->toDatabaseTime,
endTime => $nextMonthDt->clone->add(hours => 1)->toDatabaseTime,
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $tag4 = WebGUI::VersionTag->getWorking($session);
$tag4->commit;
WebGUI::Test->tagsToRollback($tag4);
my $monthVars = $monthCal->viewMonth({ start => $bday });
my @eventBins = ();
@eventBins = ();
foreach my $week ( @{ $monthVars->{weeks} } ) {
foreach my $day (@{ $week->{days} }) {
if (exists $day->{events} and scalar @{ $day->{events} } > 0) {
@ -329,6 +365,22 @@ cmp_deeply(
'viewMonth: all day event is only in 1 day when time zones line up correctly'
);
$monthVars = $monthCal->viewMonth({ start => $nextMonthDt });
@eventBins = ();
foreach my $week ( @{ $monthVars->{weeks} } ) {
foreach my $day (@{ $week->{days} }) {
if (exists $day->{events} and scalar @{ $day->{events} } > 0) {
push @eventBins, $day->{dayMonth};
}
}
}
cmp_deeply(
\@eventBins,
[ 30 ],
'... end of month event in proper bin'
);
######################################################################
#
@ -341,9 +393,10 @@ my $dayCal = $node->addChild({
title => 'Calendar for doing event span testing, day',
});
my $allDayDt = $bday->cloneToUserTimeZone;
$allDayDt = $bday->cloneToUserTimeZone;
my $nextDayDt = $bday->cloneToUserTimeZone->add(days => 1)->truncate( to => 'day')->add(hours => 19);
my $allDay = $dayCal->addChild({
$allDay = $dayCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'An event with explicit times that lasts all day',
startDate => $allDayDt->toDatabaseDate,
@ -353,10 +406,34 @@ my $allDay = $dayCal->addChild({
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $nextDay = $dayCal->addChild({
className => 'WebGUI::Asset::Event',
title => 'Event at the end of the next day',
startDate => $nextDayDt->toDatabaseDate,
endDate => $nextDayDt->toDatabaseDate,
startTime => $nextDayDt->toDatabaseTime,
endTime => $nextDayDt->clone->add(hours => 1)->toDatabaseTime,
timeZone => $tz,
}, undef, undef, {skipAutoCommitWorkflows => 1});
my $tag5 = WebGUI::VersionTag->getWorking($session);
$tag5->commit;
WebGUI::Test->tagsToRollback($tag5);
my $hourVars = $dayCal->viewDay({ start => $nextDayDt });
@eventBins = ();
foreach my $slot (@{ $hourVars->{hours} }) {
if (exists $slot->{events} and scalar @{ $slot->{events} } > 0) {
push @eventBins, $slot->{hour24};
}
}
cmp_deeply(
\@eventBins,
[ 19 ],
'... end of day event in proper bin'
);
TODO: {
local $TODO = "Tests to make later";
ok(0, 'Lots more to test');