5 use RT::Test tests => 77;
7 my $start_obj = RT::Date->new( RT->SystemUser );
9 my $start = $start_obj->iCal( Time => 1);
11 my $due_obj = RT::Date->new( RT->SystemUser );
14 my $due = $due_obj->iCal( Time => 1);
16 diag 'Test iCal with date only';
18 my ($baseurl, $agent) = RT::Test->started_ok;
20 my $ticket = RT::Ticket->new(RT->SystemUser);
24 Subject => 'Ticket ' . $_,
27 Requestor => 'ical@localhost',
28 Starts => $start_obj->ISO,
33 ok $agent->login('root', 'password'), 'logged in as root';
35 $agent->get_ok('/Search/Build.html');
36 $agent->form_name('BuildQuery');
37 $agent->field('idOp', '>');
38 $agent->field('ValueOfid', '0');
39 $agent->submit('DoSearch');
40 $agent->follow_link_ok({id => 'page-results'});
43 $agent->content_contains('Ticket ' . $_);
46 $agent->follow_link_ok( { text => 'iCal' } );
48 is( $agent->content_type, 'text/calendar', 'content type is text/calendar' );
51 $agent->content_like(qr/URL\:$baseurl\/Ticket\/Display\.html\?id=$_/);
54 my $ical = Data::ICal->new(data => $agent->content);
56 my @entries = $ical->entries;
57 my $ical_count = @{$entries[0]};
58 is( $ical_count, 10, "Got $ical_count ical entries");
60 my $prop_ref = $entries[0]->[0]->properties;
61 my $start_as_root = RT::Date->new( RT::CurrentUser->new( 'root' ) );
62 $start_as_root->Unix( $start_obj->Unix );
63 my $start = $start_as_root->ISO( Time => 0, Timezone => 'user' );
65 is($prop_ref->{'dtstart'}->[0]->value, $start, "Got start date: $start");
66 like( $prop_ref->{'dtstart'}->[0]->as_string, qr/VALUE=DATE\:/, 'Got DATE value');
68 $prop_ref = $entries[0]->[1]->properties;
69 my $due_as_root = RT::Date->new( RT::CurrentUser->new( 'root' ) );
70 $due_as_root->Unix( $due_obj->Unix );
71 my $due = $due_as_root->ISO( Time => 0, Timezone => 'user' );
73 is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date: $due");
74 like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE\:/, 'Got DATE value');
77 RT::Test->stop_server;
79 diag 'Test iCal with date and time with config option';
81 RT->Config->Set(TimeInICal =>1);
82 my ($baseurl, $agent) = RT::Test->started_ok;
84 ok $agent->login('root', 'password'), 'logged in as root';
86 $agent->get_ok('/Search/Build.html');
87 $agent->form_name('BuildQuery');
88 $agent->field('idOp', '>');
89 $agent->field('ValueOfid', '0');
90 $agent->submit('DoSearch');
91 $agent->follow_link_ok({id => 'page-results'});
94 $agent->content_contains('Ticket ' . $_);
97 my $link = $agent->find_link( text => 'iCal' ); # use $link later
98 $agent->get_ok($link->url);
100 is( $agent->content_type, 'text/calendar', 'content type is text/calendar' );
103 $agent->content_like(qr/URL\:$baseurl\/Ticket\/Display\.html\?id=$_/);
106 my $ical = Data::ICal->new(data => $agent->content);
108 my @entries = $ical->entries;
109 my $ical_count = @{$entries[0]};
110 is( $ical_count, 10, "Got $ical_count ical entries");
112 my $prop_ref = $entries[0]->[0]->properties;
114 is($prop_ref->{'dtstart'}->[0]->value, $start, "Got start date with time: $start");
115 like( $prop_ref->{'dtstart'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
117 $prop_ref = $entries[0]->[1]->properties;
119 is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date with time: $due");
120 like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
123 RT::Test->stop_server;
125 diag 'Test iCal with date and time using query param';
127 RT->Config->Set(TimeInICal =>0);
128 my ($baseurl, $agent) = RT::Test->started_ok;
130 ok $agent->login('root', 'password'), 'logged in as root';
132 $agent->get_ok('/Search/Build.html');
133 $agent->form_name('BuildQuery');
134 $agent->field('idOp', '>');
135 $agent->field('ValueOfid', '0');
136 $agent->submit('DoSearch');
137 $agent->follow_link_ok({id => 'page-results'});
140 $agent->content_contains('Ticket ' . $_);
143 my $link = $agent->find_link( text => 'iCal' );
144 $agent->get_ok($link->url . '?Time=1');
146 is( $agent->content_type, 'text/calendar', 'content type is text/calendar' );
149 $agent->content_like(qr/URL\:$baseurl\/Ticket\/Display\.html\?id=$_/);
152 my $ical = Data::ICal->new(data => $agent->content);
154 my @entries = $ical->entries;
155 my $ical_count = @{$entries[0]};
156 is( $ical_count, 10, "Got $ical_count ical entries");
158 my $prop_ref = $entries[0]->[0]->properties;
160 is($prop_ref->{'dtstart'}->[0]->value, $start, "Got start date with time: $start");
161 like( $prop_ref->{'dtstart'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
163 $prop_ref = $entries[0]->[1]->properties;
165 is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date with time: $due");
166 like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
168 diag 'Test iCal with date and time in single events';
170 my $url = $link->url . '?SingleEvent=1&Time=1';
171 $agent->get_ok($url);
173 is( $agent->content_type, 'text/calendar', 'content type is text/calendar' );
176 $agent->content_like(qr/URL\:$baseurl\/Ticket\/Display\.html\?id=$_/);
179 $ical = Data::ICal->new(data => $agent->content);
181 @entries = $ical->entries;
182 $ical_count = @{$entries[0]};
184 # Only 5 entries in single event mode
185 is( $ical_count, 5, "Got $ical_count ical entries");
187 $prop_ref = $entries[0]->[0]->properties;
189 is($prop_ref->{'dtstart'}->[0]->value, $start, "Got start date with time: $start");
190 like( $prop_ref->{'dtstart'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
192 $prop_ref = $entries[0]->[1]->properties;
194 is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date with time: $due");
195 like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');