Add an Event method for returning a non-inclusive end DataTime object.
Have Calendar use that for determining the end of a week in viewWeek. Fix getEventsIn to do all comparisons in UTC so that extra events are not added in.
This commit is contained in:
parent
f04a162ea3
commit
1bcae0d3bc
4 changed files with 213 additions and 37 deletions
|
|
@ -19,7 +19,7 @@ use WebGUI::Asset::Event;
|
|||
|
||||
use Test::More; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
plan tests => 9;
|
||||
plan tests => 10;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -81,3 +81,5 @@ is($event3->isAllDay, 1, 'isAllDay is zero since it has no start or end time, ev
|
|||
%templateVars = $event3->getTemplateVars();
|
||||
is($templateVars{dateSpan}, 'Wednesday, August 16 • Thursday, August 17 ', 'getTemplateVars: dateSpan with no times, across two days');
|
||||
is($templateVars{isOneDay}, 0, 'getTemplateVars: isOneDay with different start and end dates');
|
||||
|
||||
cmp_ok($event3->getDateTimeEnd, '>', $event3->getDateTimeEndNI, 'getDateTimeEndNI is less than getDateTimeEnd');
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ my @icalWrapTests = (
|
|||
out => '\;Escape more than one\; multiple\; semicolons\;',
|
||||
comment => 'escape semicolons',
|
||||
},
|
||||
{
|
||||
in => '\\Escape more than one\\ multiple\\ backslashes\\',
|
||||
out => '\\\\Escape more than one\\\\ multiple\\\\ backslashes\\\\',
|
||||
comment => 'escape backslashes',
|
||||
},
|
||||
{
|
||||
in => "lots\nand\nlots\nof\nnewlines\n",
|
||||
out => 'lots\\nand\\nlots\\nof\\nnewlines\\n',
|
||||
|
|
@ -48,10 +53,11 @@ use WebGUI::Test;
|
|||
use WebGUI::Session;
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Data::Dumper;
|
||||
use WebGUI::Asset::Wobject::Calendar;
|
||||
use WebGUI::Asset::Event;
|
||||
|
||||
plan tests => 5 + scalar @icalWrapTests;
|
||||
plan tests => 10 + scalar @icalWrapTests;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -60,6 +66,7 @@ my $node = WebGUI::Asset->getImportNode($session);
|
|||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->set({name=>"Calendar Test"});
|
||||
WebGUI::Test->tagsToRollback($versionTag);
|
||||
|
||||
my $cal = $node->addChild({className=>'WebGUI::Asset::Wobject::Calendar'});
|
||||
$versionTag->commit();
|
||||
|
|
@ -71,11 +78,9 @@ isa_ok($cal, 'WebGUI::Asset::Wobject::Calendar');
|
|||
my $event = $cal->addChild({className=>'WebGUI::Asset::Event'});
|
||||
isa_ok($event, 'WebGUI::Asset::Event','Can add Events as a child to the calendar.');
|
||||
|
||||
# Calendars create and autocommit a version tag when a child is added. Lets get the name so we can roll it back.
|
||||
my $secondVersionTag = WebGUI::VersionTag->new($session, $event->get("tagId"));
|
||||
|
||||
my $article = $cal->addChild({className=>"WebGUI::Asset::Wobject::Article"});
|
||||
isnt(ref $article, 'WebGUI::Asset::Wobject::Article', "Can't add an article as a child to the calendar.");
|
||||
ok(! defined $article, '... addChild returned undef');
|
||||
|
||||
my $dt = WebGUI::DateTime->new($session, mysql => '2001-08-16 8:00:00', time_zone => 'America/Chicago');
|
||||
|
||||
|
|
@ -107,6 +112,166 @@ cmp_deeply(
|
|||
'Variables returned by appendTemplateVarsDateTime'
|
||||
);
|
||||
|
||||
######################################################################
|
||||
#
|
||||
# getEventsIn
|
||||
#
|
||||
######################################################################
|
||||
|
||||
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');
|
||||
|
||||
my $startDt = $dt->cloneToUserTimeZone->subtract(days => 1);
|
||||
my $endDt = $dt->cloneToUserTimeZone->add(days => 1);
|
||||
|
||||
my $inside = $windowCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Inside window, no times, same day',
|
||||
startDate => $bday->toDatabaseDate,
|
||||
endDate => $bday->toDatabaseDate,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $inside2 = $windowCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Inside window, with times',
|
||||
startDate => $bday->toDatabaseDate,
|
||||
endDate => $bday->toDatabaseDate,
|
||||
startTime => $bday->toDatabaseTime,
|
||||
endTime => $bday->clone->add(hours => 1)->toDatabaseTime,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $outsideHigh = $windowCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Outside window, after time',
|
||||
startDate => $endDt->clone->add(days => 2)->toDatabaseDate,
|
||||
endDate => $endDt->clone->add(days => 3)->toDatabaseDate,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $outsideLow = $windowCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Outside window, before time',
|
||||
startDate => $startDt->clone->subtract(days => 3)->toDatabaseDate,
|
||||
endDate => $startDt->clone->subtract(days => 2)->toDatabaseDate,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $straddle = $windowCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Straddles the window, inclusive',
|
||||
startDate => $startDt->clone->subtract(days => 1)->toDatabaseDate,
|
||||
endDate => $endDt->clone->add(days => 1)->toDatabaseDate,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $straddleLow = $windowCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Straddles the window, lower side',
|
||||
startDate => $startDt->clone->subtract(hours => 12)->toDatabaseDate,
|
||||
endDate => $startDt->clone->add(hours => 12)->toDatabaseDate,
|
||||
startTime => $startDt->clone->subtract(hours => 12)->toDatabaseTime,
|
||||
endTime => $startDt->clone->add(hours => 12)->toDatabaseTime,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $straddleHigh = $windowCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Straddles the window, higher side',
|
||||
startDate => $endDt->clone->subtract(hours => 12)->toDatabaseDate,
|
||||
endDate => $endDt->clone->add(hours => 12)->toDatabaseDate,
|
||||
startTime => $endDt->clone->subtract(hours => 12)->toDatabaseTime,
|
||||
endTime => $endDt->clone->add(hours => 12)->toDatabaseTime,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $justBefore = $windowCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Just before the window. Ending time coincident with window start',
|
||||
startDate => $startDt->clone->subtract(hours => 1)->toDatabaseDate,
|
||||
endDate => $startDt->toDatabaseDate,
|
||||
startTime => $startDt->clone->subtract(hours => 1)->toDatabaseTime,
|
||||
endTime => $startDt->toDatabaseTime,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $justAfter = $windowCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Just after the window. Start time coincident with window end',
|
||||
startDate => $endDt->toDatabaseDate,
|
||||
endDate => $endDt->clone->add(hours => 1)->toDatabaseDate,
|
||||
startTime => $endDt->toDatabaseTime,
|
||||
endTime => $endDt->clone->add(hours => 1)->toDatabaseTime,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $tag2 = WebGUI::VersionTag->getWorking($session);
|
||||
$tag2->commit;
|
||||
WebGUI::Test->tagsToRollback($tag2);
|
||||
|
||||
is(scalar @{ $windowCal->getLineage(['children'])}, 9, 'added events to the window calendar');
|
||||
|
||||
my @window = $windowCal->getEventsIn($startDt->toDatabase, $endDt->toDatabase);
|
||||
|
||||
#diag $startDt->toDatabase;
|
||||
#diag join "\n", map { join ' ', $_->get('title'), $_->get('startDate'), $_->get('startTime')} @window;
|
||||
#diag $endDt->toDatabase;
|
||||
|
||||
is(scalar @window, 4, 'getEventsIn returned 4 events');
|
||||
cmp_bag(
|
||||
[ map { $_->get('title') } @window ],
|
||||
[ map { $_->get('title') } ($inside, $inside2, $straddle, $straddleHigh)],
|
||||
'..returns correct 4 events'
|
||||
);
|
||||
|
||||
######################################################################
|
||||
#
|
||||
# viewWeek
|
||||
#
|
||||
######################################################################
|
||||
|
||||
my $weekCal = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Calendar',
|
||||
title => 'Calendar for doing event span testing, week',
|
||||
});
|
||||
|
||||
my $allDayDt = $bday->cloneToUserTimeZone;
|
||||
|
||||
my $allDay = $weekCal->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'An event with explicit times that lasts all day',
|
||||
startDate => $allDayDt->toDatabaseDate,
|
||||
endDate => $allDayDt->clone->add(days => 1)->toDatabaseDate,
|
||||
startTime => $allDayDt->clone->truncate(to => 'day')->toDatabaseTime,
|
||||
endTime => $allDayDt->clone->add(days => 1)->truncate(to => 'day')->toDatabaseTime,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $tag3 = WebGUI::VersionTag->getWorking($session);
|
||||
$tag3->commit;
|
||||
WebGUI::Test->tagsToRollback($tag3);
|
||||
|
||||
my $allVars = $weekCal->viewWeek({ start => $bday });
|
||||
my @eventBins = ();
|
||||
foreach my $day (@{ $allVars->{days} }) {
|
||||
if (exists $day->{events} and scalar @{ $day->{events} } > 0) {
|
||||
push @eventBins, $day->{dayOfWeek};
|
||||
}
|
||||
}
|
||||
|
||||
cmp_deeply(
|
||||
\@eventBins,
|
||||
[ 4 ],
|
||||
'viewWeek: all day event is only in 1 day when time zones line up correctly'
|
||||
);
|
||||
|
||||
################################################################
|
||||
#
|
||||
# wrapIcal
|
||||
|
|
@ -125,10 +290,3 @@ TODO: {
|
|||
local $TODO = "Tests to make later";
|
||||
ok(0, 'Lots more to test');
|
||||
}
|
||||
|
||||
END {
|
||||
# Clean up after thy self
|
||||
$versionTag->rollback();
|
||||
$secondVersionTag->rollback();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue